Home ML / AI Prompt Caching Cuts LLM Bills 90% — Production Setup
Intermediate 3 min · September 07, 2026
Prompt Caching in Production LLMs

Prompt Caching Cuts LLM Bills 90% — Production Setup

Resending the same 10k-token prompt every call wastes thousands.

N
Naren Founder & Principal Engineer

20+ years shipping production ML systems and the infrastructure behind them. Written from production experience, not tutorials.

Follow
Production
production tested
September 22, 2026
last updated
1,799
articles · all by Naren
Before you start⏱ 25 min
  • An LLM API account (Anthropic, OpenAI, or Google)
  • Basic token and pricing literacy
  • A production-ish prompt over 1k tokens
 ● Production Incident 🔎 Debug Guide
Quick Answer
  • 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
✦ Definition~90s read
What is Prompt Caching in Production LLMs?

Prompt caching is a provider-side optimization that stores the processed key-value (KV) tensors of repeated prompt prefixes so subsequent requests skip recomputation. Instead of re-prefilling the same system instructions, documents, and examples on every call, the model reuses cached tensors — cutting cached-portion costs by up to 90% and reducing time-to-first-token.

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.

Anthropic implements it with developer-controlled cache_control breakpoints (5-minute TTL at 1.25x write cost, 1-hour at 2x, reads at 0.1x, ~1024-token minimums). OpenAI and Google apply caching automatically to eligible prefixes with their own thresholds and TTLs. All variants key on byte-identical ordered prefixes.

The trade-off is sensitivity: any early volatility (timestamps, reordered blocks, edited words) invalidates the cache, and short prompts never qualify. Caching rewards disciplined prompt layout and punishes ad-hoc string building — it is a architecture-level concern, not a flag you flip.

Plain-English First

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.

⚙ Browser compatibility
Latest versions — ✓ supported
ChromeFirefoxSafariEdge

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.

📊 Production Insight
A RAG service resending 8k-token context per query cut input spend dramatically once prefixes stabilized — the prefilling they were rebuying hourly became a single write plus cheap reads.
🎯 Key Takeaway
Caching skips prefilling for repeated prefixes; minimum token thresholds decide whether it engages at all.

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.

cached_call.pyPYTHON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import anthropic
client = anthropic.Anthropic()

SYSTEM = open("system_prompt.txt").read()  # long, stable
resp = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    system=[{
        "type": "text",
        "text": SYSTEM,
        "cache_control": {"type": "ephemeral"},          # 5-min TTL
        # "cache_control": {"type": "ephemeral", "ttl": "1h"}  # 1-hour
    }],
    messages=[{"role": "user", "content": user_query}],  # volatile LAST
)
print(resp.usage.cache_creation_input_tokens,  # written this call
      resp.usage.cache_read_input_tokens)       # served from cache
⚠ Defaults change without announcements
The March 2026 silent TTL change inflated real-world bills 17-32%. Treat provider defaults as mutable and pin your TTLs explicitly.
📊 Production Insight
Teams that log creation-versus-read tokens per request catch volatility bugs within hours. Teams that don't discover them on the invoice.
🎯 Key Takeaway
cache_control on stable blocks, volatile query last, and read the usage counters to prove hits.

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.

BASH
1
2
3
4
5
6
7
8
9
# Break-even rule: 5-min writes (1.25x) need ~1 reuse; 1h writes (2x) need ~2
python3 - <<'EOF'
import json
rows = [json.loads(l) for l in open('usage.jsonl')]
created = sum(r['cache_creation_input_tokens'] for r in rows)
read = sum(r['cache_read_input_tokens'] for r in rows)
print(f'created={created} read={read} hit_ratio={read / max(created, 1):.2f}')
assert read >= created, 'ALERT: writes dominate — fix prefix stability or TTL tier'
EOF
📊 Production Insight
February's 1-hour baseline ran 1.1% overhead; March's forced 5-minute ran 25.9%. Same traffic, different lifetime — TTL is a cost control, not a detail.
🎯 Key Takeaway
5-min breaks even near one reuse; 1-hour needs two — match the tier to proven read patterns.

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.

