Cache Me If You Can- Prompt Caching's Fine Print
Prompt caching gets talked about like a coupon that never expires- anything the model has already seen bills at a fraction of the price. The figure that gets passed around is "5 to 10%" of normal. An agent re-reads the same instructions, tools and history on every single turn (where an agent's tokens go). Caching all of it looks like the efficient move.. who'd turn down 90% off?
The discount is real- it's right there on Anthropic's pricing page, next to a charge on the way in. Caching a prompt that never gets reused costs more than not caching it at all- 25% more on the default cache, double on the long one.
How the Bill Works
The cache works on the front of the prompt, the "prefix"- everything from the very first token up to a marker that says where the reusable part ends. Each new request gets matched against what was recently processed, in a fixed order: tools first, then the system prompt (the standing instructions), then the messages. Anthropic's docs ask for "100 percent identical prompt segments". One character changed early on and everything after it counts as brand new.
A write is the first time a prefix goes into the cache. A hit is any re-read after that, while the entry is still warm. Per million tokens, checked October 26, 2026:
| Model | Normal input | 5-min write | 1-hour write | Hit |
|---|---|---|---|---|
| Haiku 5.5 (prompts up to 100,000 tokens) | $0.10 | $0.125 | $0.20 | $0.01 (10%) |
| Sonnet 5.5 | $2 | $2.50 | $4 | $0.10 (5%) |
| Opus 5.5 | $4 | $5 | $8 | $0.20 (5%) |
| Fable 5.1 | $10 | $12.50 | $20 | $0.25 (2.5%) |
For reads, the "5 to 10%" figure holds on most of the lineup- 10% of normal on Haiku, 5% on Sonnet and Opus- and undersells Fable 5.1, where a hit costs 2.5%. What it leaves out is the write (the same figure came up in managing agents like staff). On the five-minute cache a write costs 25% more than a plain read of the same tokens, on the one-hour cache 100% more. The five minutes run from the start of the last request that touched the entry, with every hit resetting the clock at no charge.
A five-minute write costs a quarter of the normal input price extra. A single hit saves at least 90% of the normal price on any of these models, more than enough to cover that after one reuse. The one-hour write costs a whole extra normal price. No single hit gets that back- it takes two reuses before the hour cache comes out ahead of no cache at all.
When Caching Costs More
A prompt that only ever gets sent once pays the write premium for a hit that never comes- a single summary, a one-off classification run, a quick question with a big document attached.
A timestamp in the system prompt, a "today is Monday" line, a tool list that comes out in a different order on each request- any of those near the top and the prefix never matches. Every request writes a fresh entry. None of them ever gets read. Anthropic's troubleshooting list even names Swift and Go, two programming languages that can shuffle the order of keys when they turn data into JSON (the text format APIs talk in). The cache matches on the exact bytes, not on what they mean. How many system prompts out there open with today's date....
The five minutes start counting when a request starts, not when its answer finishes. Anthropic's example is an answer that takes four minutes to stream back (arriving piece by piece as it's written)- the follow-up then has about one minute to go out before the entry expires and the whole prefix gets written again at the premium.
A cache entry only exists once the first response starts coming back. Fire ten requests at the same instant ("fanning out") and they can all miss.. all ten paying to write, since none of them waited for the first answer to start.
Each model keeps a cache of its own. In Claude Code, switching models halfway through a task means the next turn re-reads the whole conversation uncached and writes it all over again. Turning on fast mode (Claude Code's quicker, pricier output setting) does the same, since fast and standard speed keep separate caches. Changing the effort level- the dial between thorough and quick- used to break it as well.. it still does on older models. On Opus 5.5, Sonnet 5.5, Haiku 5.5 and Fable 5.1, signed in with an API key or a subscription, the cache now survives an effort change.
Same Prompt, Five Ways
Napkin math, on an example setup: a 50,000-token prefix- instructions, tool definitions, a reference doc- on Opus 5.5. Uncached, that prefix costs $0.20 every time it goes out. Writing it to the five-minute cache costs $0.25, to the one-hour cache $0.40, and every hit after that costs one cent. Output and the changing end of each request are left out of these numbers- they cost the same with caching on or off.
Sent once, the uncached prompt is the cheapest of the three- $0.20 against $0.25 and $0.40. Sent ten times in a steady stream, caching does what it says on the tin: $2.00 uncached against $0.34 on the five-minute cache, about 83% off.
Stretch those same ten calls six minutes apart and the five-minute cache lapses between every one of them. Ten writes, zero hits, $2.50.. a quarter more than not caching at all. The one-hour cache stays warm through the gaps and comes in at $0.49. Fire all ten at once and, worst case, nothing is cached yet when they go out- $2.50 on the five-minute cache. The hour cache lands on $4.00, double the uncached bill! A timestamp at the top of the prompt lands in exactly the same place, with every call writing and none reading.
Two calls twenty minutes apart on the one-hour cache cost $0.41 against $0.40 uncached- a hair worse. A third call inside the hour flips it to $0.42 against $0.60 uncached, about 30% less.
Doing It So It Pays
Instructions, tool definitions and reference docs belong at the top, where they stay identical from one request to the next. Dates, user details and the new question go at the bottom, after the marker- Anthropic's docs say to put it "on the last block that stays identical across requests". Anything after the marker bills at the normal rate with no write premium.
On Anthropic's API nothing gets cached unless the request asks for it with a cache_control marker. A prompt that won't come back can go without one- no marker, no premium.
For parallel work, the docs suggest sending the first request, waiting until its answer starts streaming back, then sending the rest. Nine of the ten then find the prefix already cached and pay the hit price instead of the write price.
A steady cadence- a request every few minutes- belongs on the five-minute cache, which refreshes for free with each hit. The one-hour cache earns its double-price write when the gaps run between five minutes and an hour and at least two reuses are coming.
Every API response reports two numbers worth watching- cache_creation_input_tokens, the writes, and cache_read_input_tokens, the hits. When writes keep outnumbering reads, the cache is costing money instead of saving it. Claude Code shows a "Prompt cache (main)" line in its session stats with the share of input served from cache, the misses, and whether the cache is warm right now. Anthropic's API also has a cache diagnostics option that compares two requests and names the spot where the prefix split.
"usage": {
"cache_creation_input_tokens": 0, <- writes (premium)
"cache_read_input_tokens": 100000, <- hits (the discount)
"input_tokens": 50 <- after the breakpoint, normal price
}
Batch requests (a pile of jobs handed over to finish within 24 hours at half price) and caching stack their discounts. Batched requests run at the same time, though. Anthropic only promises cache hits there on a "best-effort" basis, and suggests the one-hour cache when a batch shares context.
Other Shops, Other Rules
OpenAI switches prompt caching on by default. Up to GPT-5.5 there was no charge to write.. from GPT-5.6 on there is. A write costs 1.25 times normal input for the default 30-minute lifetime and 2.5 times for a 12-hour one, while reads run a tenth of normal on most of those models (a twentieth on GPT-6.1 Sol). There's also an explicit mode where a request with no breakpoints set skips caching, and the write fee, entirely. OpenAI's guide works the same arithmetic- one write plus one full reuse comes to 1.35 times the normal input, against two times with no cache.
Google's Gemini caches on its own on 2.5 and newer models, with "no cost saving guarantee"- the saving only shows up when a request happens to land on a cached prefix. Its pricing page lists one context-caching price per model and no separate write fee. Explicit caching, where a developer sets the cache up and decides how long it lives, is still in beta and isn't offered from Gemini 4 Argon onward. It bills storage by the hour for as long as the cache exists, up to $4.50 per million tokens per hour (Gemini 3.1 Pro Preview, the highest listed), whether anything reads it or not.
The Claude Code Wrinkle
On a Claude subscription, within the plan's included usage, Claude Code's main conversation asks for the one-hour cache- the double-price write. With an API key, or once a subscription spills over into paid usage credits, it drops to five minutes. Anyone paying per token who wants the hour can set promptCacheTtl to 1h in settings.. FORCE_PROMPT_CACHING_5M=1 forces five minutes on everything, which the docs suggest for debugging or comparing the two clocks.
Editing CLAUDE.md (the project instruction file) in the middle of a session doesn't break the cache. It doesn't take effect either! Claude Code reads the file once at the start and holds onto that copy until the next /clear, /compact or restart.
Anyone dug into their own cache numbers yet? Writes outrunning reads, a timestamp hiding in a system prompt, a model switch that quietly doubled a turn.. drop it in the comments.
Glossary
- Prompt caching — storing the processed start of a prompt so later requests that begin the same way can re-read it cheaply.
- Prefix — the start of a prompt, matched token for token from the very first one.
- Token — the chunk of text (roughly a short word) models read, write and bill by.
- MTok — a million tokens, the unit API prices are quoted in.
- Cache write — the first time a prefix gets stored; billed above the normal input price.
- Cache hit — a re-read of a stored prefix; billed well below the normal input price.
- TTL (time to live) — how long a cache entry survives without being used.
- Cache breakpoint /
cache_control— the marker in an API request that says where the cacheable part ends. - Streaming — an answer arriving piece by piece while it's still being generated.
- Fan-out — sending many requests at the same time instead of one after another.
- JSON — the plain-text format APIs use for structured data.
- Effort level — a setting on newer models trading thoroughness against speed and cost.
- Fast mode — a faster, pricier output speed in Claude Code with its own separate cache.
- Message Batches API — Anthropic's way to send a pile of requests to be done within 24 hours at half price.
- Cache diagnostics — an API option that compares two requests and reports where their prefixes split.
- Implicit / explicit caching — caching the provider does on its own, versus caching a developer sets up and controls.
- CLAUDE.md — the instruction file Claude Code reads at the start of a session.
- /compact — the Claude Code command that swaps the conversation history for a summary.
Sources
- Prompt caching- Anthropic docs — prices and multipliers, lifetime counted from request start, exact-match rule, parallel requests, invalidation, Swift/Go key order, 1-hour cache guidance
- Pricing- Anthropic docs — per-model input, cache write and cache hit prices
- Cache diagnostics- Anthropic docs — comparing two requests to find where the prefix diverged
- Batch processing- Anthropic docs — batch and cache discounts stacking, "best effort" cache hits in batches
- How Claude Code uses prompt caching- Claude Code docs — actions that invalidate the cache, TTL per billing type, promptCacheTtl, CLAUDE.md mid-session
- Manage costs effectively- Claude Code docs — the "Prompt cache (main)" session line
- Prompt caching- OpenAI API docs — on by default, write charges from GPT-5.6, the 1.35x break-even example
- Context caching- Gemini API docs — implicit caching on by default for 2.5 and newer
- Context caching (generateContent)- Gemini API docs — "no cost saving guarantee", explicit caching in beta, default 1-hour TTL, storage billing
- Pricing- Gemini API docs — cached-read prices and hourly storage price
- Usage Limit Reached? Not So Fast..- zkitszo — where an agent's tokens go each turn
- Run It Ten Times, Then Write the SOP- zkitszo — managing agents like staff, where the "5 to 10%" figure first got checked
- What I'd Learn Instead of Prompt Engineering in 2027?- Nick Saraev, YouTube, Oct 23, 2026 — the "5 to 10%" caching figure
Comments
Post a Comment