Why LLM Inference Costs Are Falling: Understanding KV Cache Hit Rates

    The sharp decline in large language model API prices is closely tied to advances in inference efficiency. This article explains how KV Cache eliminates repeated computation during autoregressive generation, how prefix caching enables reuse across requests, why cache hit rates can approach 99%, how much GPU memory KV Cache consumes, and how developers can structure requests to improve cache reuse and reduce costs.

    1. The Technical Variable Behind Lower Prices: Cache Hit Rate

    A large-model API recently announced another permanent price reduction, bringing its pricing down to one quarter of the original level. The move triggered extensive discussion in the developer community. Many attributed the reduction to business strategy, but actual usage reveals an important technical factor: after running the service for some time, users found that its cache hit rate could approach 99%.

    In other words, almost all repeated computation was served from cache, reducing the marginal cost to an extremely low level.

    This raises two important technical questions:

    1. Why can the cache hit rate become so high, and what are its technical limits?
    2. How much does cache reuse actually contribute to lower inference costs?

    Answering these questions requires an understanding of a fundamental GPU memory optimization technique used in large-model inference: KV Cache.

    2. Autoregressive Generation and the Source of Repeated Computation

    Language-model text generation is an autoregressive process. The model generates one token at a time, appends it to the end of the sequence, and then predicts the next token. For example:

    • Step 1: Given “The weather today,” the model predicts “is”;
    • Step 2: Given “The weather today is,” the model predicts “good”;
    • Step 3: Given “The weather today is good,” the model continues predicting the next token.

    The problem is that the attention mechanism must process the entire input sequence at every step. For each token, attention produces three vectors:

    • Q — Query
    • K — Key
    • V — Value

    At step 2, the model must recalculate the K and V vectors for “The,” “weather,” “today,” and “is.” However, the K and V values for the historical tokens were already computed during step 1, and they have not changed.

    For a sequence of length n, the total computation of naive inference is on the order of O(n²). The farther generation proceeds, the more historical tokens are recalculated, and the more computation is wasted.

    3. KV Cache: Trading GPU Memory for Computation

    The core idea behind KV Cache is straightforward: after calculating the K and V vectors for a new token, the model stores them in GPU memory. During the next inference step:

    • The K and V vectors for historical tokens are read directly from the cache instead of being recalculated;
    • Only the newly generated token needs its Q, K, and V vectors computed;
    • The new Q vector is then used with all cached K vectors to calculate attention scores, and the cached V vectors are combined according to those scores.

    As a result, each step processes only the newest token rather than the entire sequence. This can significantly accelerate inference. It is a classic space-for-time trade-off: GPU memory consumption is exchanged for a substantial reduction in computation.

    When KV Cache is extended from a per-request, in-process cache to a shared cache that can be reused across requests—commonly known as prefix caching or context caching—the benefits can extend across multiple requests. If several requests share the same system prompt or document prefix, that portion only needs to be processed once. Subsequent requests can reuse the cached result.

    This is the engineering foundation for high cache hit rates. The longer the system prompt, the more stable the conversation history, and the greater the prefix reuse across requests, the higher the hit rate can become.

    4. How Much GPU Memory Does KV Cache Use?

    The size of KV Cache can be estimated with the following general formula:

    1. KV Cache size = 2 × number of layers × number of heads × head dimension × sequence length × bytes per element

    Consider a model with:

    • 32 layers
    • 32 attention heads
    • A head dimension of 128
    • A sequence length of 4,096
    • FP16 precision, using 2 bytes per element

    The calculation is:

    • KV size for one token in one layer:
      2 × 32 × 128 × 2 = 16,384 bytes = 16 KB
    • KV size for one token across all 32 layers:
      16 KB × 32 = 512 KB
    • KV size for a complete 4,096-token sequence:
      512 KB × 4,096 ≈ 2 GB

    If 10 requests are served simultaneously, with a batch size of 10, the total KV Cache memory consumption reaches approximately 20 GB.

    This example highlights two important facts:

    1. For long-context or large-batch workloads, KV Cache can consume more GPU memory than the model parameters themselves and become the primary inference bottleneck.
    2. When cached results can be reused, the system saves not only computation but also the memory allocation and data-movement overhead associated with recalculating and managing that context. This helps explain why high cache hit rates can translate directly into substantially lower prices.

    The industry has developed several approaches to address this bottleneck. Multi-Query Attention (MQA) and Grouped-Query Attention (GQA) reduce the number of K/V heads and therefore shrink cache size. Other techniques, including quantized caches such as INT8 KV Cache and PagedAttention-style paged memory management, reduce cache costs from different angles.

    5. How Developers Can Benefit and Improve Cache Reuse

    Understanding these mechanisms allows developers to improve cache hit rates and reduce inference costs in practical applications:

    • Keep the prefix stable: Keep system prompts as consistent as possible. Avoid inserting dynamic content such as timestamps or random IDs at the beginning of a request, because this can break prefix matching.
    • Append multi-turn conversations in order: Preserve the original order of conversation history instead of rearranging or rewriting earlier messages.
    • Separate static and dynamic content: Place long documents and knowledge-base context in the request prefix, and put the user’s changing input after it.
    • Use tiered pricing where available: Some cloud providers offer lower rates for cached tokens or cached portions of requests. Designing request structures to maximize cache reuse can directly reduce API costs.

    6. Conclusion

    The continued decline in large-model inference prices may appear to be driven primarily by commercial competition. At a deeper level, however, it reflects continuous progress in inference-system engineering.

    KV Cache and the prefix-caching mechanisms built on top of it eliminate much of the repeated computation inherent in autoregressive generation. As cache hit rates approach their practical limits and marginal costs move closer to storage and scheduling costs, a price reduction to one quarter of the original level no longer necessarily represents a loss-leading strategy. It can instead be the natural result of technical efficiency gains.

    For developers, understanding this mechanism is useful for two reasons: it provides insight into the direction of industry pricing, and it offers practical guidance for reducing the cost of their own model applications.