What tokens are in neural networks and how they add up to a price
A token is the unit a model reads text in and the unit you pay in. We cover input, output, cache and context, and work out the cost of a request with a formula.
6 min · · models · экономия
If you're connecting to a model over an API for the first time, the word "token" shows up right away: price, limits and context size are all counted in tokens. Below: what tokens in AI models are, how input differs from output, how caching works, and how to work out the cost of a request from the API response. Prices in the examples are Zukko prices as of October 7, 2026.
What tokens in AI models are, in plain words
A token is a piece of text the model works with. A model doesn't read letters and words the way a person does: before processing, a special program, the tokenizer, splits text into fragments from the model's vocabulary. A common word may be a single token; a rare one gets split into several pieces. Spaces, punctuation, digits and code fragments become tokens too.
Three practical consequences follow:
- Tokens aren't words or characters. Only the tokenizer of a specific model knows the exact count.
- Different models have different tokenizers. The same text can take a different number of tokens in Claude and in GPT.
- Over the API you pay for tokens: both for what you send and for what the model writes back.
Input and output tokens
Input tokens (input, prompt) are everything that goes into the model in a single request: the system instruction, the conversation history, a pasted document, tool descriptions for an agent. Images, if the model accepts them, are also converted into input tokens.
Output tokens (output, completion) are the text the model generated. For models with a reasoning mode, that reasoning is usually counted as output tokens too, even if you never show it to the user.
For most models, output costs more than input. For example, Claude Sonnet 5 in Zukko costs $0.4 for input and $2 for output per 1M tokens (prices as of October 7, 2026). So a long answer usually moves the bill more than a long question, and the max_tokens parameter is a simple way to cap output spending.
Cache: when repeated input is cheaper
In agents and chatbots the start of a request often repeats: the same system prompt, the same documentation, the same history. The model provider can store that prefix in a cache. Then part of the input is billed not at the input price but at the cache read price. Claude also has a cache write: on the first request the prefix is stored, and that part costs more than regular input.
Claude Sonnet 5 prices in Zukko as of October 7, 2026, USD per 1M tokens:
| Token type | Price |
|---|---|
| Fresh input | 0.4 |
| Cache read | 0.05 |
| Cache write | 0.5 |
| Output | 2 |
What to know about caching in Zukko:
- Claude — the cache discount applies in the Anthropic format (
/v1/messages, Claude Code, Anthropic SDK), where the gateway sees both reads and writes. In the OpenAI format (/v1/chat/completions) all Claude input is billed at the input price. - GPT — only cache reads are visible (
prompt_tokens_details.cached_tokens), in both formats. Writes aren't billed separately: the first request is billed entirely at the input price. - DeepSeek, Qwen, GLM and others — reads are counted if the provider reports them in the response; writes aren't billed. For DeepSeek, Qwen and GLM the cache read price in Zukko equals the input price, so caching doesn't change their bill.
Details are in the key limits and cache docs.
Context window
The context window is the maximum number of tokens a model handles in one request: input plus the answer. Most models in the Zukko catalog have a 1M-token window; GLM 5.3 and GLM 5.3 Flash have 128K.
A model accessed over the API doesn't remember previous requests. To keep a conversation going, the program resends the history every time. That's why in a long chat each new message costs more than the previous one: there are more and more input tokens. If the history outgrows the window, the request returns an error, and older messages have to be trimmed or summarized.
Why Russian text costs more
Tokenizers build their vocabulary from training texts, which usually contain more English than Russian. English words more often make it into the vocabulary whole; Russian words are more often split into several pieces. As a result, the same meaning in Russian usually takes more tokens than in English, and costs more.
How much more depends on the model and the text itself, so there are no universal ratios here. Check on your own data: for Claude, input tokens can be counted in advance via count_tokens:
curl https://api.zukko.pro/v1/messages/count_tokens \
-H "Authorization: Bearer fetch_your_key" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "claude-sonnet-5", "messages": [{"role": "user", "content": "How many tokens are in this phrase?"}]}'Send the same phrase in Russian and in English and compare input_tokens. Where the difference comes from is covered in the article why Russian text is counted differently.
How the price of a request is calculated
The formula for a single request:
cost = (fresh input × input price
+ cache read × cache read price
+ cache write × cache write price
+ output × output price) / 1,000,000
Prices are in USD per 1M tokens, which is why we divide by a million at the end.
Example 1. A regular request. Claude Sonnet 5, 2,000 input and 500 output tokens, no cache:
2,000 × 0.4 + 500 × 2 = 800 + 1,000 = 1,800 → $0.0018 per request. A thousand such requests cost $1.80.
Example 2. An agent request with caching. Claude Sonnet 5 in the Anthropic format, 50,000 input tokens of which 45,000 are a repeated prefix, and 1,000 output tokens:
- no cache: 50,000 × 0.4 + 1,000 × 2 = 20,000 + 2,000 = 22,000 → $0.022;
- first request, prefix written to cache: 5,000 × 0.4 + 45,000 × 0.5 + 1,000 × 2 = 2,000 + 22,500 + 2,000 = 26,500 → $0.0265;
- subsequent requests, prefix read from cache: 5,000 × 0.4 + 45,000 × 0.05 + 1,000 × 2 = 2,000 + 2,250 + 2,000 = 6,250 → $0.00625.
The first request with a write costs more than a regular one; the gain comes on repeats. The cache lives for a limited time: if there's a long pause between requests, the prefix has to be written again.
This is an example calculation on October 7, 2026 prices. Provider prices change; for the current list and prices, call GET https://api.zukko.pro/v1/models or open the Models page in the dashboard. Prices for every model in the catalog are collected in one table in the overview AI API prices in October 2026.
Where to see the real token counts
The exact token count comes back in every response, in the usage field:
- OpenAI format:
prompt_tokens,completion_tokens, cache inprompt_tokens_details.cached_tokens; - Anthropic format:
input_tokens(fresh input),output_tokens,cache_read_input_tokens,cache_creation_input_tokens.
A Python example with the official Anthropic SDK that calculates the cost right away:
from anthropic import Anthropic
client = Anthropic(base_url="https://api.zukko.pro", api_key="fetch_your_key")
PRICE = {"in": 0.4, "out": 2, "cache_read": 0.05, "cache_write": 0.5} # claude-sonnet-5, USD per 1M, Oct 7, 2026
msg = client.messages.create(
model="claude-sonnet-5",
max_tokens=500,
messages=[{"role": "user", "content": "Explain what a token is in two sentences"}],
)
u = msg.usage
cost = (
u.input_tokens * PRICE["in"]
+ (u.cache_read_input_tokens or 0) * PRICE["cache_read"]
+ (u.cache_creation_input_tokens or 0) * PRICE["cache_write"]
+ u.output_tokens * PRICE["out"]
) / 1_000_000
print(msg.content[0].text)
print(f"input {u.input_tokens}, output {u.output_tokens}, cost ${cost:.6f}")Actual charges are shown in the dashboard under Usage. To try it on your own texts, create a key in the dashboard — one key works with every model in the catalog.
FAQ
How many tokens are in one word?
There's no fixed number. A short, common English word often takes one token; a long or Russian word often takes several. Only counting on a specific model gives an exact answer: count_tokens or the usage field in the response.
Why was I charged for more tokens than my message contains?
Input includes more than your question: the system prompt, the whole conversation history, tool descriptions, images. Output also includes the model's reasoning, if it's enabled.
Can I know the price before sending a request?
Almost. Input can be counted in advance, and output capped with max_tokens. The upper bound is input × input price + max_tokens × output price, divided by a million.
Are images counted in tokens too?
Yes. Models that accept images convert them into input tokens, and they're billed at the input price.
zukko
Pay 25×
less
for Claude Code & ChatGPT
One fetch_* key and base URL api.zukko.pro — for Cursor, Claude Code, Codex, and any SDK.
Related articles
- Grok API price: cost of Grok 4.7, 4.6 and 4.5 with examplesWe price requests to Grok 4.7, 4.6 and 4.5 in Zukko on three scenarios and compare with official xAI prices. Formulas are shown and the arithmetic can be checked.
- DeepSeek API for free: is there a free tier and what is the minimum costWe do not promise free access, but the minimum is very low. A formula-based count of how many requests fit into one dollar.
- DeepSeek API price: cost of V4 Pro and V4.1 Flash worked throughWhat requests to three DeepSeek models cost: the formula, three typical scenarios at 10,000 requests, the role of the cache and a usage-based cost script.
- opencode agents: setting up roles, models and toolsA custom agent in opencode is a role, a model and a set of permissions. A working config where a cheap model handles routine work and a stronger one edits code.