📊 Production Insight
One team found a request ID embedded in the system block; removing it took hit rates from near zero to the high nineties with a one-line template change.
🎯 Key Takeaway
Frozen versioned blocks early, dynamic values late — layout is the caching strategy.

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.

📊 Production Insight
Gateway response caches (Redis/S3) handle identical repeats; provider prefix caches handle shared prefixes. Production stacks usually need both layers.
🎯 Key Takeaway
Automatic caching follows the same stability physics — monitor hit counters on every provider.

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.

BASH
1
2
3
4
5
6
7
8
# Nightly cache health probe: same prompt twice, second call must read
for i in 1 2; do
  curl -s https://api.anthropic.com/v1/messages \
    -H "x-api-key: $ANTHROPIC_API_KEY" \
    -H 'anthropic-version: 2023-06-01' \
    -d @cached_request.json | python3 -c "import json,sys; print(json.load(sys.stdin)['usage'])";
done
# Expect: call 1 shows cache_creation_input_tokens, call 2 shows cache_read_input_tokens
📊 Production Insight
Realistic-pause load tests would have exposed the March TTL shift immediately; back-to-back benchmarks showed green while production bled.
🎯 Key Takeaway
Dashboard creation-vs-read, alert on drift, and load-test with human-like pauses.
● Production incidentPOST-MORTEMseverity: high

The Silent TTL Downgrade That Inflated Bills 26% in a Month

Symptom
Claude Code quotas built for 5 hours exhausted in 19 minutes. Per-request latency crept up as every return-from-break became a cold compute. Finance flagged the overage before engineering noticed anything wrong.
Assumption
The team assumed caching was set-and-forget: breakpoints configured once, savings forever. Nobody monitored creation-versus-read ratios, and the provider's TTL default was treated as a permanent contract rather than a mutable default.
Root cause
The default TTL change meant caches expired during normal pauses (meetings, debugging, coffee), forcing full recompute on return. February's 1-hour baseline showed 1.1% overhead; March showed 25.9%. The team expected ~$4,600 for the month based on February patterns and paid ~$5,560 — with zero announcement, changelog, or email. Their breakpoints were fine; the lifetime underneath them had moved.
Fix
They pinned explicit TTLs per workload (5-min for chat, 1h for stable knowledge packs), added a dashboard tracking cache_creation versus cache_read tokens with alerts on ratio drift, and moved session IDs out of cached blocks. Costs returned to baseline within a week. Policy: any provider changelog triggers a caching review.
Key lesson
  • 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.
Production debug guideFour failure patterns behind most prompt-caching incidents — with exact diagnostics.4 entries
Symptom · 01
Cache hit rate near zero despite long prompts
Fix
Log usage.cache_read_input_tokens and cache_creation_input_tokens per request. Reads near zero with big writes means prefix volatility. Fix: move timestamps and request IDs out of cached blocks and re-measure over 50 requests.
Symptom · 02
Bill rose after enabling caching
Fix
Compare cost per request before and after enabling caching, split by write versus read tokens. Fix: drop to 5-minute TTL for chatty traffic and reserve 1-hour for artifacts with proven 2+ reads per write.
Symptom · 03
Hits were high, then dropped to zero after a prompt edit
Fix
Diff the exact bytes of consecutive prompts — including whitespace and block order. Fix: freeze block order (tools, system, messages), pin few-shot examples, and template dynamic values after the final breakpoint.
Symptom · 04
Short prompts show no caching benefit at all
Fix
Check prompt length against the model minimum (1024 for Sonnet-class, 4096 for some Google models). Fix: only breakpoint prompts above the minimum; batch small calls or accept that short prompts never cache.
Prompt Caching Strategies Compared at a Glance
StrategyAnthropic explicit cacheOpenAI automatic cacheClient-side memoization
ControlDeveloper breakpoints + TTLAutomatic, prefix-basedFull app control
Min prefix1024 tokens (Sonnet-class)1024 tokensWhatever you choose
Write cost1.25x base (5-min), 2x (1h)No surchargeYour infra cost
Read cost0.1x base (90% off)Discounted cached tokensFree on hit
TTL5 min default, 1h optionMinutes-scale, managedYou set expiry
Best forStable system prompts, RAGLong chat prefixesRepeated identical calls
⚙ Quick Reference
3 commands from this guide
FileCommand / CodePurpose
cached_call.pyclient = anthropic.Anthropic()Set Breakpoints Right
python3 - <<'EOF'TTL Math
for i in 1 2; doMonitor Like Production

