Prompt caching shows up on Anthropic and OpenAI pricing pages, what does it actually do?
Prompt caching stores the KV state of a prompt prefix server-side so future requests sharing that prefix skip the prefill compute, dropping both cost (cached input billed at a steep discount) and time to first token.
Imagine a coffee shop where every customer asks for the same long list of background details before placing their actual order: 'Hi, I am a tall person, I drink mostly black coffee, I am allergic to dairy, I prefer ceramic cups, I'm in a hurry today, AND I would like a flat white.' The barista has to listen to the whole script every single time. Now imagine the shop remembers your background details from yesterday. You walk in and just say 'flat white' and the barista already knows the rest. The shop charges you a small fee to remember your details, but each subsequent order is faster and cheaper because they skip re-listening to the script. That is prompt caching. The repeated prefix is the script. Skipping the re-read is the savings.
Detailed answer & concept explanation~8 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.
3 min: definition + which phase it skips + Anthropic and OpenAI pricing + structure the prompt rule (stable first, variable last) + TTL constraint + self-hosted equivalents.
| Aspect | Anthropic | OpenAI | Self-hosted (vLLM, SGLang) |
|---|---|---|---|
| Discount on cached reads | ~90% off | ~50% off | Free (you own the GPU) |
| Write surcharge | ~25% on first call | None | None |
| Activation | Explicit cache_control markers | Automatic for prefixes >=1024 tokens | Configurable feature flag |
| Typical TTL | 5 minutes default (extended tiers available) | 5-10 minutes | Configurable; bounded by GPU/SSD |
| Cache key | Tokenized prefix exact match | Tokenized prefix exact match | Tokenized prefix; tree-structured in SGLang |
Real products, models, and research that use this idea.
- Claude Opus 4.7 with a 10000-token tool-definitions system prompt sees TTFT drop from ~1500ms to ~200ms when prompt caching is enabled on Anthropic's API.
- OpenAI's GPT-5.5 automatically caches prefixes of at least 1024 tokens, discounting them at 50% on subsequent matching calls within the TTL.
- vLLM's prefix caching feature applies the same idea to self-hosted inference, deduplicating KV cache across requests that share a system prompt.
- SGLang's RadixAttention extends prefix caching to a tree structure, so concurrent requests sharing partial prefixes can all benefit from cached KV state.
- Cursor and Claude Code use Anthropic's prompt caching to bring per-edit latency down by reusing the cached tool-definitions and codebase context across calls.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does Anthropic charge a write surcharge while OpenAI does not?
QHow does prefix caching in vLLM compare to RadixAttention in SGLang?
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.
Thinking prompt caching saves on output tokens. It only discounts input (prompt) tokens that match a cached prefix; output token billing is unchanged.
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.