KV Cache Hit Rate and the Effective Cost of LLM Inference
The real cost of inference is rarely set by list price alone. Whether inputs hit the cache, how long outputs run, and whether concurrency saturates GPU memory all rewrite the "sticker price" into a very different effective unit price. This article explains how to move from list price to effective cost, how KV caching turns autoregressive recomputation into cache reads, how to estimate cache memory before discussing hit rate, why hit rates can climb high enough to look free, and how to keep price cuts, caching, and throughput on separate books. It includes capacity formulas, a tiered view of caching scope, engineering practices for stable hits, common misjudgments, and a practical checklist for deciding whether a price change is an order-of-magnitude shift or just a new number on the price sheet.
The real cost of serving inference is often not determined by list price alone. Whether an input hits the cache, how long the output is, and whether concurrency fills up GPU memory can all rewrite the “sticker price” into a completely different effective unit price. Reading a price cut as “the model suddenly became worthless” misses the caching mechanism itself: when many requests share the same prefix, the token-billed input side can look almost free, but this is the combined result of billing rules and compute reuse, not parameters or precision vanishing into thin air.
Move the Question from List Price to Effective Cost
To evaluate a long-term price cut, look at four things at the same time.
- Whether the three token classes—missed input, cached input, and output—are priced separately, and how large the discount on the cached price is relative to the missed price.
- The share of context taken by system prompts, tool descriptions, retrieval templates, and multi-turn history in your workload.
- Whether the cache is reused only within a single session or is allowed to share the same prefix across requests.
- Whether high hit rates reduce compute, or mainly shift the bottleneck from compute to memory capacity and bandwidth.
If a request has a 100,000-token context, of which 99,000 tokens are a stable prefix and only 1,000 are newly added this turn, then under prefix-based billing the input hit rate is 99%. This has nothing to do with how “cleverly” the model computes; it only means the incremental compute has been compressed into the tail. Output tokens are usually still billed at full inference cost, so long answers and multi-step agent calls can still be the main body of the bill.
The effective input unit price can be roughly estimated as:
effective input price ≈ hit rate × cached price + (1 − hit rate) × missed price
If list price drops to one quarter of the original and the workload barely hits the cache, the bill falls by roughly the same proportion; if it was already highly cached, the cut mainly acts on the missed tail and on output, and the perceived effect will not match the marketing message. When comparing before and after a cut, fix the prompt structure, context length, output length, and concurrency, then look at the cost and latency per successful task—not just the list price per million tokens.
Without a Cache, Generation Repeats Its Own Work
Text generation is an autoregressive process: each step produces only one new token, then appends it back to the sequence as input for the next step. In attention, every token forms three sets of vectors—query, key, and value. If the next step re-encodes the entire history, the keys and values of the historical tokens are exactly the same as in the previous step, yet they get computed again. The longer the sequence, the more pronounced this repetition becomes, and latency and compute accumulate almost with the length already generated.
The key-value cache works like this: once a token’s key and value are computed, they are written to GPU memory layer by layer. Subsequent steps compute query, key, and value only for the newest token, then use the new query to match against all cached keys and take a weighted sum over the cached values. This converges each step’s work from “recompute the whole sequence” to “process only the new token,” with the history becoming a cache read. This is an industry-standard inference optimization, not a proprietary term of any single model generation.
Estimate Memory Before Talking About Hit Rate
Cache size is proportional to the number of layers, the number of key-value heads, the per-head dimension, the sequence length, and the numeric precision; with batched concurrency you also multiply by the batch size. Use the following order-of-magnitude formulas for capacity planning (with grouped-query attention, use the number of key-value heads, not the number of query heads):
key-value bytes per token, per layer ≈ 2 × num_key_value_heads × head_dim × bytes_per_element
total cache ≈ the above × num_layers × sequence_length × sequences_in_flight
As an order-of-magnitude example only: with 32 layers, 32 key-value heads, 128 dimensions per head, and half precision at 2 bytes, a single token in a single layer is about 16 KB, and one token across 32 layers is about 0.5 MB. At a sequence length of 4096, one sequence is about 2 GB; with ten sequences in flight at once, the cache alone can reach about 20 GB, sometimes becoming the bottleneck before the weights themselves. Dropping precision to 1 byte roughly halves the size, but you must separately verify whether long context and numerically sensitive tasks can accept it. Longer contexts and larger concurrency scale this term linearly, so “very high hit rate” and “plenty of GPU memory” are not the same statement.
When planning, leave headroom for paged management, prefix replicas, and peak fluctuations, and avoid treating the theoretical value as sellable capacity.
Why the Hit Rate Can Be High Enough to Look Free
A high hit rate usually comes from request structure, not from the cache algorithm suddenly compressing all computation losslessly.
- System prompts, personas, output formats, and tool lists are byte-for-byte identical across many requests, making them suitable as a shared prefix.
- Multi-turn dialogue only appends the user’s new question and the generated answer at the tail, so historical key-values can continue along the session.
- In retrieval-augmented setups, if document chunk order is stable and the template is fixed, the same document prefix can be reused across users; change the document order and prefix matching fails from the branch point onward.
- In agent loops, the same planning instructions recur, and the increment is just the short text returned by tools.
Prefix caching generally requires a continuous match from the start of the sequence. Inserting a date, user ID, or random number in the middle makes everything after it miss. Moving volatile fields to the end and fixing stable fields at the beginning—while controlling whitespace and punctuation—often raises the hit rate more than switching models does.
The hit rate can also be graded by scope, to avoid conflating different capabilities.
- In-step caching: reuse already-computed key-values within a single generation, solving autoregressive recomputation; this is essentially standard in inference.
- Session caching: later turns of the same conversation continue to use history; the hit rate rises with the number of turns, but the memory stays occupied until the session ends.
- Cross-request prefix caching: different users share the same system prompt or document prefix; the hit rate can be extremely high, but you must enforce tenant isolation to prevent one tenant’s context from being read by another.
The so-called “nearly full hit rate” is mostly the third tier combined with “very long prefix, very short increment” workloads. Switch to traffic whose prompts differ slightly and the hit rate drops immediately. Estimating your own bill from someone else’s demo traffic produces very large errors.
Keep Price Cuts, Caching, and Throughput on Separate Books
Permanently lowering list price changes the price table per token; caching changes which tokens still need to be fully computed. When the two combine, several typical situations appear.
- Short question, short answer, no shared prefix: low hit rate, the cut is reflected almost linearly in the bill, and caching gains are limited.
- Long system prompt, short increment, short output: the effective input price is close to the cached price, and if the cut mainly targets the missed price, the perceived effect is limited.
- Long output or many tool round-trips: output and intermediate reasoning steps make up a large share, and optimizing input caching alone is not enough.
- High concurrency with long context: cache hits cut repeated compute, but memory is still occupied by sequence length, so the service may first be saturated by capacity or bandwidth, showing up as queuing rather than getting cheaper.
Therefore, price communication should provide, at the same time: separate prices for cached and missed tokens, the output price, the context limit, and whether cached retention time is billed. Saying only “input is cut to one quarter” without defining the hit accounting makes procurement comparison impossible.
How to Make Hits Reliable in Engineering
Prompt side: version your system prompts, avoid concatenating timestamps, random seeds, and user nicknames into the prefix; sort retrieval results by a stable key; use an explicit suffix region for segments that must change. You can use fixed fixtures to measure the “prefix byte-identity rate” and catch needless invalidations before launch.
Service side: route the same session back to the instance holding its cache, or use a routable prefix hash; set cache lifetime to match the business session; under memory pressure, evict cold prefixes by least-recently-used rather than randomly discarding hot system prompts. When sharing prefixes across tenants, cache only public templates allowed by policy, and isolate user documents by tenant by default.
Precision and paging: in a general inference framework, the cache can be paged by block, avoiding reserving the maximum length for every sequence. Lowering key-value precision buys capacity, but whether it affects code, math, or long-document consistency must be regression-tested on a business set, not judged by perplexity alone.
Observability: at minimum, log missed token count, cached token count, output token count, cache bytes occupied, eviction count, and time to first token. Compute the effective unit price by replaying these three token classes, so you can tell whether a cut actually lands on task cost. When deploying inference on a cloud such as Baidu AI Cloud, just wire these metrics into your existing monitoring, alerting, and logging services; there is no need to bind to any single model’s billing story.
An illustrative accounting can be written as:
hit_rate = cached_input_tokens / (cached_input_tokens + fresh_input_tokens)effective_input_price = hit_rate * price_hit + (1 - hit_rate) * price_misstask_cost = fresh_input_tokens * price_miss+ cached_input_tokens * price_hit+ output_tokens * price_out
Here prices come from the contract or price sheet, and token counts come from gateway logs. Do not multiply a demo environment’s hit rate by production concurrency to size cache capacity; size capacity by peak sequence length instead.
Common Misjudgments
Calling in-step caching “free across users” overestimates the gains and creates a risk of cross-tenant data leakage. Treating hit rate as a quality metric ignores the output price and failed retries. Caching an incorrect or stale tool description makes later requests reliably reuse the wrong prefix—the higher the hit rate, the faster the error propagates—so template changes must proactively invalidate the relevant prefixes. Also, if batching forcibly concatenates different prefixes, it may raise compute utilization but lower prefix hits; the two must be traded off according to the hardware bottleneck.
Landing Checklist
- Map the token composition of a typical request: public prefix, retrieval body, user increment, output.
- Measure the hit rate on your own business samples rather than citing an external “nearly 99%” claim.
- Recompute task cost before and after the cut with the split-price formula, listing the output share separately.
- Estimate cache GPU memory at peak concurrency, and confirm the eviction policy and session affinity.
- Draw isolation boundaries between public prefixes and user data, and make template updates invalidatable.
- Compare latency, success rate, and cost per task on a fixed task set before deciding whether to switch traffic to the new price.
A list-price reduction is welcome, but it is only one column of the price sheet. The key-value cache decides whether historical tokens still need recomputation, the prefix structure decides whether those tokens can be reused across requests, and GPU memory decides how much concurrency that reuse can sustain. Put these three things and the output length on the same bill, and only then can you tell whether another price cut is an order-of-magnitude change for your business or just a different number on the price sheet.