Key takeaways

1
Prompt caching reuses KV tensors for repeated prefixes
up to 90% off cached portions plus faster first tokens.
2
Stable content first, volatile last
prefix order and byte-identical blocks decide hit or miss.
3
5-min TTL (1.25x write) suits chatty traffic; 1-hour (2x write) needs 2+ reads per write to pay off.
4
Minimum prefixes (~1024 tokens) mean short prompts never cache
check read counters, not assumptions.
5
Monitor creation-versus-read tokens and alert on drift; silent provider changes have inflated bills before.

Common mistakes to avoid

4 patterns
×

Putting the user message before the cached system prompt

Symptom
Hit rate sits near zero despite long prompts. Every request recomputes the full prefix because the volatile block poisons the cache key.
Fix
Put stable content (system prompt, docs, few-shots) first and volatile content (user query, timestamps, request IDs) last. Cache hits require identical prefixes — order is the feature.
×

Burying a timestamp inside the cached prefix

Symptom
The prefix changes hash every request, so nothing ever hits. You pay the 25% write premium on every call and get zero reads back.
Fix
Strip timestamps, UUIDs, and per-request metadata out of cached blocks. Pass them as separate uncached fields or at the very end after the breakpoint.
×

Defaulting everything to the 1-hour TTL

Symptom
Write costs double while most entries expire unused. The bill rises instead of falling — the expensive tier only pays off with 2+ reads per write.
Fix
Use 5-minute TTL for chatty traffic (refreshes free on each hit) and reserve 1-hour TTL for stable artifacts reused across sessions. Do the break-even math before upgrading tiers.
×

Assuming short prompts benefit from caching

Symptom
You add breakpoints to 300-token prompts and see no savings. Minimum cacheable lengths mean small prompts never cache at all.
Fix
Check usage.cache_read_input_tokens versus cache_creation_input_tokens per request. Below-minimum prefixes (under 1024 tokens on Sonnet-class) process normally with zero caching and zero errors — silence, not failure.
INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

Q01SENIOR
How does prompt caching work and what does it cost?
Q02SENIOR
Why would a long prompt show zero cache hits?
Q03SENIOR
How do you choose TTL tiers and guard against silent pricing shifts?
Q01 of 03SENIOR

How does prompt caching work and what does it cost?

ANSWER
Providers reuse KV tensors from attention layers for repeated prompt prefixes instead of recomputing them. Anthropic uses explicit cache_control breakpoints with 5-min (1.25x write) or 1h (2x write) TTL and 0.1x reads; OpenAI/Google cache eligible prefixes automatically. Minimum prefixes run 1024-4096 tokens. Stable-first prompt ordering is what makes hits happen.
FAQ · 5 QUESTIONS

Frequently Asked Questions

01
Does prompt caching really cut costs 90%?
02
When should I use 5-minute versus 1-hour TTL?
03
Why did my cache hit rate drop to zero overnight?
04
Do all providers support prompt caching?
05
How do I monitor whether caching actually works?
N
Naren Founder & Principal Engineer

20+ years shipping production ML systems and the infrastructure behind them. Written from production experience, not tutorials.

Follow
Verified
production tested
September 22, 2026
last updated
1,799
articles · all by Naren
🔥

That's LLMOps. Mark it forged?

3 min read · try the examples if you haven't

Previous
MCP Ollama Bridge for Local Agents
1 / 1 · LLMOps
Next
LLM Guardrails in Production