KV Cache and Cache Hit Rates: How LLM Inference Can Cost One-Quarter as Much

    KV caching reduces repeated computation during large language model inference, while prefix caching extends those savings across requests. This article explains how both mechanisms work, estimates their GPU memory requirements, and examines the engineering practices behind high cache hit rates—and what they mean for API costs and deployment decisions.

    1. Behind the Price Cut: Cache Hit Rates Matter

    A cloud provider recently announced a permanent reduction in its large language model API prices to one-quarter of their previous level. Viewing the move solely as a subsidy to attract customers, however, overlooks an important technical factor: inference caching.

    Developers using these models have reported that cached input accounts for a large share of their usage in multi-turn conversations and long-context tasks. Some have observed cache hit rates approaching 99%. In such workloads, most historical input tokens are billed at the cached-input rate rather than the full rate, substantially reducing their contribution to the bill.

    The price cut is the visible result; mature inference caching provides an important technical foundation for lower costs.

    To understand the connection, we need to answer two questions: What is a KV cache, and how can a serving system achieve such high cache hit rates?

    2. Why Autoregressive Inference Needs a Cache

    Language models generate text autoregressively: they produce one token, append it to the sequence, and then predict the next token. Conceptually, the process looks like this:

    1. Step 1: Input "The weather" → Generate " is"
    2. Step 2: Input "The weather is" → Generate " nice"
    3. Step 3: Input "The weather is nice" → Generate the next token

    These text fragments illustrate the process rather than a specific tokenizer’s output.

    In a Transformer, attention uses three representations: Q (query), K (key), and V (value). Without caching, each generation step would process the growing sequence again, recomputing the keys and values for historical tokens even though those representations have not changed.

    As the sequence grows, this repeated work becomes increasingly expensive. The model needs access to the historical context, but it does not need to recalculate every historical representation at every step.

    3. How KV Cache Works

    The core idea is straightforward: store the key and value representations for processed tokens in GPU memory and reuse them during subsequent decoding steps.

    For each new token:

    1. Read the historical keys and values from the cache instead of recomputing them.
    2. Compute Q, K, and V for the new token.
    3. Use the new query with the cached keys to calculate attention scores, then take the weighted sum of the corresponding values.

    The new token’s keys and values are added to the cache for future steps.

    This replaces repeated forward computation over the entire sequence with incremental processing of the new token. Attention still needs to access historical keys and values, so the work per step is not independent of context length. Nevertheless, avoiding repeated computation can substantially accelerate inference.

    There is also an important distinction between caching within a generation and reusing cached prefixes across API requests. KV caching supports efficient token-by-token decoding; prefix caching allows a serving system to reuse previously computed KV state when a new request begins with the same input.

    That cross-request reuse helps explain why cached input in multi-turn conversations can receive a substantial billing discount: the matching prefix does not require another full forward pass.

    4. The Trade-Off: GPU Memory Usage

    KV caching trades memory for computation. Its approximate size can be estimated as:

    1. KV cache size =
    2. 2 × number of layers
    3. × number of KV heads
    4. × dimension per head
    5. × sequence length
    6. × bytes per element

    The factor of two accounts for both keys and values. In standard multi-head attention, the number of KV heads equals the number of attention heads.

    Consider the following configuration:

    • 32 layers
    • 32 attention heads, each with its own key and value head
    • 128 dimensions per head
    • A sequence length of 4,096 tokens
    • FP16 storage, at 2 bytes per element

    The calculation is:

    1. KV storage per token per layer:
    2. 2 × 32 × 128 × 2 = 16 KiB
    3. Total:
    4. 16 KiB × 32 layers × 4,096 tokens = 2 GiB

    With a batch size of 10, the cache alone would require approximately 20 GiB of GPU memory.

    For long-context or highly concurrent workloads, KV cache memory can exceed the memory occupied by model weights and become a major bottleneck. KV cache memory calculators can help developers estimate these requirements without doing the arithmetic manually.

    5. How Cache Hit Rates Can Approach 99%

    Prefix reuse requires an exact match for the cached portion of the input. Very high hit rates typically depend on a combination of workload structure and serving-system engineering:

    • Reusable prefix design: Place stable content—such as system instructions, few-shot examples, and tool descriptions—at the beginning of the input. Multi-turn conversations can then reuse the unchanged prefix.
    • Cross-request cache sharing: Requests with identical prefixes can reuse the same server-side cache rather than maintaining separate copies for every conversation. Shared prefixes create more opportunities for reuse as request volume grows.
    • Cache eviction and tiered storage: Keep frequently used prefixes in GPU memory while moving less frequently used entries to host memory or SSD storage, balancing reuse against storage costs.
    • Cache-aware routing: Direct requests to nodes that already hold the relevant cached prefix, avoiding misses caused by routing them elsewhere.

    For application developers, the practical steps are simple:

    1. Put static content before dynamic content.
    2. Avoid inserting changing content into the middle of a reusable prefix.
    3. Keep system-prompt versions stable where possible.
    4. Preserve the conversation history rather than rewriting earlier messages between turns.

    An observed hit rate near 99% reflects a particular workload and serving setup, not a guaranteed result for every application.

    6. What This Means for Developers

    When a model service has mature prefix caching, total token count alone no longer tells the full cost story. The split between cached and uncached input becomes important.

    Organizing prompts for reuse can make long-context tasks, multi-turn conversations, and batch document question answering substantially cheaper than an estimate based entirely on full-price input tokens would suggest. The actual savings still depend on the provider’s cached-input pricing and the workload’s hit rate.

    For private deployments, the same principle affects infrastructure selection. When evaluating cloud-hosted container platforms and GPU instances, consider the inference framework’s caching capabilities and GPU memory management alongside the model itself.

    With identical model weights, differences in cache scheduling and memory handling can translate into several-fold differences in throughput and unit cost.

    Lower prices are the outcome; caching is one of the underlying levers. Understanding KV cache and prefix reuse helps developers interpret LLM inference economics—and design applications that benefit from those efficiencies.