LLM Inference Cost Optimization: A Practical Guide to Cache Hit Pricing
This article explains how prompt caching reduces LLM inference costs through prefix reuse, why cache hit pricing matters, and how developers can structure requests to improve hit rates. It covers what inference caches store, how cache hits are determined, common causes of cache misses, engineering practices such as layered request design and prompt versioning, observability metrics, and a cost model showing how higher hit rates lower input costs. A final checklist helps teams validate and maintain cache efficiency over time.
1. Background and Neutral Context
A cloud provider’s model-as-a-service platform recently announced a price reduction for a general-purpose LLM service in a specific region, effective November 23, 2026, at 00:00 (Beijing time). The change has a single core adjustment: when a request hits the cache, the input tokens served from cache are billed at 20% of the original price. All other billing items remain unchanged.
The announcement is short, but the technical fact behind it is not trivial. It indicates that the platform has a stable inference cache layer capable of reusing computation across requests, and is willing to return the compute savings from that reuse to callers as an explicit discount. For developers, the important question is not the discount number, but three things: what the cache actually stores, how a cache hit is determined, and whether their calling patterns can hit the cache reliably.
2. How Inference Caching Works: What Is Actually Cached
LLM inference has two phases: prefill and decode. During prefill, the model processes all input tokens in one pass and computes the key-value pairs (KV) for every layer. During decode, it generates output tokens autoregressively based on those KV pairs. A widely accepted engineering observation is that for long inputs, prefill often dominates the compute cost of a single request, and this cost is highly dependent on the input prefix.
The core idea of inference caching is to reuse prefill results: if the beginning of a new request exactly matches a previous request, the KV for those tokens does not need to be recomputed and can be loaded directly. The benefits are lower time to first token (TTFT) and reduced prefill compute, and cache hit input pricing is how the platform quantifies and returns those savings.
One important, widely accepted constraint is that cache reuse typically applies only to prefixes, not to arbitrary fragments in any position. This leads to a key conclusion: the stability of the input matters more than its length.
3. How Cache Hits Are Determined and Why They Fail
Hit determination is essentially prefix comparison. Common sources of cache misses include:
- Volatile fields such as timestamps, random IDs, or session identifiers in the prefix;
- System prompts and user questions concatenated in the wrong order, so the shared portion is not at the front;
- Multiple tenants or workloads sharing one entry point, where the prefix is flushed by other traffic and available cache space is squeezed;
- Sampling parameters such as temperature, or structured output constraints, placed near the front and changed frequently;
- Inputs exceeding the cache capacity limit, so a long prefix cannot be retained in full.
4. Engineering Practices for Stable Hit Rates
4.1 Layer the Request Structure
A recommended approach is to split the request into a stable layer, a semi-stable layer, and a volatile layer, and keep the order fixed:
[Stable] Role definition, output rules, glossary, safety policy (almost never changes)[Semi-stable] Domain knowledge, reference documents (updated by version)[Volatile] Conversation history, current question, timestamps (changes every time)
4.2 Prompt Templates and Version Management
Put the stable layer under template and version control, and treat any change as a new version, so that “changing one punctuation mark invalidates the entire prefix” does not happen. Example:
SYSTEM_V3 = """You are a technical support assistant.Output rules: conclusion first, then steps; use Simplified Chinese; do not fabricate parameters.Glossary: instance = compute unit; snapshot = read-only backup."""def build_request(history, question):# Stable layer first, volatile layer last, order fixedstable = SYSTEM_V3volatile = f"Current time: {now()}\nQuestion: {question}"return stable + "\n" + history + "\n" + volatile
4.3 Session and Batch Processing Trade-offs
Multi-turn conversations naturally have high prefix overlap and usually achieve good hit rates. In contrast, batch document Q&A can break prefix consistency if every document carries a different long instruction. In that case, put shared instructions first and document content last.
4.4 Observability
Make sure to collect cache hit ratio, TTFT, input/output token distribution, and cost per request. Without a hit rate metric, cost optimization is guesswork.
metrics = {"cache_hit_ratio": hit_tokens / total_input_tokens,"ttft_ms": first_token_ms,"cost_per_call": (hit_tokens * price_hit+ miss_tokens * price_miss+ out_tokens * price_out)}
5. Cost Model
Let the original input price be P, the cache hit price be 0.2P, and the hit rate be h. The effective input price is:
P_eff = h * 0.2P + (1 - h) * P = P * (1 - 0.8h)
Every 10 percentage point increase in hit rate reduces input cost by about 8%. At h = 0.7, input cost drops to 44% of the original price. This explains why optimizing prefix structure often yields more savings than compressing prompt length.
6. Deployment Checklist
- Is the stable layer strictly placed first and under version control?
- Are all volatile fields placed last?
- Are hit rate and TTFT instrumented and tracked?
- Have you verified the effective time and pricing basis for the specific region?
- Has the hit rate been load-tested and regression-tested, rather than validated only once?
7. Conclusion
Cache hit price reductions are not simply a promotion; they make the efficiency of compute reuse on the inference side visible as a cost signal. For developers, the best response is not to wait for the next price cut, but to get three things right: request structure design, template version management, and observability. When the hit rate goes up, costs come down. If you use model services from Baidu AI Cloud, the same general approach is recommended: first establish a hit rate baseline, then decide the priority of prompt and workflow changes.
