Cutting LLM Inference Costs with Prompt Cache Hits
A cloud provider cut cached-input pricing to 20% of the original rate, signaling that inference savings now depend on reuse, not just unit price. This article explains the cost model, which workloads benefit, how to raise cache hit rates, and how to monitor, load-test, and avoid common pitfalls.
Background: What a Price Change Signals
A cloud provider announced that, from 00:00 Beijing time on 23 November 2026, it would lower prices for large-model inference in a given region. Cached-input tokens would be billed at 20% of the original input price; other prices would stay the same. On the surface this is a billing change. From an engineering view it is a clear signal: cost optimization is shifting from cheaper unit rates toward higher compute reuse per request.
For developers and enterprises, that change is not only a finance issue. It affects inference architecture, prompt layout, cache strategy, capacity planning, and cost monitoring. In long-context, fixed system-prompt, knowledge-base Q&A, coding-assistant, and multi-turn chat workloads, input often dominates the bill. If cache hits are used well, overall inference cost can drop substantially.
This article is product-agnostic. It covers why cached input is priced separately, the compute logic behind it, how to design requests and caches, and how to verify results with metrics and load tests.
What Cached-Input Discounts Really Mean
Inference can be abstracted as input parsing, context encoding, token-by-token generation, and output. The input stage processes prompts, history, system instructions, and retrieved content. Recomputing identical prefixes or highly similar input wastes compute.
Cache-hit mechanisms identify reusable fragments and reuse prior results. Common approaches include prefix cache, context cache, session cache, and semantic cache. Implementations differ; the shared goal is less duplicate work.
On a hit, the system does not re-run the expensive work for the full input, so that portion costs less. Pricing hits at 20% of the original rate maps “low duplicate compute” into billing. Uncached input still needs full computation, so its price is unchanged. Output still depends on generation length and decoding, so it is unchanged as well.
A simplified model:
Total input cost = miss input cost + hit input costHit input cost = hit tokens × original input unit price × 20%Miss input cost = miss tokens × original input unit price
The lever is not only “fewer input tokens,” but a higher share of tokens that hit cache.
Workloads That Benefit Most
Not every product benefits equally. Stable input structure and high repetition help most.
1. Fixed system prompts
Many apps prepend long system prompts: role, output format, safety rules, tool instructions. If that text is stable, it is a natural cache prefix. A support bot with thousands of tokens of fixed rules is expensive if recomputed every time; higher hit rates cut input cost.
2. Long-document Q&A and RAG
RAG concatenates document chunks with the user question. If the same document is queried repeatedly, or a session follows up on the same material, those chunks are reusable. Cache design must track document version, chunk granularity, and session context. Frequent document updates need invalidation so answers do not go stale.
3. Multi-turn dialogue
History grows each turn. Re-encoding the full history every time makes input cost grow with turns. Session or prefix reuse reduces that. Users may edit history, inject new instructions, or change topic, so cache keys must be careful—not all history is reusable.
4. Coding assistants
Completion, explanation, and test generation often reuse project rules, snippets, APIs, and log templates. Hits reduce input load. Code is time-sensitive; stale cache can yield wrong advice. Invalidate with version, file hash, or commit id.
How Hit Rate Changes Total Cost
Assume original input unit price P and output unit price Q. A request has 10,000 input tokens, 8,000 of them cached, and 2,000 output tokens.
Without cache pricing:
Input cost = 10000 × POutput cost = 2000 × QTotal = 10000P + 2000Q
With cached input at 20%:
Hit input cost = 8000 × P × 20% = 1600PMiss input cost = 2000 × PInput cost = 3600POutput cost = 2000QTotal = 3600P + 2000Q
Input cost falls from 10000P to 3600P (64%). At a 95% hit rate, input cost is about 2900P.
def estimate_cost(input_tokens, hit_tokens, output_tokens, input_price, output_price):hit_tokens = max(0, min(hit_tokens, input_tokens))miss_tokens = input_tokens - hit_tokenshit_cost = hit_tokens * input_price * 0.2miss_cost = miss_tokens * input_priceoutput_cost = output_tokens * output_pricereturn miss_cost + hit_cost + output_cost
Savings track hit rate. The question is whether the workload can hit cache reliably, not only whether the list price fell.
Design for Higher Hit Rates
1. Stable prefixes first
Put fixed content first and dynamic content last, for example:
[fixed system rules][fixed knowledge snippets][fixed tool descriptions][current user question][dynamic session context]
That raises prefix reuse. Dynamic content at the front can prevent later stable text from hitting.
2. Limit prompt drift
Frequent, unnecessary changes—timestamps, random IDs, debug notes—break reuse. Template prompts:
system_prompt = """You are an enterprise knowledge assistant.Answers must be based on the given materials.Do not invent information that was not provided.Output format is JSON."""def build_prompt(question, context):return f"{system_prompt}\nMaterials: {context}\nQuestion: {question}"
Keep the fixed part stable and isolate the dynamic part.
3. Cache keys with business meaning
Keys should not be raw request text only. Typical dimensions:
- model version
- prompt template version
- knowledge-base version
- document hash
- session id
- safety-policy version
- output-format constraint version
After a model or knowledge-base upgrade, invalidate by version instead of waiting for accidental misses.
4. Avoid cache pollution
In multi-tenant systems, isolate by tenant, permission, and product line. Mixing caches hurts quality and can create security and compliance risk.
cache key = tenant id + scenario + template version + content hash + permission scope
That reduces cross-tenant false hits.
Engineering: From Request Hygiene to a Monitoring Loop
Discounts do not apply themselves; the stack must cooperate.
1. Layer requests
- Fixed: system rules, safety, output format
- Semi-fixed: knowledge snippets, tool defs, template variables
- Dynamic: user question, live context, one-off parameters
Keep the first layer stable, version the second, change the third only when needed.
2. Hit-rate metrics
Track at least:
- cache hit rate
- hit input tokens
- miss input tokens
- average input length
- output tokens
- cost per request
- invalidation count
- expiration share
- false-hit rate
A simple business metric:
cache savings = input cost if all miss − current input cost
If savings stay near zero or negative, fix request shape or cache policy.
3. Load test and gradual rollout
Load-test before switching policy. The goal is not maximum hit rate alone, but acceptable cost, latency, and quality on real traffic.
Roll out by product line, user cohort, prompt template, knowledge-base version, or region/AZ. Watch for stale answers, inconsistency, cache stampedes, and hot keys.
4. Invalidation and fallback
More cache is not always better. Short TTL or active invalidation for time-sensitive content. If cache fails:
prefer a cache hit;on miss, compute normally;on cache errors, fall back to no-cache;log and alert
Do not let the cache layer take down the main path.
Common Mistakes
Longer input always saves money. Unstable long input still misses and stays expensive. Repetition and stability matter.
Higher hit rate is always better. Very high hits can mean stale data or weak isolation. Judge correctness, security, and freshness together.
Cache only affects input. Output length still drives cost. Control generation length while you cache input.
No architecture change after the price cut. Without stable templates, keys, and observability, the discount is hard to capture.
Practical Checklist
- Inventory high-volume requests and find stable prefixes.
- Template system prompts, safety rules, and output formats.
- Put dynamic content last.
- Version templates, knowledge bases, and models.
- Dashboard hit rate and cost.
- Canary high-value scenarios.
- Set TTL and active invalidation.
- Isolate tenants and check permissions.
- Load-test latency vs. cost.
- Review cache savings regularly, not only a single invoice.
Conclusion
Pricing cached input at 20% of the original rate turns “duplicate work is reusable” into a billing incentive. For developers it is an architecture signal, not only a cost headline. Real savings come from stable prefixes, sound cache keys, versioned templates, and observability—not from waiting for list prices to move.
As input hit rates rise, fixed content becomes an asset instead of repeated spend, and the marginal cost of long context and multi-turn chat falls. Consistency, tenant isolation, freshness, and alerting must be built at the same time. Only when cache hits are part of a complete engineering system does the price change become durable technical value.
