LLM Inference Cost Optimization: A Practical Guide to Cache Hit Billing
This article examines how fine-grained pricing for cached input tokens is reshaping LLM inference cost optimization. It explains prefix caching in the prefill and decode stages, presents the general billing formula with a cache hit discount factor, and analyzes the four main factors that determine hit rates: prefix stability, prefix length and sharing, concurrency and temporal locality, and routing or region consistency. It then covers architecture-level techniques such as layered prefixes, prefix alignment for conversations and retrieval results, affinity-based traffic routing, and write-side warmup, along with prompt governance, measurement, cost attribution, common pitfalls, and a practical implementation checklist. The focus is on reusing shared computation rather than simply choosing a cheaper model.
1. Background: The Technical Signal Behind a Pricing Adjustment
A cloud provider’s model-as-a-service platform announced that, starting at 00:00 Beijing time on November 23, 2026, it would reduce the price of a large model service hosted in a single region, Guiyang. The adjustment applies only to the “cached input” billing item, which drops to 20% of its original price; all other billing items remain unchanged. The announcement is short but information-dense: this is not a blanket price cut but a targeted reduction on a specific cost dimension, limited to a single region and effective on the hour.
For developers, the important part is not the discount itself but the pricing logic it reveals. Inference cost is being broken down into finer granularity, and reusable computation is being priced separately with a significant discount. The focus of cost optimization is shifting from “choosing a cheaper model” to “making the same requests hit more reusable computation.”
2. How It Works: Reusable Input Computation and Cache Hits
Large model inference has two stages. The prefill stage performs one forward pass over all input tokens and generates the key-value cache. The decode stage then produces output tokens one by one based on that cache. Prefill computation grows roughly linearly with input length and is the main cost driver in long-context scenarios.
The core insight behind prefix caching is that multiple requests often share exactly the same input prefix, such as system prompts, tool definitions, a few examples, or the body of a long document. Once the key-value cache for these tokens is generated, it can be reused without recomputation. Cached input tokens only incur the cost of reading the cache and a small amount of validation, so they are significantly cheaper than full prefill.
This leads to a general form of the billing model:
Input cost = uncached tokens × standard input price+ cached tokens × standard input price × cache hit discount factor
The cache hit discount factor is set by the service provider and is 0.2 in this adjustment. Two constraints matter: first, a hit usually requires the prefix to match token by token exactly, and any character difference causes all subsequent positions to miss; second, the cache has a capacity limit and a lifetime, so entries can be evicted.
3. Four Factors That Determine Hit Rate
First, prefix stability. If a system prompt contains timestamps, random identifiers, or request IDs, the prefix differs every time and the hit rate approaches zero. This is the most common and most easily overlooked problem in practice.
Second, prefix length and sharing. The longer the reusable portion and the more requests that share it, the greater the benefit. In multi-tenant scenarios, if tenants’ prompts differ substantially, the sharing space is limited.
Third, concurrency and temporal locality. Cache eviction is sensitive to time, so burst traffic and calls spaced far apart both reduce the hit rate.
Fourth, routing and region consistency. Caches are usually bound to a specific instance or region. If a load balancer spreads requests with the same prefix across different nodes or regions, the hit rate is diluted. The fact that this adjustment is limited to a single region also suggests that the region dimension needs to be included in the cost model.
4. Architecture-Level Optimizations
Layer the prefix. Divide request content into a stable layer, a semi-stable layer, and a volatile layer. Put the system role and tool definitions in the stable layer, domain knowledge and examples in the semi-stable layer, and user input in the volatile layer. The order must be fixed, and volatile content must always come last.
[Stable layer] Role definition + output constraints + tool descriptions[Semi-stable layer] Domain knowledge snippets + fixed examples[Volatile layer] Current user input + dynamic information such as timestamps
Align prefixes for conversations and retrieval results. In multi-turn conversations, keep the history sequence stable and avoid rewriting or summary-style compression that causes prefix drift. In retrieval-augmented scenarios, apply stable sorting and normalization to retrieved documents to avoid ordering jitter.
Traffic scheduling affinity. At the gateway layer, use consistent hashing based on a prefix fingerprint so that requests with the same prefix preferentially land on the same instance, improving temporal locality.
Write-side warmup. For known high-frequency long prefixes, proactively issue a warmup call after system startup or a change to avoid a spike of misses during cold start.
5. Prompt and Content Governance
Normalize text by removing unnecessary whitespace and invisible character differences; render from templates using fields concatenated in a fixed order rather than iterating over a dictionary in arbitrary order; version prompts so that any change is treated as a new prefix and rolled out gradually; and control the granularity of volatile fields by pushing high-frequency changing information as far back as possible.
def build_prompt(system_v, knowledge_v, user_input, dynamic):# Keep the stable prefix first and volatile content last to ensure a token-exact prefixreturn f"{system_v}\n{knowledge_v}\n{user_input}\n{dynamic}"
6. Measurement, Validation, and Cost Attribution
Optimization must be based on a closed data loop. Recommended metrics include the share of cached tokens, the number of uncached tokens, average input length, prefix fingerprint distribution, cache eviction frequency, input cost per request, and cost per thousand successful calls.
For validation, first compare hit rate and cost with the feature on and off using shadow traffic, then run a small-scale canary, and finally roll out to all traffic. In load testing, construct both high-sharing and low-sharing request sets and observe both ends of the cost curve, so that an ideal sample does not overestimate the benefit.
Cost attribution needs to map to business dimensions: calculate unit cost by scenario, tenant, and API, and identify which paths still have long prefixes that are not being reused. Note that the specific discount factor, cache capacity, and cache lifetime are governed by the provider’s official documentation; this article does not assume any undisclosed parameters.
7. Common Pitfalls
One is putting dynamic information into the system prompt, which invalidates the cache entirely. Another is assuming the discounted item covers all input, when it only applies to the cached portion. Others include ignoring the scheduling impact of region and instance dimensions, sacrificing correctness for hit rate by forcibly reusing expired knowledge snippets, and treating hit rate as the only goal while ignoring regressions in end-to-end latency and output quality.
8. Implementation Checklist
Map out request templates and divide them into the three layers; build a dashboard for prefix fingerprints and hit rate; implement affinity routing at the gateway; add warmup for high-frequency long prefixes; bring prompts under version control and gradual rollout; perform cost attribution by business dimension; and rerun comparison load tests after every model or template change. Following this path, the cost reduction from cache hits typically appears within a few iterations and continues to grow as shared prefixes accumulate.
