AI for beginnersGuide
Input vs output tokens: what an AI API bills you for
Why an AI API counts input and output tokens separately, where to read them in the usage field, and how to work out the cost of one request.

On this page
If you have just made your first API call to a language model, you have probably seen a usage block in the response and wondered what exactly it counts. The short answer: every request has two meters. One counts the tokens you send (input), the other counts the tokens the model writes back (output). Each meter has its own price, and the cost of a request is the sum of both.
This guide shows where to find the numbers, how to turn them into dollars, and what you can change to spend less. If the word "token" is still fuzzy, start with What is a token in AI?.
What counts as input and what counts as output#
Input tokens are everything the model has to read to answer you:
- your latest message;
- the system prompt (instructions such as "answer briefly, in English");
- the earlier messages of the conversation, if you send them again;
- documents, code or search results you paste into the request.
Output tokens are everything the model generates in reply. In the OpenAI-compatible format this is the text in choices[0].. Some models in thinking mode also generate reasoning tokens before the final answer; check a model's pricing page to see whether they are billed as output.
The important point for beginners: the model does not remember your chat between requests. A chat app resends the whole history each time, so the input of a long conversation grows with every turn, even if your new message is one line.
Where to read the numbers: the usage block#
Every non-streaming response from an OpenAI-compatible API ends with a usage object. This is an educational example of its shape:
{
"choices": [
{ "message": { "role": "assistant", "content": "..." }, "finish_reason": "stop" }
],
"usage": {
"prompt_tokens": 2000,
"completion_tokens": 500,
"total_tokens": 2500
}
}Scroll the table right →
| Field | What it means | Billed as |
|---|---|---|
prompt_tokens |
Tokens in everything you sent | Input |
completion_ |
Tokens the model generated | Output |
total_tokens |
prompt_tokens + completion_ |
Not a separate price: it is only the sum |
A common beginner mistake is to multiply total_tokens by one price. Because input and output have different prices, you need the two numbers separately.
Some providers add extra fields. For example, DeepSeek's own API also splits prompt_tokens into prompt_ and prompt_ and, in thinking mode, reports reasoning_tokens (source: DeepSeek API docs, checked 21 October 2026). The three fields in the table are the ones you can rely on in any OpenAI-compatible response.
When you stream the answer, usage is not known at the start. In DeepSeek's own API it arrives in the last content chunk before data: [DONE] (DeepSeek API docs, checked 21 October 2026); other APIs may send it differently or only on request, so check what your client receives. Streaming itself is covered in Streaming responses in Python.
Why the two sides have different prices#
Reading your prompt and writing an answer are different kinds of work. The model processes the whole prompt in one pass, but it has to produce the answer one token at a time, and every new token depends on the previous ones. That is why providers usually price output higher than input, and why you see two numbers per model in any price list.
The model we use as an example below, MiniMax-M2.7 (id minimax-m2.7), follows this pattern. The current prices per 1M tokens are $0.05 for input and $0.15 for output.
The formula#
Prices are quoted per 1 million tokens, so the cost of one request is:
cost = input_tokens × input_price ÷ 1,000,000
+ output_tokens × output_price ÷ 1,000,000Here it is with made-up round prices, only to show the arithmetic (example, substitute current prices from the table below):
# example, substitute current prices from the table
price_in = 0.20 # USD per 1M input tokens
price_out = 0.80 # USD per 1M output tokens
prompt_tokens = 2000
completion_tokens = 500
cost = (prompt_tokens * price_in + completion_tokens * price_out) / 1_000_000
# 2000 × 0.20 ÷ 1,000,000 = 0.0004 (input)
# 500 × 0.80 ÷ 1,000,000 = 0.0004 (output)
# 0.0004 + 0.0004 = 0.0008 USDA worked example with a real model#
Take the request from the usage example above: 2,000 input tokens and 500 output tokens. On MiniMax-M2.7 through CheapTokens it costs $0.00018. The number is calculated from the current price list each time the page is shown.
A single request is tiny, so it helps to scale up. A small app that sends 10,000 requests of this size uses 20,000,000 input tokens and 5,000,000 output tokens, which comes to $1.75.
The same request on other models from our list:
| Model | Input $/1M | Output $/1M | Cost | OpenRouter |
|---|---|---|---|---|
| GLM-5.3-Flash | $0.02 | $0.04 | $0.00006 | $0.00012 |
| DeepSeek-V4-Flash | $0.015 | $0.10 | $0.00008 | $0.00017 |
| MiniMax-M2.7 | $0.05 | $0.15 | $0.00018 | $0.0012 |
2,000 input and 500 output tokens in total. Prices per 1M tokens are current and change together with our tariffs; the OpenRouter column shows reference prices for the same workload.
Notice that output is a minor part of the token count here (500 of 2,500) but a larger part of the bill than its share of tokens, because output tokens are priced higher (see the table). For this model the output side is also where the saving against OpenRouter's reference price is confirmed, which is useful if your app writes long answers.
Using it in code#
You can read usage from the official openai Python package by pointing it at the CheapTokens base URL:
from openai import OpenAI
client = OpenAI(
base_url="https://api.cheaptokens.dev/v1",
api_key="YOUR_API_KEY",
)
response = client.chat.completions.create(
model="MiniMaxAI/MiniMax-M2.7",
messages=[{"role": "user", "content": "Explain input and output tokens in two sentences."}],
)
usage = response.usage
print("input:", usage.prompt_tokens)
print("output:", usage.completion_tokens)
print("total:", usage.total_tokens)
# example, substitute current prices from the table above
price_in, price_out = 0.20, 0.80
cost = (usage.prompt_tokens * price_in + usage.completion_tokens * price_out) / 1_000_000
print(f"approx. cost: ${cost:.6f}")If you have not sent a request yet, follow Your first API request with CheapTokens first.
How to spend fewer tokens#
- Shorten the prompt. Trim the system prompt and remove instructions the model does not need. Every token you send is billed on every request.
- Trim the history. In a long chat, keep the last few turns or a short summary instead of the whole conversation.
- Send only the relevant part of a document. A page of text is cheaper than a whole file.
- Ask for the format you need. "Answer in three bullet points" produces fewer output tokens than an open-ended essay.
- Set
max_tokenson purpose. It limits output only. Too low and the answer is cut off; the details are in Why does an AI answer stop mid-sentence? MiniMax-M2.7 on CheapTokens allows up to 8,192 output tokens per answer and has a 180K context window.
For estimating the cost of a bigger workflow, see How to estimate the cost of an AI agent.
What to remember#
- Every request has input tokens (
prompt_tokens) and output tokens (completion_).tokens - They have separate prices, usually with output higher.
- Cost = input tokens × input price + output tokens × output price, with prices per 1M tokens.
- Read the numbers from
usagein the response rather than guessing.
On CheapTokens one prepaid balance covers all models, prices per model are fixed with no peak-hour pricing, and the API is compatible with OpenAI Chat Completions and Anthropic Messages. To try the example above, get an API key and send your first request.
Current prices for every model: CheapTokens pricing.



