How do Anthropic and OpenAI prompt-cache pricing models work and what counts as a cache hit?
Explain how prompt caching is priced by Anthropic and by OpenAI. What counts as a cache hit, what doesn't, and what should an application architect do to maximize hit rate?
Prompt caching reuses the KV state of a byte-identical prefix at a steep discount, so put stable content first and dynamic content last to maximize hit rate.
Imagine a coffee shop where the barista has to read your whole life story before every order, charging you per word. With prompt caching, the barista writes your fixed story (who you are, your usual notes) onto a card once, keeps it behind the counter, and only reads the new bit each visit. Reading the card costs almost nothing compared to re-reading everything. But the card only works if the story is word for word identical to last time. Change one comma at the top and the barista throws the card away and rereads it all. The card also expires after a few minutes of no visits. So you keep the unchanging part at the top, the new order at the bottom, and you visit often enough that the card stays warm.
Detailed answer & concept explanation~7 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 min: byte-identical prefix hit rule + Anthropic 10 percent read, write fee, TTL + OpenAI flat 50 percent auto + prompt ordering rule + savings math + high-impact workloads.
Real products, models, and research that use this idea.
- Anthropic's Claude Opus 4.7 API exposes cache_control breakpoints so an agent can cache a long system prompt and tool schema across a multi-turn loop.
- OpenAI's GPT-5.5 automatically caches prompt prefixes above its length threshold, giving a 50 percent input discount with no code changes.
- RAG stacks on LangChain place retrieved documents and few-shot examples ahead of the user query specifically to keep the cached prefix large.
- Cursor and similar coding agents cache a stable repository-context and instruction header so each edit request only pays full price on the new diff.
- Customer support bots cache a shared policy and persona system prompt across thousands of sessions, where the prefix is the bulk of every request.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does Anthropic add a write surcharge while OpenAI does not?
QHow would you measure and monitor cache hit rate in production?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Assuming any semantically similar prompt hits the cache. A hit needs a byte-identical prefix, so one changed token, reordered tool, or stray whitespace high in the prompt invalidates everything below it.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.