What Is LLM Cache Hit and How It Lowers Token Costs
This article explains what a cache hit means in large language model inference and why it reduces token costs. It covers the prefill and decode stages, the three conditions for reusing a KV Cache, the gap between full-price input and discounted cache reads, and the trade-offs in GPU memory, eviction, and routing. It also lists practical ways to raise the hit rate, such as stable prefix layout, suppressing implicit jitter, careful use of summarization, trimming tool output, adapting call cadence, and data-driven tuning, plus common misconceptions to avoid.
1. Starting From a Counterintuitive Billing Pattern
A single agent task can trigger hundreds of model calls. Intuitively, every request has to resend the full conversation history, that history keeps growing, and cost should balloon quadratically. Real bills are often far lower than that.
The reason is not a mystery. Usage records usually contain two cache-related counters, named differently across platforms: some call it “cached tokens,” others “cache read input tokens.” In agentic coding workloads, the measured shape looks roughly like this: a single-step request carries about 119K tokens of history as its prefix, while only about 875 tokens are genuinely new and need full computation. Most of the former is billed at a discounted tier of the normal input price.
This rule is not a marketing feature of any particular product. It is a low-level constraint of the inference system. It shapes the API billing structure, how GPU memory is reused, how a cluster schedules work, and how upper-layer frameworks should organize context.
2. What a Cache Hit Actually Is
LLM inference has two stages: prefill and decode. Prefill processes every input token and produces the key-value pairs (KV Cache) for each layer and each attention head. Decode then emits new tokens one by one, appending fresh key-values as it goes.
A cache hit means this: if the leading tokens of the current request are identical to those of an earlier request, the KV Cache for that prefix can be reused directly, with no need to repeat the expensive prefill computation.
Three conditions deserve emphasis:
- It must be a prefix, not an arbitrary fragment. Attention depends on position and causal order, so inserting or modifying a single token in the middle invalidates the key-values at every position after it.
- It must match token by token. Spaces, line breaks, punctuation, serialization order, and the raw text returned by tools all count; any single difference causes a miss from that position onward.
- A hit needs a “survival window.” The cache occupies GPU memory and can be evicted. If the gap between two requests is too long, or system load is too high, the hit rate naturally decays.
So a “cache hit” is not a switch-style configuration. It is a statistical outcome determined jointly by content stability and call cadence.
3. Why Hits Cut Costs So Much
The cost difference comes from the difference in computation. On a miss, the entire history goes through prefill; on a hit, that portion only pays for reading GPU memory plus a small amount of validation. The industry generally prices cache reads at a discount to normal input precisely because their real compute consumption is far below a full prefill.
A rough estimate shows the magnitude (illustrative only, not any specific pricing):
Without reuse:Per call ≈ 119,000 tokens at full price100 calls ≈ 11,900,000 tokens at full priceWith prefix reuse (assume 95% prefix hit, cache read billed at 1/10):Per call ≈ 119,000 × 5% full price + 119,000 × 95% × 0.1≈ 5,950 + 11,305 ≈ 17,255 equivalent full-price tokensInput-side cost drops about 85% versus no reuse
There is a second benefit as well: time to first token (TTFT) drops sharply. Skipping prefill for a long prefix makes responses noticeably faster, which often affects the experience of multi-turn interactive tool calls more directly than cost does.
4. The Constraints: GPU Memory, Eviction, and Scheduling
Reuse is not free; it changes the system’s resource profile.
- GPU memory usage shifts from “transient” to “resident.” Keeping a prefix reusable for a while means trading GPU memory for computation.
- The eviction policy sets the ceiling on hit rate. A common approach evicts by recency of use and priority, so the hit rate falls during load peaks.
- Scheduling affinity becomes mandatory. A request must be routed to the instance holding the matching cache, otherwise no hit can occur. This pushes load balancing from plain round-robin toward affinity-aware scheduling, and forces you to accept hit-rate jitter during scaling and instance restarts.
- Observability must cover the cache dimension. Monitoring only QPS and total tokens is not enough; cache hit rate and cache read share need to be part of monitoring, alerting, and logging before cost anomalies can be traced.
5. Engineering Practice: Systematically Raising the Hit Rate
1. Prefix layout: stable content first, volatile content last
Put the system prompt, tool definitions, domain rules, and a few examples at the very front and keep them byte-stable; put timestamps, random IDs, live user input, and retrieval results at the end.
[Stable] system instructions + tool schema + output rules + fixed examples[Semi-stable] facts and code context confirmed early in the session[Volatile] this turn's retrieved snippets, current time, new user input
2. Suppress implicit jitter
Timestamps precise to the second, randomly ordered candidate sets, floating-point formatting differences, and unstable dict serialization order can all invalidate a prefix that would otherwise hit. The principle: dynamic information should appear only where necessary and as late as possible.
3. Use “compression and rewriting” with care
Summarizing history looks like it saves tokens, but if the summary is regenerated every turn, the prefix changes every turn and reuse is destroyed. A more robust approach is to freeze history in segments: once a segment is finalized it is never modified, and new content is appended after it.
4. Keep tool output small
Tool results are a hotspot for prefix pollution. Apply structured trimming and pagination to logs, files, and retrieval results, returning only the fragment this turn actually needs.
5. Adapt call cadence to the cache lifecycle
Batching, serializing, or spacing calls too far apart lengthens the cache’s idle time. Where the business allows, submitting consecutive steps of the same session close together can significantly raise the hit ratio.
6. Tune with data
Build a minimal observability table and track, per business line: average prefix length, cache read share, the position where misses start, and average call interval. Wherever misses cluster is where optimization should begin.
6. Common Misconceptions
- Assuming identical content always hits. Cross-session, cross-instance, and out-of-window cases can all miss.
- Assuming the cache fixes model capability. It affects only cost and latency, not output quality.
- Treating hit rate as a pure client-side metric. It is also affected by server-side load and eviction policy, and needs observation from both sides.
- Using the cache as an excuse to drop context. Semantically necessary information must not be removed just to keep the layout tidy.
7. Conclusion
Cache hits turn “context length” from a pure liability into a partially amortizable asset. For developers, there are three real levers: a stable prefix layout, clean boundaries for dynamic information, and a cost observability system centered on cache hit rate. Building this mechanism into the framework layer, on top of general cloud capabilities such as container platforms, logging services, and monitoring and alerting, is what finally makes the cost curve of long sessions and multi-step agent tasks controllable.
