Why LLM Inference Prices Keep Falling: The KV Cache Explained

    LLM inference prices have dropped sharply, in some cases to a quarter of earlier levels or lower. This article explains the technical basis for that trend. It covers what the KV Cache is, how it works, why its hit rate determines inference cost, and which other engineering optimizations support lower prices. It also gives a method for estimating KV Cache memory use and practical tips for writing prompts that cache well.

    Many people first attribute falling LLM prices to price wars or subsidies. From a technical standpoint, however, the long-term decline rests on changes to the cost structure of inference, driven by a set of low-level optimizations. The most central and most overlooked of these is the KV Cache and the optimization of its hit rate. This article explains what the KV Cache is, how it works, why cache hit rate determines inference cost, and what other engineering measures reduce costs.

    1. Autoregressive Generation: A Source of Repeated Computation

    Large language models generate text autoregressively. At each step, the model predicts only the next token, then appends that token to the end of the input sequence and uses the extended sequence as input for the next prediction.

    Consider a simple example. Suppose the user enters “今天天气” (the weather today):

    • Step 1: The input is “今天天气” and the model outputs “真”.
    • Step 2: The input is “今天天气真” and the model outputs “好”.
    • Step 3: The input is “今天天气真好” and the model predicts the next token, and so on.

    The inefficiency lies in how the attention mechanism computes results. In a Transformer, each token produces three vectors: a Query (Q), a Key (K), and a Value (V). In step 2, the model must compute the K and V vectors for the tokens “今天”, “天气”, and “真”. Step 1 already computed these same K and V vectors without any change. The longer the sequence, the more wasteful this repetition becomes. For a sequence of length N, a naive attention implementation has a computational complexity close to O(N²), and most of that work repeats calculations for historical tokens.

    2. KV Cache: Trading Memory for Computation

    The idea behind the KV Cache is simple: store results that have already been computed, and do not recalculate them.

    After the model processes each token, it saves the K and V vectors that the token produces in each attention layer to GPU memory. In the next step, the model reads the K and V vectors for historical tokens directly from memory. It only needs to compute Q, K, and V for the newest token. It then scores the new Q against all cached historical K vectors and computes a weighted sum of the cached V vectors.

    As a result, the computation per step drops from processing the entire sequence to processing a single token, which speeds up inference by orders of magnitude. This is a classic space-for-time tradeoff: memory usage increases, but computation drops substantially.

    3. How Much Memory the KV Cache Requires

    The memory footprint of the KV Cache can be estimated precisely with the following general formula:

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

    The factor of 2 accounts for the two cached tensors, K and V. Consider a hypothetical model with 32 layers, 32 attention heads, a head dimension of 128, a sequence length of 4096, and FP16 precision (2 bytes per value):

    • KV size per token per layer: 2 × 32 × 128 × 2 = 16,384 bytes, or 16 KB.
    • Total cache for one full sequence: 16 KB × 32 layers × 4096 tokens = 2 GB.

    If the server handles 10 concurrent requests (batch size 10), the memory footprint grows to 20 GB. For very long contexts or high concurrency, the KV Cache can exceed the memory used by the model weights themselves, which makes it the main constraint in inference deployments. This is why optimizing the KV Cache has become central to inference engine design. Common approaches include multi-head attention variants, KV cache quantization and compression, and paged memory management.

    4. Cache Hit Rate: The Real Driver of Lower Prices

    Once you understand the KV Cache, it becomes clear how cache hit rate directly reshapes the cost curve.

    In production, many requests share highly overlapping prefixes. Common examples include identical system prompts, the same few-shot examples, conversation history accumulated over multiple turns, and document excerpts that RAG pipelines repeatedly retrieve. If the inference system can detect these repeated prefixes and reuse the KV cache computed earlier, which is the idea behind prefix caching or prompt caching, the matched tokens require almost no attention computation. Their cost approaches zero.

    Some services reportedly reach cache hit rates close to 99%. At that level, most tokens carry only a small share of the computation cost. Users experience this as very low prices. For providers, the savings come from engineering efficiency, not from subsidies. This is the technical basis for sustained price reductions rather than time-limited promotions.

    5. The Engineering Measures Behind Lower Prices

    KV Cache reuse alone does not explain the full decline. The overall reduction in inference cost results from several optimizations working together:

    1. Attention architecture changes: Attention variants that share or compress KV heads reduce the size of the KV Cache at the source.
    2. Quantization: Low-bit quantization of model weights and the KV Cache lowers memory and bandwidth costs several times over, while keeping accuracy loss within acceptable limits.
    3. Scheduling and batching: Techniques such as continuous batching and request priority scheduling raise hardware utilization, so each unit of compute serves more requests.
    4. Memory management: Paged KV Cache management reduces memory fragmentation and increases the number of concurrent requests per GPU.
    5. Scale effects: Higher call volume increases cache reuse and keeps resource utilization stable. Unit costs then fall further, creating a positive feedback loop.

    Developers can also apply several practical techniques. Place stable system prompts at the beginning of the input, avoid inserting random content into prefixes, and keep conversation history in a consistent order. These steps increase the probability of prefix cache hits and can lower the actual bill.

    6. Conclusion

    The sharp decline in LLM service prices mainly reflects the maturing of inference engineering. The KV Cache removes redundant computation in autoregressive generation. Prefix caching pushes that optimization further. Quantization, scheduling, and memory management add to the gains. Together, these changes make prices low enough that “rounds down to free” is no longer a joke. For developers, understanding these mechanisms explains industry pricing trends and shows how to design applications that benefit from them. Structuring prompts and context so they cache well is one of the most direct ways to reduce cost. Teams that want to add LLM capabilities quickly can also look at general-purpose model inference services from platforms such as Baidu AI Cloud, then weigh cost and performance against their own workloads.