Prompt caching and the KV cache: why cached tokens decide an agent's bill
AI agents resend their whole conversation on every model call, so most of their input tokens are ones the model has already processed. Prompt caching keeps that processed context, the KV cache, and bills it at a fraction of the normal price. In a typical coding-agent task 90% of input is cached, so the cached-token price often decides the bill: DeepSeek V4 Pro charges $0.003625 per million cached tokens, Claude Opus 5.5 charges $0.20.
What is the KV cache?
When a model reads a prompt, it computes a key and a value for every token at every layer. Those keys and values, the KV cache, are what the model attends to when it writes the next token. Computing them is most of the work of reading a long prompt. If the next request starts with the same tokens, the cached keys and values can be reused instead of recomputed.
What is prompt caching?
Prompt caching is the provider keeping that KV cache between requests and charging less for the tokens it reuses. A request that shares a prefix with an earlier one, the same system prompt, tools and conversation so far, gets those tokens at the cached-input price. Only the new tokens at the end pay full price.
Why it matters more for agents
An agent's calls are almost all shared prefix. Each turn adds a tool result and a little reasoning to a conversation that is otherwise identical to the last call's. In our typical coding-agent task, 1.8M of 2M input tokens are cached. That shifts the bill from the input price to the cached price:
| Model | Cached input per 1M | Per task |
|---|---|---|
| DeepSeek V4 Pro | $0.003625 | $0.13 |
| DeepSeek V4.1 Flash | $0.006 | $0.12 |
| Claude Opus 5.5 | $0.2 | $1.96 |
| Qwen3.8-Max | $0.25 | $1.09 |
| GLM-5.3 | $0.26 | $0.92 |
| Kimi K3 | $0.3 | $1.74 |
| MiniMax M3 | $0.3 | $0.65 |
| GPT-6 Astra | $1 | $5.80 |
This is why Kimi K3, with cheaper input and output than Opus 5.5 but a higher cached price, saves only about 11% on cache-heavy agents, while DeepSeek V4 Pro saves 93%.
Why caches miss during agent loops
The cache lives in GPU memory, which is scarce. A serving stack built for chat evicts idle sessions to make room. An agent is idle every time it runs a tool, and tests or builds can take minutes, so its context is often gone by the time the next call arrives. That call then pays full price and waits while the whole context is recomputed.
How to raise your cache hit rate
- Keep the prefix stable. Put the system prompt and tool definitions first and don't change them mid-session. A timestamp at the top of the prompt breaks the cache on every call.
- Append, don't rewrite. Add tool results to the end of the conversation. Editing or reordering earlier messages invalidates everything after the change.
- Keep a session on one replica. Caches are per GPU. Routing a session's calls to the same replica keeps its cache warm.
- Hold context through tool runs. Serving that knows a session is waiting on a tool can keep its cache, or move it to CPU memory and back, instead of evicting it.
The last two are the serving provider's job. They are the core of how we serve agents.
Common questions
What is prompt caching?
Prompt caching is a provider keeping the processed form of a prompt, the KV cache, between requests and charging less for tokens it reuses. Requests that share a prefix with an earlier one pay the cached price for those tokens.
How much of an agent's input is cached?
Most of it. An agent resends its whole conversation every turn, so on a typical coding-agent task about 90% of input tokens are cached, which makes the cached-token price the biggest line on the bill.
Which model has the cheapest cached tokens?
Among the leading models, DeepSeek V4 Pro at $0.003625 per million and DeepSeek V4.1 Flash at $0.006. Claude Opus 5.5 charges $0.20 and GPT-6 Astra $1.
More guides
- Open-source LLM inference for AI agents: the complete guide
- The best open-source models for coding agents in 2026
- How to fine-tune an open-source LLM for your AI agent
- Self-hosted LLMs vs an inference API vs on-prem: how to choose
- How to run Claude Code on open-source models
- Cost per successful task, explained