An AI token bill is not one number. It is four numbers added together: input tokens that missed the cache, input tokens that hit the cache, output tokens, and sometimes a cache write. Change the mix and the same workload costs an order of magnitude more.
This page explains the four lines, the two places cost accumulates, and how to read your own bill before you try to reduce it.
The four lines on the bill
Uncached input. Every token you send that the provider has not seen recently. This is the expensive line.
Cached input. Tokens the provider recognizes from a previous request and serves from a prefix cache. This is the cheap line, often a small fraction of the uncached price.
Cache write. Some providers charge a premium to store the prefix for reuse. It is a small one-time cost that pays back after a couple of turns.
Output. The tokens the model generates. Output is usually priced higher than input, because generation is more expensive than reading.
The first thing to understand is that input volume, not output volume, usually drives a long-running agent's bill. Every turn resends the conversation, the instructions, the tool list, and the context. A 100-turn session can send millions of input tokens to produce a few thousand words.
The same question on three paths
A worked comparison from a real MCP architecture makes the shape clear.
Assume 15 connected data sources, about 1,500 tokens of raw output per tool call, and a question that needs five tools.
Client-side orchestration. The host model sees every tool definition, decides which to call, receives all five raw results, and then writes the answer. All 15 tools are in context. The measured comparison puts this at about 38,000 tokens.
Search-based routing. The model searches for relevant tools by keyword, loads only the matches, and still receives the raw results. About 18,000 tokens.
An embedded router inside the MCP server. The host model makes one call, receives one synthesized answer, and never sees the raw tool output. About 4,000 tokens.
That is an 89% reduction against client-side orchestration for the same question. The model did not change. The path did.
Why the prefix matters more than the prompt
In a long-running agent, most of the input is a prefix that does not change: system instructions, skills, memory, tool schemas, repository context. The provider can cache that prefix and charge the cached rate for it on every subsequent call.
On a production Hermes deployment, the prefix is roughly 47,000 tokens and the cache read per API call is about 103,000 tokens. The miss share of all tokens sent is 1.33%, which is almost exactly one cold prefix per session.
That is the structural picture. The prefix is large and nearly free. The misses are cold starts, not model failures.
The price gap that makes caching worth the work
Provider pricing is not linear. DeepSeek V4.1 bills cache hits at a small fraction of misses. Off-peak Flash pricing is $0.003 per million cached input tokens against $0.15 per million uncached, a 50x gap. Pro charges more on both sides, $0.022 cached against $0.66 uncached, a 30x ratio and a wider dollar spread.
Anthropic's prompt caching has the same shape at different numbers: cache reads bill at roughly 10% of base input, and cache writes carry a small premium, so the crossover comes after a couple of turns rather than immediately.
The implication is simple. If 98% of your input is cached, you are paying a few percent of the uncached price for the bulk of the work. If your cache hit rate is zero, you are paying full price for a prefix you resend every turn.
Where cost accumulates in an agent
The prefix is unstable. A timestamp, a run ID, or a dynamic skill list in the system prompt changes the prefix on every call. The hit rate collapses to zero without an error.
Sessions are too short. A cold start costs one full prefix. Spread over 100 turns it is noise. Spread over two turns it is most of the bill. One-shot scripts that open a session to ask one question pay the cold prefix every time.
Tool payloads are too large. A tool that returns 20,000 tokens of raw JSON floods the context, and every later turn resends it. Filtering at the server is cheaper than filtering in the model.
The model is too strong for the task. A frontier model classifying support tickets costs more than a small model doing the same job at the same accuracy.
Retries are invisible. A failed call that is retried three times costs three times. Without logging, the retry line is invisible in the total.
How to read your own bill
Hermes records per-session, per-model usage in the profile's state.db. The table session_model_usage has api_call_count, input_tokens, and cache_read_tokens.
select model,
sum(api_call_count) as calls,
sum(input_tokens) as miss_tokens,
sum(cache_read_tokens) as hit_tokens,
round(100.0 * sum(cache_read_tokens)
/ (sum(cache_read_tokens) + sum(input_tokens)), 2) as hit_pct
from session_model_usage
group by model
order by sum(cache_read_tokens) desc;
Three readings matter:
- Miss tokens divided by session count. If it is close to your prefix size, the caching is healthy and every miss is a legitimate cold start.
- The worst 10 percent of sessions. If they are long sessions, something is mutating the prefix.
- Cache read per call. A rising number means the prefix is growing, which is fine until it hits the context limit.
What to do with the numbers
If the hit rate is high and the bill is still large, the workload is genuinely large. Reduce the work or route more of it to a cheaper model.
If the hit rate is low, find the mutation. The usual suspects are a timestamp in the system prompt, a skill loaded after turn one, a model switch mid-session, and a context compression event.
If the miss tokens per session are close to one prefix, the caching is working. Stop optimizing and look at output or tool payloads instead.
What token cost is not
It is not the same as the subscription price. A $20 plan and an API bill measure different things. The plan bundles usage. The API meters it.
It is not a proxy for quality. A cheaper model that fails 20 percent of the time is more expensive per successful task than a frontier model that succeeds.
It is not fixed. The same workload can cost 30 to 50 times more depending on cache behavior and routing. That is the lever.
Sources and what they change
Provider documentation is the only reliable source for the pricing mechanics. Three of them matter here.
- Anthropic prompt caching. The cache has a five-minute default lifetime and refreshes for free on each use. That is why a burst of calls is cheaper than the same calls spread across a day.
- DeepSeek context caching. A hit requires a full match of a cache prefix unit. A prompt that is almost the same is a miss at full price, which is the quiet failure behind most bad bills.
- OpenAI API pricing. Published rates per model, so the comparison is arithmetic rather than a vendor claim.
Related
- How to reduce AI token costs: the seven changes, in order.
- Prompt caching: the structural rules and the measurement.
- Model routing: matching the model to the task.
- Perplexity token optimization: research without carrying the payload.
- Hermes case study: the measured 9.69B-token month.
Questions owners ask
A piece of text the model reads or writes, usually smaller than a word. Pricing is per million tokens, and input and output are priced separately.
Because every turn resends the context. A long conversation with a large prefix can send far more input than the visible messages suggest.
No. Caching stores the processed prefix; it does not change the answer. It changes the price of the part that did not change.
Usually yes. Generation costs more than reading. For long-running agents, input volume often dominates anyway.
Stabilize the prefix, run longer sessions, filter tool output at the server, and route routine tasks to a smaller model. Those four changes usually do more than switching providers.

