Same files, different bill: tokenizers and agent overhead

Developers who plug an alternative model into an agent built for another vendor often report the same puzzle. The task is identical, the files are small, yet the agent hits its context limit far sooner than with the original model. Others look at a usage dashboard after a couple of months and see a total that seems impossible for the work they remember doing.
Both puzzles have the same roots. A token is not a fixed unit of text; each model family slices text with its own tokenizer. On top of that, agents add large amounts of hidden material to every request, and how a given model and client handle that material varies widely. This article explains the mechanics so you can predict and measure token use instead of being surprised by it.
Frequently asked questions
What is a tokenizer?
A tokenizer is the component that splits text into the units a model reads and writes. Each model family trains its own vocabulary, so the same sentence can become a different number of tokens depending on the model.
How large can the difference between tokenizers be?
It depends heavily on the text. For plain English prose the gap is often modest. For code, non-Latin scripts, long numbers or unusual formatting, it can be considerably larger. The only reliable answer is to measure on your own content.
Why would an agent fill context faster with a different model?
Besides tokenizer differences, agents tuned for one model may behave differently with another: reading more files, retrying tool calls, producing longer reasoning or failing to use caching. Each of these adds tokens.
Do context window sizes compare directly between models?
Only roughly. A 128k window on one model and a 128k window on another hold different amounts of actual text, because their tokens are different sizes for your content.
How does prompt caching affect token counts?
Caching does not reduce how many tokens a request contains, but some providers bill cached input at a lower rate and process it faster. Dashboards may count cached tokens separately, which can make totals look huge while costs stay moderate.
Which is more accurate, a character-based estimate or the API's usage field?
The usage field returned by the API. Character estimates such as four characters per token are rough guides for English and can be far off for code or other languages.
Does the free-ai endpoint report tokens?
Yes, responses include a standard usage object with prompt and completion tokens, as with other OpenAI-compatible APIs. Those counts apply to free-ai's own tokenizer, not to Claude's.
Tokens are a model-specific unit
When a provider says a model has a certain context length or charges a certain price per million tokens, the token is defined by that model's tokenizer. Tokenizers are trained on large text corpora and learn which character sequences are common enough to deserve a single token. A model trained mostly on English prose learns long tokens for common English words. One trained with more code learns tokens for frequent programming patterns.
The consequence is that token counts do not transfer between model families. A file that is 2,000 tokens for one model might be noticeably more or fewer for another. When you switch models inside the same tool, every limit and estimate you had built up quietly shifts.
Code and whitespace
Indentation, long identifiers and symbols are tokenized very differently across vocabularies. Some tokenizers merge runs of spaces efficiently; others spend a token on nearly every few characters. Deeply indented code can cost much more on one model than another.
Languages other than English
Text in many non-English languages tends to use more tokens per word, and the penalty varies by tokenizer. A multilingual application can see large swings when it changes models, even with identical prompts.
The hidden material inside every agent request
Tokenizers explain part of the gap. The larger part, in agent workflows, is the material you never typed. A coding agent sends a system prompt describing its behaviour, the definitions of every tool it can call, the conversation history, the contents of files it has read and the results of commands it has run. On each turn, much of this is sent again.
Tool definitions alone can be substantial. Each tool has a name, a description and a JSON schema for its arguments. An agent with dozens of tools, plus several MCP servers, may carry thousands of tokens of definitions before the first user message. Teams evaluating MCP servers often want to measure this exact overhead per server.
History accumulates
Stateless APIs need the full conversation on every call. A long session therefore resends earlier messages, file reads and tool outputs repeatedly. The total processed across a session grows much faster than the visible conversation.
Tool outputs are often the biggest item
A command that prints a long log or a file read that returns a large module can dwarf everything else. One verbose test run can add more tokens than an hour of chat.

