Prompt caching shows up on Anthropic and OpenAI pricing pages, what does it actually do?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
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.
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.
What an interviewer would ask next. Try answering before peeking at the approach.
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.