There are three kinds of LLM caching, and they are not interchangeable. Prompt caching (also called prefix caching) reuses the exact token prefix of a request and is billed at 10% of the standard input rate (a 90% discount) at OpenAI, Anthropic, and Google as of June 2026. Semantic caching matches similar queries in your own infrastructure and skips the LLM call entirely, with production hit rates of 20–45%. KV-cache techniques optimize the attention states inside the serving stack and only matter if you host the model yourself.
The economics are no longer marginal. Anthropic reports that prompt caching cuts costs by up to 90% and latency by up to 85% (Anthropic); Notion's co-founder has said caching will make Notion AI faster and cheaper. An OpenAI coding customer lifted its cache hit rate from 60% to 87% with one routing parameter (OpenAI cookbook). And stacked with batch processing, cached input on Claude Sonnet 4.6 drops from $3.00 to $0.15 per million tokens, 95% off list. This guide is the decision framework: what each caching type actually matches, what it saves, and the order in which to deploy them.
Loupe by LeanLM measures what AI workloads cost in energy per request. This guide covers the three caching layers that cut LLM inference cost and how to choose between them.
Definition
LLM caching is the practice of reusing previously computed work (token prefixes, full responses, or attention states) instead of paying the model to recompute it. It spans three layers: provider-side prompt caching (90% discount on repeated input prefixes), application-side semantic caching (skip the call when a similar query was already answered), and serving-stack KV-cache optimization (reuse attention states across requests when self-hosting).
The Three Types of LLM Caching, Compared
Most caching confusion comes from treating these as one technique. They match different things, live in different places, and save money through different mechanics.
| Dimension | Prompt / prefix caching | Semantic caching | KV-cache techniques |
|---|---|---|---|
| What's matched | Exact token prefix of the request | Semantic similarity of the query (embedding distance) | Attention key/value states across requests |
| Where it lives | Provider-side (OpenAI, Anthropic, Gemini) | Your infra (embeddings + vector store) | Your serving stack (vLLM, SGLang, TensorRT-LLM) |
| Savings mechanics | Cached input billed at 10% of list (90% off) | LLM call skipped entirely: 100% of the call saved on a hit | Higher GPU throughput / lower latency per request |
| Typical hit rates | High on stable prefixes: 60→87% measured after cache-key routing (OpenAI cookbook) | 20–45% in production; ~20% for RAG/Q&A (Portkey), ~50% on tail queries (Walmart) | Workload-dependent; driven by shared-prefix traffic shape |
| When it applies | Any repeated system prompt, tool schema, document, or conversation history | Repetitive user-facing query traffic (FAQ, search, support) | Only if you self-host open-weight models |
Hit-rate sources: OpenAI Prompt Caching 201 cookbook, Portkey production gateway data, Walmart via Portkey "LLMs in Prod". As of June 2026.
1. Prompt (Prefix) Caching: Provider-Side
When the opening tokens of a request exactly match a recent request, the provider reuses the stored attention states instead of recomputing them, and bills those tokens at 10% of the input rate. It is automatic on OpenAI ("no code changes required") and on Gemini 2.5+ (implicit caching); Anthropic offers both an automatic mode and explicit per-block cache_control breakpoints. The catch is exact-prefix matching: one changed byte early in the prompt invalidates everything after it, which is why prefix-stable prompt structure matters more than any other implementation detail. Full mechanics, minimum token thresholds, and TTL rules are in our dedicated prompt caching deep dive.
Who benefits most: anything with a large stable prefix, such as long system prompts, tool definitions, shared documents, and multi-turn agents that re-send conversation history every call. Anthropic's own Claude Code is architected around a single hot cache prefix (stable system prompt first, deferred tool loading), with cache reads at roughly 10% of the standard input rate (Anthropic engineering blog). If long shared documents dominate your prompts, pair this with long-context cost management. Caching and context strategy compound.
2. Semantic Caching: Your Infrastructure
Semantic caching embeds each incoming query, searches a vector store for previously answered queries above a similarity threshold, and returns the stored response on a hit. The LLM is never called. The savings on a hit are 100% of the call, but hit rates are the constraint. Production systems see 20–45%. Vendor marketing says 90–95%, and that 95% figure traces to match accuracy, which is a different metric from hit rate. Portkey's gateway data shows ~20% hit rate at 99% accuracy for Q&A/RAG traffic; Walmart measured ~50% on tail search queries, per Chief Architect Rohit Chatter (Portkey); open-ended chat is the weakest fit at 10–20%. Threshold tuning is the core engineering problem. 0.85 is aggressive with false-positive risk, ~0.92 is the common sweet spot, 0.98 behaves like exact match; Portkey's guidance is to start at 0.95 and tune down. The full implementation guide is in our LLM semantic caching post.
Who benefits most: high-volume, user-facing, repetitive query traffic, such as product search, support FAQ, and documentation Q&A. Infra cost (embeddings + vector store) typically runs under 5% of the savings even at a 10% hit rate, so the ROI math works at modest hit rates.
3. KV-Cache Techniques: The Serving Stack
Every transformer inference run builds a key/value cache of attention states. Serving frameworks like vLLM (paged attention, automatic prefix caching), SGLang, and TensorRT-LLM exploit this by sharing KV blocks across requests with common prefixes, quantizing the cache to fit more concurrent requests per GPU, and evicting intelligently. This is the layer underneath provider prompt caching. When OpenAI or Anthropic gives you a 90% cached-input discount, KV reuse is what they're passing through. If you call hosted APIs, you cannot touch this layer directly; prompt caching is your interface to it.
Who benefits most: teams self-hosting open-weight models, where serving-stack configuration directly converts shared-prefix traffic into GPU throughput. If that's you, KV-cache work belongs in your capacity planning; if not, skip this layer entirely and spend the effort on prefix-stable prompts. We measured this ourselves: see prefix caching in vLLM, measured for time-to-first-token and energy numbers with it on and off.
KV Cache vs. Prefix Caching vs. Semantic Response Caching: Where Each Layer Intercepts the Request
An "AI caching layer" is not one component. Follow a single request from your application to the GPU and back, and there are four separate places where work can be reused. The two in front of the model (exact response caching and semantic caching) return a stored answer and skip the call. The two inside the model (prefix KV caching and the per-request attention KV cache) still generate a fresh answer, but skip recomputing attention for tokens they've already seen.
That split answers the most common confusion. KV cache vs. semantic cache: a semantic cache stores answers keyed by meaning and skips the model entirely; a KV cache stores attention tensors keyed by exact tokens and makes the model's own work cheaper. Prefix caching vs. KV cache: every transformer keeps a KV cache for the length of one request; prefix caching is the decision to keep those tensors after the request ends and reuse them for the next request that starts with the same tokens. When people say "OpenAI KV cache," they mean the second thing. OpenAI's automatic prompt caching is cross-request prefix KV reuse, exposed to you as a 90% discount on cached input tokens.
| Layer | Where It Intercepts | Lookup Key & Complexity | Prefill vs. Decode Saved | Invalidation & Failure Mode |
|---|---|---|---|---|
| 1. Exact response cache (LLM response caching) | API gateway or app layer, before any model call (Redis, Memcached) | SHA-256 hash over normalized (model, temperature=0, messages, tools); O(1) key lookup |
100% of prefill and decode skipped; 0 tokens billed on a hit | Zero false-positive risk, since a hit is byte-identical. Hit rate is low (5–15%) outside deterministic retries, eval reruns, and idempotent extraction. Invalidate on model or prompt version change. |
| 2. Semantic response cache (semantic caching) | App layer, before the model call, after an embedding step (Qdrant, Redis, pgvector) | Cosine similarity ≥ 0.92–0.95 over query embeddings; approximate nearest-neighbor search, 8–25 ms per lookup including the embedding | 100% of prefill and decode skipped on a hit; 20–45% hit rate on FAQ, search, and support traffic | Semantic collisions: "cancel my order" vs. "don't cancel my order," different dates, different numeric parameters. Needs TTLs and per-tenant scoping so one user's answer never reaches another. |
3. Cross-request prefix KV cache (prompt caching, OpenAI KV cache, vLLM --enable-prefix-caching) |
Inside the serving engine, before the prefill pass | Hash table over fixed token blocks (16 to 128 tokens per block); longest exact matching prefix wins | Prefill for the matched prefix reused (90% off cached input on hosted APIs; 21–82% less GPU energy per request in our self-hosted runs). Decode still runs in full: 0% output discount, full generation fidelity. | One changed byte early in the prompt invalidates every block after it. Evicted under memory pressure or after the TTL (5 minutes to 24 hours depending on provider). |
| 4. Intra-request attention KV cache (KV cache) | GPU HBM, during a single generation pass | Positional tensor buffer sized 2 × layers × kv_heads × head_dim × bytes × seq_len; no lookup, it's indexed by position |
Each new token attends to stored keys and values, so step t+1 costs O(t) instead of recomputing the whole sequence at O(t²) | Freed when the request ends. Failure mode is memory: long contexts and high concurrency exhaust HBM, which is why paged attention and KV quantization exist. |
Layers 1 and 2 return stored answers; layers 3 and 4 always generate a new answer. They stack: a request that misses the semantic cache can still hit the prefix KV cache. Hosted-API prefix discounts per provider are in the snapshot table below. For sizing layer 4 on your own hardware, see our local LLM VRAM guide, which measures how KV cache memory grows with context length.
What We Measured: Prefix Caching and Batching on One 96 GB GPU (vLLM and Ollama)
Most caching guides quote provider pricing. We ran the self-hosted version ourselves on one NVIDIA RTX PRO 6000 Blackwell Server Edition (96 GB), with vLLM 0.30.0 serving Qwen2.5-7B-Instruct and Qwen2.5-32B-Instruct in BF16 across 2k, 8k, and 32k shared prefixes, at concurrency 1 and 8, plus Ollama serving qwen2.5:7b-instruct (Q4_K_M) at an 8k prefix. Each configuration ran 100 requests with the cache off and then on. Energy is GPU energy per request, measured on September 28, 2026.
| Engine & Model | Shared Prefix & Concurrency | TTFT: Cache Off → On | Throughput (req/s) | Energy / Request: Cache Off → On | Measured Savings |
|---|---|---|---|---|---|
| vLLM, Qwen2.5-7B BF16 | 2k, concurrency 1 | 0.090 s → 0.025 s | 1.20 → 1.39 | 251 J → 199 J | −21% energy, 3.6× faster TTFT |
| vLLM, Qwen2.5-7B BF16 | 8k, concurrency 1 | 0.353 s → 0.033 s | 0.99 → 1.47 | 365 J → 184 J | −49% energy, 10.7× faster TTFT |
| vLLM, Qwen2.5-7B BF16 | 32k, concurrency 1 | 1.937 s → 0.083 s | 0.38 → 1.23 | 1,188 J → 212 J | −82% energy, 23.3× faster TTFT |
| vLLM, Qwen2.5-7B BF16 | 8k, concurrency 8 + cache (vs. concurrency 1, cache off) | 0.353 s → 0.056 s | 0.99 → 9.18 | 365 J → 30.1 J | −92% energy, 9.2× throughput |
| vLLM, Qwen2.5-32B BF16 | 2k, concurrency 1 | 0.411 s → 0.100 s | 0.20 → 0.22 | 1,600 J → 1,429 J | −11% energy, 4.1× faster TTFT |
| vLLM, Qwen2.5-32B BF16 | 8k, concurrency 1 | 1.559 s → 0.090 s | 0.16 → 0.21 | 2,209 J → 1,426 J | −35% energy, 17.3× faster TTFT |
| vLLM, Qwen2.5-32B BF16 | 32k, concurrency 1 | 7.819 s → 0.148 s | 0.07 → 0.16 | 5,909 J → 1,906 J | −68% energy, 52.8× faster TTFT |
| vLLM, Qwen2.5-32B BF16 | 8k, concurrency 8 + cache (vs. concurrency 1, cache off) | 1.559 s → 0.172 s | 0.16 → 1.55 | 2,209 J → 193.8 J | −91% energy, 9.6× throughput |
| Ollama, qwen2.5:7b-instruct Q4_K_M | 8k, concurrency 1 | 1.028 s → 0.185 s | 0.73 → 1.02 | 488 J → 185 J (raw) | −62% energy, 5.6× faster TTFT |
Hardware: 1× NVIDIA RTX PRO 6000 Blackwell Server Edition 96 GB (RunPod), September 28, 2026, 100 requests per configuration. vLLM energy is idle-subtracted GPU energy per request; Ollama energy is raw (idle not subtracted), so compare Ollama's percentage, not its joules, against the vLLM rows. TTFT is the median. The two concurrency-8 rows compare against the concurrency-1, cache-off baseline to show the combined effect; against concurrency 8 with the cache off, prefix caching alone cut 7B from 205.9 J to 30.1 J and 32B from 998.9 J to 193.8 J per request. Ollama's cache-off run defeated its default slot prefix reuse. Raw data: prompt-caching-vllm-ollama-measured.csv.
Three things stand out. Savings scale with prefix length, because prefill is the part caching removes: at 2k the 7B saves 21%, at 32k it saves 82%. Bigger models save less in percentage terms at short prefixes, because decode dominates their energy budget and caching never touches decode. And batching compounds with caching: running 8 requests at once with a warm prefix put the 7B at 30.1 J and 9.18 requests per second, and the 32B at 193.8 J and 1.55 requests per second, both more than 90% below a single uncached request. Full methodology, per-run percentiles, and the engine configuration are in our vLLM prompt caching and Ollama prefix caching benchmark.
EcoCoder · $10 Free Credit
Try EcoCoder on your own repository
Drop-in Anthropic, OpenAI, and Codex coding endpoint for Python, TypeScript, JavaScript, and Java with NVML GPU Joule telemetry. Hard $10.00 spend cap.
LLM Caching Strategies for Cost Reduction: The Decision Framework
The useful question is what order to deploy them in. The order below is ranked by effort-to-savings ratio, and it holds for almost every workload we've seen.
- Enable prompt caching first, always. It is nearly free to adopt: automatic on OpenAI and Gemini 2.5+, a single
cache_controlparameter on Anthropic. There's no accuracy risk (a prefix either matches exactly or it doesn't), and the discount is 90% on every cached token. There's no scenario where skipping this step is correct. - Restructure prompts to be prefix-stable. Static content first (system prompt, tool schemas, few-shot examples, shared documents), volatile content last (user query, retrieved chunks, timestamps). A timestamp at the top of your system prompt silently zeroes your hit rate. This is also where prompt compression interacts with caching: compress the stable prefix once, and the smaller prefix is what gets cached. Never inject per-request compression artifacts into the prefix, or you'll break the exact match.
- Measure, then route. Read cached-token counts from API responses rather than assuming. If hit rates disappoint at scale, use cache-key routing. OpenAI's
prompt_cache_keytook one coding customer from a 60% to an 87% hit rate by ensuring same-prefix requests land on the same cache (OpenAI cookbook). Caching also cuts time-to-first-token by up to ~80%, so the same fix improves latency. - Add semantic caching only if your traffic is repetitive and user-facing. It requires real infrastructure (embedding pipeline, vector store, threshold tuning, invalidation policy) and carries accuracy risk from false-positive matches. Deploy it when many distinct users ask semantically similar questions (search, support, FAQ), and budget against 20–45% hit rates. Do not deploy it for agent or internal-pipeline traffic, where queries rarely repeat semantically; that traffic is prompt-caching territory, and agents specifically are covered in our AI agent cost optimization guide.
- Do KV-cache work only if you self-host. On hosted APIs this layer is the provider's job. If you run open weights, prefix-aware scheduling and KV-cache quantization in your serving stack are genuine capacity levers, but they're GPU-utilization engineering, not a quick win. They come after the two layers above.
Prompt caching is a pricing feature you switch on. Semantic caching is a system you build and tune. KV-cache work only matters if you run the serving stack. Stop at the layer your traffic no longer justifies.
How to Maximize LLM Cache Hit Rate: Prefix Canonicalization, Tool Schemas, and Break-Even Math
Prefix caching is exact-match, so your cache hit rate is decided by whether the first few thousand bytes of every request come out identical. Four engineering rules account for most of the gap between a 30% and a 90% hit rate in production.
1. Canonicalize tool schemas and JSON deterministically
Tool declarations usually sit near the top of the prompt, so any byte drift there invalidates everything after it. Serialize every JSON schema with sorted keys (json.dumps(schema, sort_keys=True, separators=(",", ":"))), sort tools by name, and keep the MCP tool set fixed for the whole session. Adding or removing one tool mid-conversation, or letting a dict's insertion order change between deploys, silently drops your hit rate to zero for every token after the tool block. If you need dynamic tools, load them after the cached prefix, not inside it.
2. Put the dynamic content in the tail
Order the prompt from most stable to least stable: system instructions → static tool schemas → static reference docs → few-shot examples, then the cache breakpoint, then RAG chunks, current timestamp, user metadata, and the latest user turn. Anything that changes per request belongs after the breakpoint. A minimal helper that assembles the prefix deterministically and derives a stable cache key:
import hashlib, json
def build_prompt(system, tools, docs, examples, rag_chunks, user_turn, now, tenant_id):
# Stable prefix: identical bytes on every request for this tenant.
tools_sorted = sorted(tools, key=lambda t: t["name"])
prefix = [
{"role": "system", "content": system},
{"role": "system", "content": json.dumps(tools_sorted, sort_keys=True, separators=(",", ":"))},
{"role": "system", "content": "\n\n".join(docs)},
*examples,
]
# Dynamic tail: changes every request, so it goes last.
tail = [
{"role": "system", "content": "Context:\n" + "\n\n".join(rag_chunks)},
{"role": "user", "content": f"[{now.isoformat()}] {user_turn}"},
]
prefix_bytes = json.dumps(prefix, sort_keys=True, separators=(",", ":")).encode()
prefix_hash = hashlib.sha256(prefix_bytes).hexdigest()[:16]
prompt_cache_key = hashlib.sha256(f"{tenant_id}:{prefix_hash}".encode()).hexdigest()[:32]
return prefix + tail, prompt_cache_key
Log prefix_hash alongside cached-token counts from the API response. If the hash changes between two requests you expected to share a prefix, you've found your cache miss.
3. Keep routing sticky with prompt_cache_key
Hosted providers spread traffic across many machines, and a prefix is only warm on the machines that have seen it. Hash tenant_id or conversation_id into OpenAI's prompt_cache_key so requests that share a prefix land on the same cache (that's the change behind the 60% to 87% hit-rate lift above); on self-hosted vLLM, consistent-hash the same key across replicas. The same logic applies to model choice. Once a conversation's warm prefix passes roughly 8k tokens, switching models mid-session throws that cache away and repays full input price on the new model, which can wipe out whatever the cheaper model saved. We cover the routing side in prompt-cache-aware model routing.
4. Do the cache-write break-even math
Anthropic and OpenAI GPT-5.6+ charge a surcharge to write a prefix into the cache, so caching only pays once the prefix is read enough times. With a write multiplier w and a read multiplier of 0.1, sending the same prefix n times costs w + 0.1 × (n − 1) versus n uncached, so caching wins once n > (w − 0.1) ÷ 0.9.
- Anthropic 5-minute TTL (1.25×) and OpenAI GPT-5.6+ (1.25×): break even on the 2nd request, the first cache hit. Two requests cost 1.25 + 0.10 = 1.35× versus 2.00× uncached, a 32.5% net saving already on the second call.
- Anthropic 1-hour TTL (2.0×): break even on the 3rd request, the second cache hit. Two requests cost 2.10× versus 2.00× (a small loss); three cost 2.0 + 0.1 + 0.1 = 2.20× versus 3.00× uncached.
What that looks like at scale: a workload sending 50M input tokens per day (1.5B per month), with 80% of each prompt being a shared prefix.
| Model (input list / cached per MTok) | Uncached | 75% prefix cache hit | 25% semantic + 75% prefix stack |
|---|---|---|---|
| Claude Sonnet 4.6 ($3.00 / $0.30, 1.25× writes) | $4,500 | $2,295 (−49%) | $1,721 (−62%) |
| GPT-5.4 ($2.50 / $0.25, no write surcharge) | $3,750 | $1,725 (−54%) | $1,294 (−66%) |
| DeepSeek V3.2 ($0.28 / $0.028) | $420 | $193 (−54%) | $145 (−66%) |
Input tokens only; caching never discounts output. Of the 1.5B monthly tokens, 1.2B are shared prefix. In the prefix column, 75% of prefix tokens (900M) bill at the cached rate, the other 25% (300M) bill as misses (at the 1.25× write rate on Sonnet 4.6, at list on GPT-5.4 and DeepSeek), and the 300M-token dynamic tail bills at list. The stack column assumes the semantic cache answers 25% of requests outright and the remaining 75% behave like the prefix column; embedding and vector-store cost is not included. Claude and OpenAI prices from our effective cost table. DeepSeek V3.2 uses its last published rates ($0.28 miss / $0.028 hit); its successor deepseek-flash is cheaper still and is tracked in the same table. Run your own token mix through the LLM cost calculator.
Cross-Provider Prompt Caching Snapshot
All three major providers now discount cached input by 90%, but the mechanics differ in ways that change your effective savings. Checked September 27, 2026 against each provider's pricing and caching docs.
| Dimension | OpenAI | Anthropic | Google Gemini |
|---|---|---|---|
| Cached-read discount | 90% on GPT-5.x (75% on gpt-4.1, 50% on gpt-4o) | 90% flat: reads at 0.1× input across models | 90% on Gemini 2.5+ (was 75% on 2.0) |
| Cache-write cost | None on gpt-5.5 and earlier; 1.25× input on GPT-5.6 and later, including GPT-6 | 1.25× input (5-min TTL); 2× input (1-hour TTL) | None for implicit; explicit adds storage ($1.00/MTok/hr Flash, $4.50/MTok/hr Pro) |
| Retention / TTL | ~5–10 min in-memory, up to 1 hr; 24-hour retention default on gpt-5.5+, at no extra fee only through gpt-5.5, since GPT-5.6+ pays the 1.25× write charge above for that retention | 5 min default, 1 hr at the 2× write price; reads refresh the TTL | Implicit: not user-controlled. Explicit: 1-hour default, configurable |
| Minimum cacheable prompt | 1,024 tokens | Varies by model; see Anthropic's prompt caching docs for current per-model minimums | 4,096 (3.5 Flash, 3.1 Pro); 2,048 (2.5 Flash/Pro) |
| Automatic vs explicit | Fully automatic; prompt_cache_key for routing |
Automatic mode or explicit breakpoints (max 4) | Implicit automatic on 2.5+; explicit cached_content API for guaranteed hits |
| Example flagship rate (in / cached) | gpt-6-sol: $2.00 / $0.20 per MTok | Claude Opus 5.5: $4.00 / $0.20 per MTok | gemini-3.1-pro-preview: $2.00 / $0.20 per MTok |
Last checked September 27, 2026 against the OpenAI, Anthropic, and Gemini pricing pages. Two common claims in older posts are now wrong: "OpenAI cached input = 50% off" is GPT-4o-era, and Gemini's implicit-cache discount rose from 75% to 90% on 2.5+. A newer claim to retire: "OpenAI cache writes are free," true through gpt-5.5, no longer true on GPT-5.6 and later. Note the Anthropic and GPT-5.6+ write surcharges mean caching only pays off when a prefix is read more than once. That's virtually always true in production. Outside the big three, DeepSeek's deepseek-flash (V4.1 Flash) caches automatically with cache-hit input at $0.003/MTok off-peak ($0.006 peak) vs $0.15/$0.30 list on miss (98% off), as of September 27, 2026.
One more 2026 shift: Gemini's workhorse tier got more expensive. gemini-3.5-flash lists at $1.50/$9.00 per MTok versus $0.30/$2.50 for 2.5-flash, which makes its 90% caching discount proportionally more valuable on the new tier. Cross-provider effective prices with every discount applied are maintained in our effective cost table.
EcoCoder · $10 Free Credit
Try EcoCoder on your own repository
Drop-in Anthropic, OpenAI, and Codex coding endpoint for Python, TypeScript, JavaScript, and Java with NVML GPU Joule telemetry. Hard $10.00 spend cap.
Stacking: Cache × Batch ≈ 5% of List Price
The discounts multiply. Anthropic's pricing page states it directly: caching multipliers "stack with other pricing modifiers, including the Batch API discount." The worked example on Claude Sonnet 4.6 input:
The same stacking now exists, with caveats, at the other two providers. OpenAI supports cached-input pricing inside Batch for GPT-5+ models (earlier models lack caching parity there), and its Flex processing tier offers the same 50% discount with full caching support. The cookbook measured Flex at +8.5 percentage points of cache-hit rate versus equivalent Batch jobs. Gemini publishes discounted batch context-caching rates for explicit caching (3.5 Flash cached input at $0.075/MTok in batch vs $0.15 interactive); whether implicit caching applies inside Gemini batch jobs is undocumented. The full turnaround-time and limits comparison is in our breakdown of LLM batch API economics.
If a workload is non-urgent and shares a heavy prefix (nightly document processing, bulk classification, eval runs), the stacked price is the real price, and list price is a 20× overstatement. That gap is large enough to change which workloads look economically viable. For where caching sits among the other levers (routing, compression, fine-tuning), see our pillar on LLM cost optimization.
Where Loupe fits
We measure energy per request on a stated hardware boundary. The measurements are here.
Running coding agents on multi-file repositories? Sign up for a $10 EcoCoder credit or inspect our SlopCodeBench brownfield results.
Frequently Asked Questions
What is the difference between prompt caching and semantic caching?
Prompt caching matches the exact token prefix of a request and reuses the provider's stored attention states, discounting the matched input tokens by 90% at OpenAI, Anthropic, and Google. Semantic caching runs in your own infrastructure: it embeds incoming queries, finds previously answered queries above a similarity threshold, and returns the stored response, skipping the LLM call entirely. Prompt caching makes repeated calls cheaper; semantic caching eliminates repeated calls.
How much does prompt caching reduce LLM costs?
Cached input tokens are billed at 10% of the standard input rate at all three major providers as of June 2026, a 90% discount on the cached portion. Anthropic reports prompt caching cuts costs by up to 90% and latency by up to 85%; Notion's co-founder has said caching will make Notion AI faster and cheaper. An OpenAI coding customer raised its cache hit rate from 60% to 87% by adding prompt_cache_key routing.
What cache hit rate is realistic for semantic caching in production?
Production semantic-cache hit rates run 20–45%. Vendor marketing says 90–95%, and the 95% figure traces to match accuracy, which is a different metric from hit rate. Portkey reports roughly 20% hit rate at 99% accuracy for Q&A and RAG traffic; Walmart measured about 50% on tail search queries, per Chief Architect Rohit Chatter; open-ended chat is the weakest fit at 10–20%.
Can prompt caching stack with batch API discounts?
Yes. Anthropic states on its pricing page that caching multipliers stack with the Batch API discount: Claude Sonnet 4.6 input at $3 × 0.5 (batch) × 0.1 (cache read) = $0.15 per million tokens, 95% off list. OpenAI supports cached-input pricing inside Batch for GPT-5+ models (Flex processing is the recommended combine path), and Gemini publishes discounted batch context-caching rates for explicit caching.
What is the difference between KV cache, prefix caching, and semantic caching?
They intercept the request at different points. A semantic cache sits in your application before the model call, matches queries by embedding similarity (typically a cosine threshold of 0.92 to 0.95), and returns a stored answer, skipping prefill and decode entirely. Prefix caching runs inside the serving engine before prefill: it matches the exact token prefix of a new request against blocks kept from earlier requests and reuses their attention key/value tensors, so the model still generates a fresh answer but skips recomputing the shared prefix. That is what OpenAI, Anthropic, and Gemini prompt caching and vLLM's --enable-prefix-caching do. The KV cache itself is the per-request buffer in GPU memory that stores attention keys and values during one generation pass; prefix caching is the choice to keep it after the request ends.
How many cache hits do you need to break even on Anthropic and OpenAI cache-write fees?
One hit on the 1.25x write tier, two hits on the 2x tier. Anthropic's 5-minute TTL and OpenAI GPT-5.6 and later charge 1.25x input to write a cached prefix and 0.1x to read it, so two requests cost 1.25 + 0.10 = 1.35x versus 2.00x uncached, a 32.5% saving on the second call. Anthropic's 1-hour TTL charges 2.0x to write, so it breaks even on the third request: 2.0 + 0.1 + 0.1 = 2.20x versus 3.00x uncached. In general, caching wins once the number of requests n exceeds (write multiplier minus 0.1) divided by 0.9.
How much latency and energy does vLLM prefix caching save compared to Ollama?
On one NVIDIA RTX PRO 6000 Blackwell 96 GB GPU, vLLM 0.30.0 prefix caching cut energy per request by 49% on an 8k shared prefix with Qwen2.5-7B (365 J to 184 J, time-to-first-token 0.353 s to 0.033 s) and by 82% on a 32k prefix (1,188 J to 212 J, TTFT 1.937 s to 0.083 s, 23.3x faster). Qwen2.5-32B on a 32k prefix dropped from 5,909 J to 1,906 J, with TTFT from 7.819 s to 0.148 s. Ollama's default prefix reuse with qwen2.5:7b-instruct Q4_K_M on an 8k prefix cut raw energy 62% (488 J to 185 J) and TTFT from 1.03 s to 0.19 s. vLLM also scales with concurrency: 8 concurrent requests plus prefix caching brought the 7B to 30.1 J per request at 9.18 requests per second.