Why a swapped model can behave less efficiently
Agents are usually tuned for a particular model family. Their prompts, tool descriptions and stopping rules assume certain habits: how eagerly the model reads files, whether it batches tool calls, how long its reasoning runs. Put a different model behind the same agent, and those assumptions may no longer hold.
A model unfamiliar with the agent's conventions might read whole directories when one file would do, re-read files it already saw, call tools one at a time instead of in parallel or produce verbose thinking. None of this means the model is worse in general. It means the pairing is not tuned, and the cost shows up as context consumption.
Caching may not apply
Some agents rely on provider-side prompt caching to keep repeated context cheap. If the alternative model or its gateway does not support the same caching mechanism, every resent token is processed in full.
Context reporting differs
Clients estimate how full the context is using their own counting. If they apply one model's tokenizer assumptions to another model's traffic, the displayed percentage can be misleading in either direction.
How huge monthly totals happen
Seeing a usage total in the billions after a couple of months of agent work feels absurd until you do the arithmetic. Suppose each agent turn sends 50,000 tokens of context, and a busy day has several hundred turns across sessions. That alone is tens of millions of tokens per day, most of it repeated context rather than new work.
Cached tokens complicate the picture. Dashboards may list cached reads alongside fresh input, so the headline number reflects everything processed, while the cost depends on how much was cached and how the provider prices it. Check the provider's own documentation for how it counts and bills cached input.
Exploration is expensive
Sessions spent exploring capabilities, generating long documents or letting an agent wander through a codebase consume far more than targeted edits. If a month included lots of experimentation, a big total is expected rather than a sign of a billing error.
Output tokens cost more but are fewer
Many providers price output above input. In agent work, though, input usually dominates the count because context is resent each turn. Look at both numbers before deciding where to optimise.
- Turns per day multiplied by average context per turn gives a first estimate.
- Large tool outputs and file reads usually dominate the average.
- Cached input may be counted in totals but billed differently.
- Long sessions cost more per turn than several short ones with focused context.

Measuring tokens on your own content
Estimates are useful for planning, but measurements settle arguments. The simplest method is to send a representative request to each model and read the usage field in the response. Because the field is computed by the provider with the model's own tokenizer, it is the authoritative count.
Run a small set: a typical prompt, a code file, a paragraph in each language you support. Record prompt tokens per model. Within an hour, you will know how much your content shifts between models, which no general rule of thumb can tell you.
Keep max_tokens at 1 for counting
Setting max_tokens to 1 limits the response so the test measures input cost almost exclusively. Remember that even tiny calls count against per-request limits on rate-limited endpoints.
from openai import OpenAI
client = OpenAI(base_url="https://api.apikeyclaudefree.com/v1", api_key="not-needed")
samples = {
"prose": open("sample_prose.txt", encoding="utf-8").read(),
"code": open("sample_module.py", encoding="utf-8").read(),
}
for name, text in samples.items():
resp = client.chat.completions.create(
model="free-ai",
messages=[{"role": "user", "content": text}],
max_tokens=1,
)
u = resp.usage
print(f"{name}: {len(text)} chars -> {u.prompt_tokens} prompt tokens "
f"({len(text) / u.prompt_tokens:.2f} chars/token)")Measuring tool and MCP overhead
To isolate the cost of tool definitions, send the same short user message twice: once with no tools and once with the full tool list your agent uses. The difference in prompt tokens is the overhead per turn. Repeat with each MCP server's tools added separately to see which servers are expensive.
This test is especially useful when comparing MCP servers that offer similar functions. A server with twenty verbose tools may cost several times more per turn than one with five concise ones, regardless of what they do. The comparison of MCP connectors against local exports discusses this trade-off for knowledge bases.
Trim descriptions without losing meaning
Long tool descriptions are often written for humans. Shorten them to the facts the model needs to choose and call the tool correctly. Test that tool selection still works afterwards, especially with smaller models.

Practical ways to keep counts predictable
You cannot change a model's tokenizer, but you control most of what goes into each request. The biggest gains usually come from limiting what tools return and keeping sessions short and focused.
Budget per task, not per month
Estimating tokens for a typical task, then multiplying by expected tasks, gives a far better forecast than watching a monthly meter. It also shows quickly when a change in agent or model shifts the per-task cost.
- Cap the length of command output and file reads that tools return.
- Disable MCP servers you are not using in the current task.
- Start fresh sessions for unrelated tasks instead of continuing one long thread.
- Summarise long history into a short note and continue from that.
- Measure each model on your own content before switching an agent to it.
Where free and paid models fit
Token economics push many people toward mixed setups: an expensive frontier model for the hard reasoning and a cheaper or free one for routine work. The keyless endpoint here serves free-ai, an independent open-weight model of around 35B parameters with a 32,000-token context. It is not Claude, and this site is not affiliated with Anthropic.
A 32k window is small next to the very large windows some commercial models offer, so it suits focused tasks rather than whole-repository agents. For those, Claude and other frontier models are the stronger choice. The article on choosing a context size covers which tasks fit in which window, and how max_tokens interacts with quotas explains another common source of surprise.

Send a test prompt to the keyless free-ai endpoint from the chat box on the home page, no sign-up or key required.
Read also
- How to Trim Huge Build Logs Before Asking an AI Model for Help
- How to Analyse an Ad Campaign Export With an LLM API, Step by Step
- Why Don't AI Agents Know Today's Date or the User's Time Zone?
- Why Does a Coding Assistant Keep Adding Its Own Vendor's API?
- Coding-Tuned Model vs All-Round Model: Which Suits Everyday Work?