KV Cache Hit Rate and LLM Inference Cost

    LLM online inference cost is driven less by the model name than by how much computation a request can reuse. This article separates KV cache, hit conditions, and cost structure: why autoregressive decoding repeats work, what the cache stores, how memory scales, why hit rates can look extremely high, what still costs money after a hit, and how to keep prefixes stable so savings are real rather than shifted onto GPU memory.

    LLM online inference cost is often not decided by the model name alone. It depends on how much computation in a request can be reused. Claims of “extremely high cache hit rate” and “incremental cost near zero” usually do not mean weights are given away. They mean the key–value cache for the same prefix is read repeatedly, so a large share of prefill matrix work is skipped. To evaluate that, KV cache, hit conditions, and cost structure must be treated separately.

    Why autoregressive decoding repeats work

    Text generation is autoregressive: each step emits one new token, appends it to the sequence, and uses that as the next input. Attention produces query, key, and value vectors for every token. Without a cache, step n adds only one token but still recomputes key and value projections for all n tokens. The first n−1 keys and values were already computed, and they are identical if weights and numeric precision are unchanged. The longer the sequence, the worse this repetition; both prefill and token-by-token decode are dragged by history length.

    What the KV cache does

    Once a token’s keys and values are computed, they are written per layer and per head into GPU memory (or other fast storage that can be swapped in). The next step computes query, key, and value only for the newest token. The query attends to all historical keys and then weights historical values. Incremental work per step drops from “the full sequence” to “one new token plus cache I/O and attention.” The cache holds intermediate activations, not model weights. Weights still participate when computing the new token.

    Multi-turn chat, a fixed system prompt, the same tool schema, and a repeated long-document prefix let different requests share already-computed keys and values. If the server finds that cache by prefix identity, the request is a hit. If not, it must prefill again: a miss.

    Memory footprint can be estimated

    In a typical multi-head attention implementation, cache size is roughly:

    layers × KV heads × head dim × sequence length × bytes per element × 2

    The factor of 2 stores keys and values. Grouped-query attention reduces KV head count and shrinks the cache in proportion, which is one reason long context is practical. The following numbers are only order-of-magnitude illustrations, not measurements of any specific model.

    Assume 32 layers, 8 KV heads, head dim 128, sequence 4096, FP16 (2 bytes). Keys and values for one layer and one sequence are about 2×8×128×4096×2 bytes, ~16 MB; 32 layers ~0.5 GB. With batch size 8 and every context full, cache alone is several GB, excluding activation peaks and communication buffers. If sequence length, concurrency, or precision rises, cache can exceed the weights and become a memory and bandwidth bottleneck. A high hit rate is therefore not the same as “cache is free”: hits save repeated FLOPs; they still consume capacity and read bandwidth.

    Why hit rate can be very high

    Hit rate is the reused prefix length relative to the context length that is billed or that participates in attention. Platforms differ in how they count, but the idea is the same. It is easy to push the rate high because:

    • System prompts, role settings, and tool protocols are identical across many requests, and the server matches exact prefixes, not semantic similarity.
    • Multi-turn chat only appends the latest user message and model reply; the historical prefix grows but can be reused as a whole.
    • In agent loops, the same retrieved text or spec is carried in repeatedly; only the latest observation changes.
    • Temperature and sampling affect newly generated tokens, not keys and values already written, so they do not break hits on the old prefix.

    Under these traffic patterns, misses mostly happen on the first turn, when the prefix is rewritten, when the cache is evicted, or when the request lands on an instance that does not hold the replica. Seeing “most tokens counted as hits” after a few days reflects workload shape, not a change to the attention formula.

    What still costs money after a hit

    A hit can cut time to first token because a long prefix need not be recomputed. Decode still attends over all historical keys and values and writes the new token’s KV; output length does not vanish because of a hit. There is also:

    • Capacity: cache occupies GPU memory or tiered storage. Higher hit rates make hot data worth keeping; cold data is still evicted.
    • Reads: attention over very long context is often memory-bandwidth bound. When compute is idle, the bill may fall less than intuition suggests.
    • Consistency: the prefix must match token for token. An extra space, reordered system-prompt sections, or a different template wrapper invalidates the whole prefix.
    • Isolation: multi-tenant systems cannot freely share prefixes that contain private data. Only confirmed public prompts, or reuse inside a tenant boundary, are allowed.

    “Essentially free” is a narrow approximation: a short increment, an extremely long prefix already hot in cache, a provider that prices hit tokens near marginal cost, and GPU memory not yet filled by cache. Cache residency, cross-device copies, or a fresh prefill immediately return cost to miss-level.

    How to keep hits stable

    On the application side, put variable content last and keep stable instructions in the true prefix. Avoid rewriting the system prompt every turn or injecting timestamps and random IDs. Templates must be byte-stable, including whitespace and wrapping markers. For long material, excerpt or retrieve externally rather than stuffing the full document. When branching, keep a shared prefix before the fork so candidates share cache.

    On the service side, use prefix-aware scheduling: send requests that may share a cache to the instance that holds it, and evict with recency, a prefix tree, or tiered storage. Under memory pressure, swap out inactive sessions and pay a reload or recompute cost on swap-in. Monitor hit rate together with miss-driven prefill latency, cache occupancy, eviction count, and cost per thousand tokens—not a single hit percentage.

    Illustrative request layout (stable prefix vs. increment; not a vendor API):

    1. prefix = system_spec + tool_schema + shared_doc
    2. request = prefix + history + latest_user_turn
    3. # Hits on prefix and history are possible only when latest_user_turn changes

    How to judge another “price cut”

    For users, look at unit price and latency of hit tokens, miss tokens, and output tokens on your traffic; whether prefixes are stable; whether cache still fits at peak concurrency; and whether long outputs become the new dominant cost. Many independent short requests with a changing prefix will not hit often, so a cut is barely felt. Long system prompts plus multi-turn increments can save a lot—enough that a call can look almost free.

    For operators, high hit rate is a capacity problem: hot prefixes buy memory and scheduling complexity. Low prices must still cover bandwidth, failover recompute, and burst prefill on misses. High hits are engineering plus billing, best described as near-full reuse of a public prefix—not as every request and every token consuming no resources.

    Design prompts and sessions assuming cache is the default. Fix the prefix first, then compress context, then accept the result with hit rate, latency, and the bill together. That is how you tell whether a very high hit rate saved compute or only moved cost onto memory and architecture.