What is an LLM API? A beginner's guide
Chat apps are one way to use AI models. An LLM API is the other: it lets your own software send text to a model and get a response back. Here's how it works, from the first request to the bill.
When people talk about building with AI, they almost always mean calling a large language model through an API. Every AI-powered feature you've seen, from support bots to coding assistants to document summarisers, is software sending requests to a model and doing something useful with the answers. This guide explains what's happening under the hood, in plain terms.
What is an LLM API?
An API (application programming interface) is a way for one program to talk to another. An LLM API is an interface your code uses to send input to a large language model, such as Claude, GPT or Grok, and receive its output. Instead of typing into a chat window, your application sends a structured request over the internet and gets a structured response back.
The model runs on the provider's servers. You don't need GPUs or any machine-learning setup: you need an API key, a few lines of code and a balance to pay for what you use.
What happens in a single API call
- Your code builds a request naming the model and containing the messages: usually a system instruction and the user's input.
- It sends the request to the provider's endpoint over HTTPS, with your API key in a header.
- The provider checks the key, runs the model on your input and generates a response.
- The response comes back with the model's text and a usage report: how many input and output tokens the call used.
- The provider bills your account for those tokens.
What a request contains
- model: which model to use, by its ID, such as claude-sonnet-5.
- messages: the conversation, as a list of turns with roles such as system, user and assistant.
- max_tokens: the longest response you'll accept, which also caps the cost.
- temperature: how varied the output should be; lower is more consistent.
- stream: whether to receive the answer word by word as it's written.
- tools: optional functions the model may ask your code to run.
LLM APIs are stateless: the model doesn't remember earlier requests. To hold a conversation, your code sends the previous turns again with each new message. That history counts toward the model's context window and toward your bill.
API keys
An API key is a secret string that identifies your account and authorises requests. Anyone who has it can spend your balance, so keep it on your server or in environment variables, never in frontend code or a public repository. Good platforms let you create separate keys per application and set spend limits on each, so a leaked or misbehaving key can't cost you much.
The formats you'll meet
Most LLM APIs follow one of a few request formats, and the official SDKs are built around them:
- OpenAI Chat Completions: the most widely supported format, used by countless libraries and tools.
- OpenAI Responses: OpenAI's newer format, with a simpler input and built-in conversation features.
- Anthropic Messages: the format Claude models and tools such as Claude Code use natively.
A service that supports these formats works with existing SDKs unchanged. GreenTokens serves all three, so one key reaches Claude, GPT, Grok, DeepSeek and more whichever format your code already uses. The text API docs show each one.
Your first request
Here's a complete request in Python using the official OpenAI SDK. Install it with pip install openai, create a key, and run:
from openai import OpenAI
client = OpenAI(
base_url="https://api.greentokens.io/v1",
api_key="sk-gt-…",
)
response = client.chat.completions.create(
model="claude-sonnet-5",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain what an API is in one sentence."},
],
max_tokens=200,
)
print(response.choices[0].message.content)
print(response.usage) # input and output tokens usedTo try a different model, change the model string: gpt-5.6-sol, grok-4.6 or any other ID from the models page. The quickstart has the same example in TypeScript and curl.
Streaming
Models generate text one token at a time, so a long answer can take several seconds. With streaming turned on, the API sends each piece as soon as it's written, and your app can display it immediately. That's what makes chat interfaces feel responsive, and it lets you stop a response early if it isn't needed.
Tool calling
Tool calling lets a model ask your code to do something it can't do alone, such as look up an order, search a database or call another API. You describe the available functions in the request; the model responds with the function it wants and the arguments; your code runs it and sends back the result. This is the foundation of AI agents.
How you pay
Text models are billed per token, with separate prices for input and output, usually quoted per million tokens. Image and video models are billed per image or per second of video. Some platforms bill monthly in arrears; others, including GreenTokens, use a prepaid balance with no subscription. Our guide to how AI API pricing works goes through it step by step.
Choosing a model
Start with a capable mid-tier model to get your feature working, then test cheaper models on your real inputs. Many tasks, such as classification or extraction, run well on budget models that cost a fraction as much. Using one API for every model makes these comparisons a one-line change.
Common questions
Is an LLM API free?
Most LLM APIs are paid by usage, though some offer free trial credits or rate-limited free tiers for experimenting. For anything beyond testing, expect to pay per token. Prices vary enormously by model, so a cheaper model can make an API very affordable.
Do I need to know machine learning to use one?
No. Using an LLM API is ordinary web programming: build a request, send it, read the response. If you can call any other web API, you can call an LLM API. The skill that matters most is writing clear instructions for the model.
In short
An LLM API lets your software send messages to a language model and get its answer back, authenticated with an API key and billed per token. Requests name a model, carry the conversation and set a few options; responses return the text and the tokens used. Learn the request, keep your key safe, and you can build on any model.
Pay less for the same models
Compare our prices with the official ones, then switch with one base URL.
Read next
- What Is a Token in AI? Tokens in LLMs ExplainedWhat tokens are, how text becomes tokens, how many words a token is, and why tokens decide what every AI API call costs.
- How Does AI API Pricing Work? Tokens, Images & VideoHow AI APIs charge for text, images and video, what drives the bill, how to estimate a workload before you build, and how to keep costs predictable.