What is an LLM API? How it works, how it bills, how to choose

The short version
- An LLM API is the HTTP interface to a large language model. You send a model name and a conversation as JSON, and you get the generated text back as JSON.
- Most LLM APIs bill per token, with separate rates for input and output, quoted per million tokens.
- The OpenAI Chat Completions format is the common language. Change the base URL and the key, and the same code calls another company's model.
- Before you choose a provider, compare five things: models and features, the billing unit, limits, data handling, and how you pay.
- If you use models from several labs, an AI gateway puts them behind one key and one bill.
What an LLM API is
A large language model (LLM) is a model trained on a very large body of text. It writes, summarizes, translates and generates code. An LLM API exposes that model to your own programs over the internet. The lab that built the model, or a company that hosts it, runs the GPUs and keeps the model up. You get an API key, send requests in a fixed format, and use the answers in your app.
The chat app versus the API
The same model behaves like a different product in a chat app and through the API.
| Chat app | LLM API | |
|---|---|---|
| Who uses it | A person typing | A program calling it |
| Typical use | Research, drafting | Features in an app, automation, agents |
| Pricing | Mostly a monthly plan | Mostly pay per use |
| Conversation history | Kept by the app | Sent by the caller on every request |
| Control | What the app exposes | Model, output length, output format and more |
History is the one people miss. Each API request stands alone, so to get an answer that follows the conversation, you send the earlier turns again every time. That matters for cost, as the billing section shows.
What people build with it
- Support bots and internal assistants
- Summaries and translations of meeting notes, email and long documents
- Classification, tagging, and pulling fields out of text as JSON
- Code generation and review, and coding agents such as Claude Code and Codex
- Retrieval-augmented generation (RAG): search your own documents first, then answer from what was found
Add function calling, where the model asks your code to run a tool, and you can build agents that fetch data and carry a task forward on their own.
How a request works
A call is one HTTP request and one response:
- Create an account with a provider and get an API key.
- Put the model id and the conversation (
messages) in a JSON body, and send it with the key. - The provider's servers run the model and generate the answer.
- The answer comes back as JSON, with the number of tokens used.
In the OpenAI-compatible format the request looks like this:
curl https://api.fastmetal.ai/v1/chat/completions \
-H "Authorization: Bearer $FASTMETAL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic-claude-sonnet-5-5",
"messages": [
{"role": "system", "content": "You are an assistant that answers briefly."},
{"role": "user", "content": "Explain an LLM API in three lines."}
]
}'
messages is a list of turns, each with a role. system holds the instructions the model works under, user is the person's message, and assistant holds the model's earlier answers. The response carries the answer and the token counts that the bill is based on:
{
"choices": [
{"message": {"role": "assistant", "content": "An LLM API is..."}, "finish_reason": "stop"}
],
"usage": {"prompt_tokens": 38, "completion_tokens": 95, "total_tokens": 133}
}
prompt_tokens is input and completion_tokens is output. Multiply each by its rate and add them up, and you have the cost of the call.
Tokens and billing
Tokens
A token is the unit a model reads and writes. In English a token is roughly a word or part of one. Other languages often need more tokens for the same content. Every model has its own tokenizer, so the same text can count differently on two models.
Per-million-token rates
Most LLM APIs charge input tokens and output tokens at separate rates, quoted per million tokens, and output usually costs more than input. The cost of a call is:
cost = input_tokens / 1,000,000 × input_rate + output_tokens / 1,000,000 × output_rate
Take a job that sends 2,000 input tokens and gets 500 output tokens back, run 10,000 times a month. That is 20 million input tokens and 5 million output tokens. The monthly cost is 20 times the input rate plus 5 times the output rate.
Reasoning models think before they answer, and that thinking is counted as output tokens, at the output rate.
Where costs grow
- Resending history: the longer a conversation runs, the longer every input gets. The context window sets how much one request can carry.
- Long outputs: long documents and long chains of reasoning add output tokens, the expensive side. Set
max_tokensto cap them. - Agents: a coding agent calls the model many times per task and resends its context each time, so input tokens make up most of the bill. Models with prompt caching cost less here.
The main labs and their models
These are the labs most LLM APIs come from, with models FastMetal serves on its API as of November 30, 2026:
| Lab | Models on FastMetal's API | The lab's own price list |
|---|---|---|
| Anthropic | Claude Fable 5.2, Opus 5.5, Sonnet 5.5, Haiku 5.5 | Anthropic pricing |
| OpenAI | GPT-6.1 Sol, GPT-6.1 Terra | OpenAI pricing |
| Gemini 4 Argon, Gemini 4 Carbon | Gemini API pricing | |
| DeepSeek | DeepSeek V4 Pro, V4.1 Flash | DeepSeek pricing |
| xAI | Grok 4.7 | xAI models |
| Moonshot AI | Kimi K3.1 Pro, Kimi K3 | Kimi pricing |
| Z.ai | GLM 5.3 | Z.ai pricing |
| Alibaba | Qwen4 Max |
Models from Meta, Mistral AI and others are on APIs too. Rates change often, so check each lab's own page for current figures.
There are three ways to reach these models: sign up with each lab directly, go through a cloud platform such as Amazon Bedrock or Google Cloud Vertex AI, or use an AI gateway that puts many labs behind one API.
The OpenAI-compatible format
Each provider's API used to differ in small ways. Today most providers and tools accept requests in the same shape as OpenAI's Chat Completions API. With the OpenAI SDK, or any tool built on it, you change the base URL and the key, and you are calling another provider's models:
from openai import OpenAI
client = OpenAI(
api_key="YOUR_FASTMETAL_API_KEY",
base_url="https://api.fastmetal.ai/v1",
)
resp = client.chat.completions.create(
model="deepseek-v4-pro",
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)
Change model to anthropic-claude-sonnet-5-5 or gpt-6.1-sol and the same code calls a model from another lab. The Chat Completions reference covers the request fields.
What still differs between models
A shared format does not make the models the same:
- Features: tool calling, image input, structured output and streaming support vary by model.
- Parameters: the
temperaturerange and the way you set reasoning effort differ from model to model. - The Anthropic format: Claude Code speaks Anthropic's Messages API, so an OpenAI-compatible endpoint alone will not connect it. Look for an Anthropic-compatible endpoint. FastMetal has both, and the setup is in the Claude Code guide.
LLM APIs and other AI APIs
"AI API" covers any API that exposes an AI capability. LLM APIs are one kind:
| Kind | What it does | Usual billing unit |
|---|---|---|
| LLM | Answers, summaries, translation, code | Per million tokens |
| Embeddings | Turns text into vectors for search and classification | Per million tokens |
| Image generation | Makes an image from a prompt | Per image |
| Video generation | Makes a video from a prompt or an image | Per video, or per second |
| Speech | Transcription and text to speech | Per second of audio, or per character |
Teams used to wire up a separate API for each job. Now that LLMs read images and return strict JSON, more apps are built around the LLM API. On FastMetal the same key calls text models, image generation (billed per image), video generation (billed per video) and models that take image input. FastMetal does not serve embedding models, so a RAG build takes its embeddings from elsewhere.
Getting started with any provider
- Pick a provider and create an account. Check first that the models you want are there.
- Add a payment method. Prepaid and postpaid billing need different budget controls.
- Create an API key. Keep it in an environment variable or a secrets manager, never in source code. Usage on a leaked key is billed to its owner.
- Send a first request: a short question, to confirm that an answer and token counts come back. On FastMetal, getting started walks through it.
- Watch usage by model and by day, and check it against what you expected to spend.
If you use it for work, decide up front which data may be sent.
Five things to compare
| Check | What to look at |
|---|---|
| Models and features | Context length, tool calling, image input, structured output |
| Billing unit | Input and output rates, cache and batch discounts |
| Limits | Rate limits, and whether a spending limit really stops requests |
| Data handling | Training on your data, retention, where inference runs |
| Payment | Prepaid or postpaid, card or invoice, currency |
1. Models and features
Check the context length and support for tool calling, image input and structured output, beyond the model's name. The same model can offer different features at different providers. The model catalog shows what each model supports on FastMetal.
2. Billing unit
Look at the input and output rates, and at discounts for prompt caching or batch jobs. Estimate cost as tokens per call times the number of calls. The cost calculator gives a figure per model.
3. Rate limits and spending limits
Most LLM APIs cap requests or tokens per minute and return HTTP 429 above the cap. LLM API rate limits and 429 errors covers how to handle it.
Check also whether you can cap spending. On a postpaid account a limit may only send an alert, and usage above it is still billed. On a prepaid account requests stop when the balance runs out.
4. Data handling
Find out whether your data trains the model, how long it is kept, and in which country inference runs. If you send personal or confidential data, read the provider's terms before you start.
5. Payment
Check the currency, the payment methods, and whether you will get one bill or one per lab. With every new lab you sign up for, the number of bills grows.
One key for many labs: an AI gateway
Matching the model to the job keeps quality and cost in balance: a light model for summaries, a top model for hard code. With a separate account at each lab, every new lab adds work:
- Another account and another payment method
- Another API key to issue and store
- Another request format to support
- Another bill, with its own currency and billing date
An AI gateway takes that work away. Your app calls one endpoint and picks the lab's model with the model field. Keys, billing and usage live in one place.
LLM APIs on FastMetal
FastMetal is an AI gateway: one API key and one endpoint for models from many labs.
- Both OpenAI-compatible and Anthropic-compatible APIs. The OpenAI-compatible base URL is
https://api.fastmetal.ai/v1. - Models from Anthropic, OpenAI, Google, DeepSeek, xAI, Moonshot AI, Z.ai and more, switched by the
modelvalue. Model ids are in the model catalog. - Send
model: "auto"and FastMetal routes the request to the cheapest model that meets its needs (tools, images, JSON). If that model fails, the next candidate takes over, and you pay the rate of the model that answered. - Prepaid: usage is deducted from your balance by the tokens you use, and the minimum card top-up is $5 per purchase.
- The balance is the limit. When it is spent, requests stop with HTTP 429 and
budget_exceeded, so you are never billed beyond it. - FastMetal does not train on your data. Each request is relayed to the model's provider and handled under that provider's policy.
Per-model rates are on the pricing page.
FAQ
What is an LLM API?
The interface your programs use to call a large language model. You send the model name and the conversation as JSON, and you get the generated text and the token counts back as JSON.
How is an LLM API priced?
Most providers bill per token, with one rate for input and one for output, each quoted per million tokens. Output usually costs more. Check each provider's own pricing page for current rates.
Does a paid chat plan include API access?
At most providers, no. The chat subscription and API usage are separate. To use the API, add a payment method to the API account and create a key.
Are there free LLM APIs?
Some providers have free tiers, and some models are free to call. FastMetal has free models priced at $0 per token as well as paid ones. Free tiers usually cap requests per day or speed, so for production use or agents, plan on paid models.
What should I compare between LLM APIs?
Models and features, the billing unit, rate and spending limits, data handling, and how you pay.
Can one API key call models from several labs?
Yes, through an AI gateway. On FastMetal, one key and one OpenAI-compatible endpoint call models from many labs, switched by the model value, and usage comes out of one prepaid balance.
Swap model in the samples above for any id in the model catalog to try another lab's model. Rates are on pricing.