LLM Inference Cost Optimization: A Practical Guide to Cache Hit Billing
This article examines how cache hit billing is reshaping the cost structure of large language model inference. It breaks down where input-side costs come from, explains prefix caching and its matching constraints, and outlines practical strategies for improving cache hit rates, such as stabilizing prompt prefixes, separating templates from content, and adding observability. It also covers engineering risks including billing definition drift, consistency and privacy concerns, and load testing distortion. The goal is to help teams build platform-independent cost engineering capabilities rather than chase a single vendor's discount.
1. Background: The Technical Signal Behind a Price Adjustment
A cloud provider’s model-as-a-service (MaaS) platform recently announced that, starting November 23, 2026 at 00:00 (Beijing time), it would lower the price of a large model service deployed in a single region. Under the new pricing, the input billing for the cache-hit portion is adjusted to 20% of the original rate, while all other billing items remain unchanged.
On the surface, this is a pricing announcement. In practice, it sends a clear technical signal: in the cost structure of LLM inference, input-side computation and cache reuse are being priced separately, and the cache-hit path is now strongly incentivized. For developers and enterprise architects, this means that optimizing prompt structure and cache hit rate has shifted from a nice-to-have to a quantifiable cost engineering discipline.
It is worth noting that platforms differ significantly in cache granularity, hit determination rules, validity periods, and billing definitions. This article does not discuss any specific vendor’s APIs or parameters. Instead, it focuses on the industry-standard technical principles and engineering practices.
2. Cost Model Breakdown: Why the Input Side Deserves Separate Optimization
A typical LLM call incurs costs from several sources:
- Input side: prefill computation for the prompt (system prompt, few-shot examples, context, retrieved snippets);
- Output side: token-by-token autoregressive generation;
- Additional items: long context, multimodal assets, retrieval augmentation, logging, monitoring, and other surrounding resources.
The autoregressive nature of Transformer-based models means that the input portion can be processed in parallel during prefill, with the results retained as a key-value cache (KV Cache), while the output portion must be generated serially, one token at a time. When multiple requests share an identical prefix, the prefill results for that prefix can theoretically be reused, eliminating redundant computation.
This is the technical basis for pricing cache-hit input separately: the marginal compute cost of the hit portion is significantly lower than that of the miss portion, so a lower price is consistent with cost logic. When the hit price drops to 20% of the original, prefix reuse capability directly determines the magnitude of the input bill.
3. How Cache Hits Work: Principles and Common Implementation Layers
3.1 The Basic Constraint of Prefix Caching
Mainstream industry approaches generally use prefix matching semantics: a cached sequence can only be reused when the new request’s token sequence matches it exactly from the beginning. This leads to one hard rule—any small change at an earlier position invalidates everything after it.
Request A: [System prompt][Tool definitions][Examples][User query]Request B: [System prompt][Tool definitions][Examples][User query 2]↑ The identical prefix can be reused; only the "user query" portion needs recomputation
3.2 Common Cache Layers
- In-request caching: reusing historical context across multiple turns within a single session;
- Cross-request prefix caching: multiple requests sharing the same system prompt and knowledge snippets;
- Semantic caching: returning historical answers for semantically equivalent questions. This is an application-level capability that you build yourself, and you must handle freshness and consistency on your own;
- Result caching: end-to-end caching for idempotent queries. It offers the highest hit rate but the narrowest applicability.
3.3 Example Code: Assembling a Stable Prompt Prefix
def build_prompt(system: str, tools: str, examples: str, query: str) -> list[dict]:# Fixed order: put low-volatility content first, high-volatility content lastreturn [{"role": "system", "content": system},{"role": "system", "content": tools},{"role": "user", "content": examples},{"role": "user", "content": query},]
What matters here is not the code itself but the ordering principle behind it: organize context by volatility, from lowest to highest.
4. Actionable Strategies for Improving Hit Rate
- Stabilize the prefix: Strip volatile fields such as version numbers, timestamps, random IDs, and usernames from the top of the prompt, and move them to later positions or the output side. Many teams see persistently low hit rates because they insert the current time at the very beginning.
- Separate templates from content: Put prompt templates under version control and inject content through placeholders, preventing templates from being polluted by runtime string concatenation.
- Order knowledge base chunks deterministically: In retrieval-augmented scenarios, sort retrieved snippets by a fixed rule and trim them to a stable length to prevent ordering jitter from invalidating the prefix.
- Session-sticky routing: Route requests from the same session to the same cache domain to reduce repeated prefill across nodes. For multi-region deployments, pay attention to the regional locality of caches—the fact that this price reduction covers only a single region shows that caches and compute resources have clear regional boundaries.
- Tiered caching and eviction policies: Set longer retention for high-frequency prefixes and shorter retention for long-tail content to prevent hot entries from being evicted all at once.
- Build observability: Bring hit rate, hit token count, and miss reasons into monitoring, alerting, and logging to form a “measure—attribute—optimize” loop.
5. Engineering Risks and Governance
- Billing definition drift: Cache definitions, validity periods, and discount ratios may change with platform policy. Architecturally, cost parameters should be configurable rather than hard-coded into business logic.
- Consistency and privacy: Semantic caches and result caches may return stale or unauthorized content. Tenant isolation, permission checks, and invalidation mechanisms are essential.
- Load testing distortion: If load test requests are highly repetitive, they artificially inflate the hit rate and lead to overly optimistic capacity planning. Construct long-tail traffic that closely resembles real distribution.
- Fallback plans: When the cache is unavailable, the pipeline must still return results normally—only at a higher cost, not with broken functionality.
6. Conclusion
The essence of this price adjustment is to explicitly price “cache reuse capability” as an optimizable engineering resource. For R&D teams, the right response is not to chase a specific vendor’s discount, but to build platform-independent cost engineering capabilities: stable prefixes, disciplined templates, fine-grained routing, and quantified observability. When the hit price is only 20% of the original, every percentage point of improvement in hit rate is reflected directly on the bill. And when billing rules change again, a system with built-in optimization only needs to adjust configuration, not re-architect.
