Prompt Caching Cuts LLM Bills 90% — Production Setup
Resending the same 10k-token prompt every call wastes thousands.
20+ years shipping production ML systems and the infrastructure behind them. Written from production experience, not tutorials.
- ✓An LLM API account (Anthropic, OpenAI, or Google)
- ✓Basic token and pricing literacy
- ✓A production-ish prompt over 1k tokens
- Prompt caching reuses computed KV tensors for repeated prompt prefixes — cached reads cost 0.1x base input (90% off) on Anthropic-style pricing
- Anthropic model: explicit cache_control breakpoints, 5-min TTL writes at 1.25x base, 1-hour writes at 2x, minimum ~1024 tokens on Sonnet-class models
- Performance insight: cached prefixes skip recompute entirely — teams report up to 90% savings on cached portions plus measurably lower time-to-first-token on long prompts
- Production rule: stable content first (system, docs, few-shots), volatile content last (query, timestamps) — any early byte change zeroes the hit rate
- The March 2026 silent TTL shift (1h to 5min) inflated real bills 17-32%; monitor creation-versus-read token ratios and pin TTLs explicitly
- Biggest mistake: timestamps or request IDs inside cached blocks — every request hashes differently and you pay the write premium for zero reads
Picture a restaurant where the chef re-reads the entire cookbook before cooking every single dish — even the dishes they've made a thousand times. That's an LLM without caching: every request reprocesses your long instructions from scratch. Prompt caching is giving the chef a prep station where the chopped vegetables and measured spices wait ready. As long as the recipe start stays identical, cooking begins halfway through — faster and cheaper. But move one ingredient (a timestamp, a reordered paragraph) and the chef throws everything out and starts over. The art is arranging your recipe so the stable prep stays untouched at the front while only the fresh garnish changes at the end.
| Chrome | Firefox | Safari | Edge |
|---|---|---|---|
| ✓ | ✓ | ✓ | ✓ |
LLM bills scale with tokens, and most production prompts resend the same system instructions, documents, and examples on every call. Recomputing identical prefixes thousands of times a day is pure waste. You'll see it the moment you price a RAG feature at scale.
Prompt caching fixes exactly that. Providers store the processed prefix and reuse it, cutting cached-portion costs by up to 90% and trimming time-to-first-token. It's the single biggest cost lever in most LLM APIs.
But caching is prefix-sensitive in ways that surprise teams. One timestamp in the wrong block zeroes your hit rate. A silent TTL default change once inflated bills 17-32% across the industry.
This guide shows the prompt layouts, TTL math, and monitoring that keep caching saving money instead of quietly spending it.
How Prompt Caching Works — KV Reuse, Not Magic
Transformer inference splits into prefilling (processing your prompt into KV tensors) and decoding (generating tokens). For long prompts, prefilling dominates cost and time-to-first-token. Resending a 10k-token system prompt a thousand times a day means paying for the same prefilling a thousand times.
Caching stores those KV tensors keyed by prompt prefix. A matching prefix skips prefilling and starts decoding immediately — cheaper (0.1x reads) and faster (lower TTFT). All major providers offer it: Anthropic via explicit breakpoints, OpenAI and Google automatically for eligible requests.
Minimum thresholds gate everything: typically 1024 tokens (Anthropic, OpenAI) to 4096 (Google). Below that, requests process normally with no error and no benefit — the silent case teams misread as broken config.
Set Breakpoints Right — Stable Early, Volatile Late
Anthropic's pattern is explicit: attach cache_control to the stable block (usually system), keep the volatile user message after it. The response usage fields tell you exactly what happened — creation tokens on first call, read tokens on subsequent ones.
Order is contractual: caching covers tools, system, and messages in that order up to the breakpoint. Put the long stable content early, the per-request content late, and never split stable content across volatile insertions.
Up to four breakpoints are allowed, so large RAG prompts can cache system plus document blocks separately. Each breakpoint is a prefix boundary — everything before it must be byte-identical for a hit.
TTL Math — 5 Minutes vs 1 Hour Break-Even
The TTL math decides the tier. Five-minute writes cost 1.25x base and refresh free on every hit — an active conversation stays cached cheaply forever. One-hour writes cost 2x and need roughly two reads per write to break even.
Chatty sequential traffic belongs on 5-minute. Cross-session stable artifacts (knowledge packs, few-shot libraries) with proven reuse justify 1-hour. Everything else on 1-hour is paying double for expiry.
The March 2026 incident is the cautionary tale: a default shift from 1h to 5min turned normal work pauses into full recomputes, inflating costs ~26% with no code change. Explicit TTLs plus ratio monitoring would have caught it in a day.
Prompt Layouts That Maximize Hit Rates
Design prompts cache-first: system instructions, retrieved docs, and few-shot examples as frozen early blocks; user query, timestamps, and session IDs late or outside cached regions. Template engines should render stable sections from versioned files, not inline string building that drifts.
Keep tool definitions stable too — reordering tools changes the prefix hash. Pin tool order, descriptions, and schemas; version them deliberately.
For agents with long horizons, research shows naive caching still helps but ordered, compact context helps more. Keep working memory small and stable rather than appending endless history before the breakpoint.
OpenAI, Google, and Gateway Caches Compared
OpenAI and Google cache eligible prefixes automatically — no breakpoints, but the same stability rules apply. That convenience hides the same volatility traps, so monitor cached-token counters (cached_tokens > 0) the same way.
Google adds storage billing for cache entries (hourly per million tokens), which changes the math for huge rarely-reused prefixes. LiteLLM-style gateways add their own response caching (Redis, S3) for identical requests — a different layer that complements prefix caching rather than replacing it.
Multi-provider teams should abstract TTL and breakpoint config per provider behind one interface. The concepts transfer; the parameters don't.
Monitor Like Production — Dashboards, Alerts, Realistic Tests
Production caching needs a dashboard: creation versus read tokens, hit rate by prompt template, cost per request before and after. Alert when creation spikes without matching reads — that's volatility or a TTL shift, and it costs money every hour it persists.
Review provider changelogs on a schedule and re-verify minimums and TTL behavior quarterly. Parameters move: minimums, lifetimes, and multipliers have all changed within the last year.
Load-test with realistic pauses, not back-to-back blasts. Back-to-back tests show perfect hit rates that real traffic with coffee breaks never achieves — the TTL interacts with human rhythms, not benchmark loops.
The Silent TTL Downgrade That Inflated Bills 26% in a Month
- Monitor the creation-to-read ratio like a production metric, not a billing footnote. Silent default changes have inflated industry bills 17-32% before.
- Pin TTLs explicitly per workload instead of inheriting defaults. Defaults are the provider's choice, not your strategy.
| File | Command / Code | Purpose |
|---|---|---|
| cached_call.py | client = anthropic.Anthropic() | Set Breakpoints Right |
| python3 - <<'EOF' | TTL Math | |
| for i in 1 2; do | Monitor Like Production |
Key takeaways
Common mistakes to avoid
4 patternsPutting the user message before the cached system prompt
Burying a timestamp inside the cached prefix
Defaulting everything to the 1-hour TTL
Assuming short prompts benefit from caching
Interview Questions on This Topic
How does prompt caching work and what does it cost?
Frequently Asked Questions
20+ years shipping production ML systems and the infrastructure behind them. Written from production experience, not tutorials.
That's LLMOps. Mark it forged?
3 min read · try the examples if you haven't