Prompt Caching Economics: The Cheapest Lever in Agent Coding

An agent session re-sends the same repository context on every turn, so most of what you pay for is text the model has already read. Caching charges that repetition at 2% to 10% of the input rate, which in a modelled 20-turn refactor is a 70% saving – larger than the 50% you get by dropping a tier from Claude Opus 5.5 to Claude Sonnet 5.5, and without giving up any model quality. The catch is that the discount belongs to the prefix, not to you: reorder a file list and it disappears.

Anthropic cache read
2.5% – 10%
of base input price, model-dependent
DeepSeek off-peak cache hit
$0.003 / M
V4.1 Flash, 2% of the $0.15 input rate
Cache write premium
1.25x – 2x
5-minute vs 1-hour Anthropic TTL
Modelled session saving
70%
Sonnet 5.5, 20 turns, 90% hit rate

Somewhere around the eighth turn of a refactor, the arithmetic stops resembling a conversation. The agent has read forty files, run the tests twice and repaired one failure. Every turn re-sends the repository context, the tool schema and the system prompt, and the model has seen all of it before. You are paying full price for a reread.

Caching is the fix, and it is the largest single lever in agent coding. Anthropic charges a cache read at 5% of the input rate on Claude Sonnet 5.5 and Opus 5.5, and 2.5% on Fable 5.1. DeepSeek charges 2%, which at the off-peak input rate is $0.003 per million tokens.

But the number that matters is not on any price list. It is how much of your prompt is stable from one turn to the next, and nothing in the vendor documentation can tell you that about your own repository.

The argument in three steps: caching prices repetition, the write premium sets a deadline on the prefix, and the saving is bigger than the one you get by switching to a cheaper model.

Caching prices repetition, not tokens

Read the published rates as a statement about what the vendors think you are buying. Anthropic's base input for Claude Sonnet 5.5 is $2.00 per million tokens, the cache read is $0.10 and the cache write is $2.50. The first read of a cached prefix costs a quarter more than a normal prompt; every read after it costs a twentieth.

That shape only makes sense if the vendor expects the same text to arrive repeatedly. A one-shot prompt never earns the write premium back. A twenty-turn agent session earns it on the second turn and keeps earning it for the other eighteen.

DeepSeek's schedule is the same idea with the premium removed. There is no published write charge, and the hit price is 2% of the off-peak input rate: $0.003 per million against $0.15. A cache miss costs exactly what the prompt would have cost anyway, so on DeepSeek caching is not a decision you can get wrong.

The prices differ by more than an order of magnitude, but the mechanism behind them is identical: the discount is attached to a prefix, not to a request.

The write premium is a deadline on your prefix

A cache write costs 1.25x base input on Anthropic's 5-minute tier, and the entry is only worth buying if something reads it before it expires. One read pays the 25% back; a second read is profit. The 1-hour tier costs 2x and needs two reads before it breaks even.

This is a latency decision disguised as a pricing decision. Terminal agents usually finish a turn in seconds, so a 5-minute TTL covers the gap between turns and the 1-hour tier is a premium for sessions with long human pauses. A developer who leaves for lunch between turns is the customer for the expensive cache; an automated test loop is not.

The failure mode is subtler than expiry. Cache keys are prefix-based, so the cached span ends at the first byte that differs from the previous request. An agent that reorders file reads, inserts a timestamp at the top of the system prompt, or regenerates its tool schema per turn invalidates everything downstream of the change.

Pay the write premium, then throw the prefix away, and you have paid 25% more than not caching at all.

A stable prefix beats a cheaper model

Take a concrete session. A 60,000-token repository context, re-sent across twenty turns, plus 8,000 tokens of new conversation and tool output each turn. That is 1.2M tokens of prefix and 160,000 tokens of fresh input, and at Sonnet's $2.00 input rate with no caching it costs $2.72 before a single output token.

Now cache it. One 60,000-token write at $2.50, 90% of the 1.2M prefix reads hitting at $0.10, and the rest at the base rate: $0.82, a 70% saving. That is one write and twenty turns, and the result is not sensitive to small changes in the hit rate – at 80% the same session still saves more than half.

Compare the alternative. Dropping from Claude Opus 5.5 to Claude Sonnet 5.5 cuts the input rate by 50% and costs you two intelligence points. Caching the Sonnet session cuts the bill by 70% and costs you nothing but a stable prompt.

That is the whole argument for doing this first.

The counter-case is real: an agent whose work is genuinely different on every turn – a fresh web page per request, a different repository per task, a tool that rewrites its own schema – has almost nothing stable to cache, and will see a hit rate closer to zero than to 90%. The diagnostic is one line of logging on the provider's usage object, which reports cached tokens separately from fresh ones. If the hit rate is under 50%, the prompt is the problem, and no vendor switch will fix it.

What would change the conclusion: a vendor pricing cache reads at the full input rate, or an agent framework that guarantees byte-identical prefixes. Neither exists. Until one does, the cheapest token in agent coding is the one you have already paid for.

Reference

Published cache pricing by model

USD per million tokens, checked 2026-12-03
ModelBase input / MCache write / MCache read / M
Claude Opus 5.5$4.00$5.00 (1.25x)$0.20 (5%)
Claude Sonnet 5.5$2.00$2.50 (1.25x)$0.10 (5%)
Claude Haiku 5.5$0.10$0.125 (1.25x)$0.01 (10%)
Claude Fable 5.1$10.00$12.50 (1.25x)$0.25 (2.5%)
DeepSeek V4.1 Flash 1017 (off-peak)$0.15—$0.003 (2%)
DeepSeek V4.1 Flash 1017 (peak)$0.30—$0.006 (2%)
GLM-5.3 (Z.ai direct)$1.40—$0.26
Kimi K3 (direct)$3.00$3.00$0.30 (10%)

Anthropic's write tier is the 5-minute cache; the 1-hour cache costs 2x base input. DeepSeek publishes no separate write charge.

The modelled 20-turn session

Claude Sonnet 5.5, input only, before output tokens
RouteCompositionInput cost
No caching1.36M tokens at $2.00/M$2.72
One write, 90% hit rate60k write at $2.50/M + 1.08M reads at $0.10/M + 0.12M misses and 0.16M fresh input at $2.00/M$0.82

Assumptions: 60k-token prefix re-sent on each of 20 turns, 8k fresh input per turn, one cache write, 90% of prefix reads hitting, 5-minute TTL. This is a model, not a measurement; a real session's hit rate depends on how the agent builds its prompt.

Three rules that keep the prefix alive

  • Put everything stable first. System prompt, tool schema and repository context in that order, and nothing volatile above them.
  • Never regenerate what you can freeze. A tool schema serialised fresh per turn, with keys in a different order, is a new prefix every time.
  • Route the volume to a cheap cached model. GLM-5.3 and DeepSeek V4.1 Flash both publish cache-hit prices under 10% of base input. A lint or test loop on a cached cheap model with the final patch on a frontier model is usually cheaper than one frontier model doing everything.
← Back to Models Comparison (52 Models) Switch Models Off-Peak (Recipes) →

Got a question, or spotted an outdated price or wrong number? Email hello@codingplans.dev. Every figure links to its source.