Why LLM Inference Costs Keep Dropping: KV Cache and Prefix Reuse Explained

    This article explains why large language model inference keeps getting cheaper, focusing on the engineering factors behind the falling cost per token rather than pricing announcements. It breaks inference cost into compute, GPU memory capacity, and memory bandwidth, then shows how autoregressive decoding repeatedly recomputes key and value vectors and how KV Cache removes that work within a single request. It also covers how to estimate KV Cache memory usage, why long context and high concurrency can make it exceed model weights in size, and how prefix reuse turns repeated content across requests into cache hits. The article closes with a practical capacity and cost planning checklist for developers, including measuring real traffic, structuring stable content at the front of prompts, and tracking cost per token as an ongoing engineering metric.

    1. The Real Question Behind the Price Cut: A Shift in the Unit Cost Curve

    A recent “permanent price cut to one quarter” for a class of LLM services has kept the discussion focused on pricing. From an engineering perspective, price is only the outcome. The more useful question is what determines the inference cost per token, which parts can be reused, and which overheads cannot be compressed.

    Inference cost can be broken down into three parts:

    • Compute: the floating-point operations required to generate each token.
    • GPU memory capacity: which sets the upper bound on concurrency.
    • Memory bandwidth: which determines how fast historical context can be read.

    Any significant price reduction usually corresponds to one or more of these being substantially reduced through engineering. Among the three, the most overlooked and most optimizable is repeated computation.

    The reason a service can feel cheap only “after using it for a few days” is that real business traffic is not random text. It is highly templated. System prompts, tool definitions, knowledge base snippets, few-shot examples, and multi-turn conversation history all recur within a single session and often across sessions. When a platform can identify and reuse the intermediate computation results for this shared prefix, both the actual billing and the measured overhead come in well below the theoretical estimate based on recomputing everything.

    2. KV Cache: Where the Repeated Computation in Autoregressive Generation Comes From

    Transformer decoding is autoregressive: it produces one token at a time, appends it to the end of the sequence, and generates the next one.

    1. Step 1: input "It is" -> predict "sunny"
    2. Step 2: input "It is sunny" -> predict "today"
    3. Step 3: input "It is sunny today" -> predict the next token

    In the attention mechanism, every token produces three vectors: Q (Query), K (Key), and V (Value). The problem is that in Step 2, the K and V vectors for the first three tokens are identical to Step 1, yet they are computed again. The longer the sequence, the worse this redundancy becomes, and the overall complexity degrades from “processing one token” to “processing the entire sequence.”

    KV Cache takes a direct approach: the K and V for each token are computed once and kept in GPU memory. Later steps only compute the Q, K, and V for the newest token, use the new Q against all cached K to get attention scores, and then take a weighted sum over the cached V. The work per step therefore drops from O(sequence length) to a constant, which is the first major leap in inference throughput.

    3. Doing the GPU Memory Math: Capacity Estimation and the Concurrency Ceiling

    KV Cache usage can be estimated precisely:

    1. KV Cache bytes = 2 × layers × heads × head_dim × sequence_length × bytes_per_value

    For 32 layers, 32 heads, a head dimension of 128, and FP16 (2 bytes):

    1. Per token, per layer: 2 × 32 × 128 × 2 = 16384 bytes = 16 KB
    2. Per token, full model: 16 KB × 32 layers = 512 KB
    3. Sequence length 4096: 512 KB × 4096 ≈ 2 GB
    4. 10 concurrent requests: about 20 GB

    The conclusion is clear: with long context and high concurrency, KV Cache memory usage can exceed the model weights themselves and become the real bottleneck. In practice, engineering teams use techniques such as paged memory management, continuous batching, and quantization to raise effective concurrency. These are common industry practices, not proprietary features of any single platform.

    4. Prefix Reuse: Turning Repetition into Cache Hits

    KV Cache handles repetition within a single request. Prefix reuse handles repetition across requests. When multiple requests share the same prefix (the same system prompt, the same document, the same multi-turn history), the K and V for that prefix only need to be computed once, and later requests read them directly.

    The hit rate therefore becomes the key metric. As the hit rate approaches saturation, the vast majority of input no longer consumes real compute, and billing drops in step with actual overhead. One caveat: a hit requires the prefix to match byte for byte. Inserting a timestamp, a random ID, or changing the ordering will invalidate the cache. Practical measures include:

    • Put stable content first and variable parts such as user input at the end.
    • Template and version system prompts and tool definitions to avoid frequent changes.
    • In multi-turn conversations, append history rather than rewriting it.
    • Group batch offline jobs by prefix to increase similarity within each group.

    Illustrative code (pseudo-implementation, showing only the layering order):

    1. def build_prompt(system_block, docs_block, user_input):
    2. # Keep the stable prefix first and variable content last to maximize prefix reuse
    3. return f"{system_block}\n{docs_block}\n{user_input}"

    5. A Capacity and Cost Planning Checklist for Developers

    1. Measure before optimizing: collect the average input length, prefix repetition rate, and output length distribution of real traffic.
    2. Use the formula above to estimate memory and concurrency, and leave a safety margin to avoid queuing when long inputs arrive.
    3. Structure reusable content at the front, and monitor changes in the cache hit rate rather than looking only at unit price.
    4. For long context, prioritize retrieval-based trimming and segmented summarization to reduce ineffective prefixes.
    5. Build a cost-per-token dashboard on top of logging and monitoring with alerts, turning cost optimization into a sustainable engineering metric.

    Summary: the technical foundation of this round of price cuts is the systematic elimination of repeated computation in autoregressive inference. By understanding the boundaries between KV Cache and prefix reuse, developers can make explainable and reproducible trade-offs among budget, latency, and context length.