LLM Prompt Caching and Price Reduction: The Engineering Logic Behind Prefix Cache Hits

    This article explains why LLM API providers can sharply reduce prices for cached input tokens, framing the change as a restructuring of inference cost rather than a marketing discount. It breaks down the two phases of LLM inference, shows why AI agent workloads with long stable prefixes and short changing suffixes naturally achieve high cache hit rates, and describes how compact KV cache representations amplify the benefit. You will also find a practical reading of tiered cache pricing, six actionable engineering practices for designing cache-friendly prompts, and common misconceptions about hit rates, byte-level prefix matching, and output cost.

    1. What Is Really Happening: Not a Discount, but a Restructured Cost Model

    A cloud provider recently cut the price of the cached portion of input tokens across its LLM service lineup to one tenth of the launch price, stacking it on top of existing discounts to create what is effectively a “discount on a discount.” On the surface this looks like a marketing move. From an engineering perspective, it is better understood as the inevitable outcome of re-examining the cost structure of inference.

    To see why, start with how LLM inference costs are built. Processing a request roughly splits into two phases. The first is a forward pass over the input sequence that generates and writes the key-value cache (KV Cache). The second is autoregressive decoding that produces output on top of that cache. The first phase scales with input length and is compute-intensive. The second scales with output length and is memory-bandwidth-intensive. A cache hit means the key-value states for the prefix already exist, so the server can skip the repeated forward pass and reuse the existing state. What is saved is compute and time-to-first-token, not the full cost of storage and bandwidth. That is why the price can drop dramatically without going to zero.

    2. Why Agent Workloads Are a Natural Fit for Prefix Caching

    Agentic applications have a request shape that differs structurally from the traditional one-question-one-answer pattern, and that difference is the root cause of higher hit rates.

    • Long, stable prefix: system prompts, structured tool and function descriptions, repository context, long-term memory, and conversation summaries stay essentially unchanged within a session and often make up the bulk of the input.
    • Tiny suffix: in each turn, only the latest observation, the current subtask description, a run identifier, and similarly small pieces of content actually change.
    • High-frequency multi-turn: a single task typically involves a dozen or even dozens of model calls, so the prefix is reused repeatedly.

    A schematic view of the structure:

    1. [ stable prefix: system + tool schema + repo context + memory + summary ]
    2. [ changing suffix: observation + task + run_id ]

    When the number of calls is N, the prefix length is P, and the suffix length is S with S far smaller than P, the theoretical input computation drops from N×(P+S) to P+N×S. The larger N is and the higher the share of P, the greater the gain. This is the demand-side basis for pushing cached-input prices so low: the provider’s marginal cost genuinely falls.

    3. Why a Small KV Cache Amplifies the Benefit

    The hit rate only determines whether compute is saved. The size of the KV cache determines whether the saved state is cheap to store and easy to schedule. KV cache footprint is roughly proportional to the number of layers, the number of attention heads, the head dimension, and the sequence length, and inversely proportional to the parallelism grouping scheme. When a model adopts a more compact representation, finer-grained quantization, or a more efficient attention variant, the cache volume for the same context length becomes significantly smaller.

    This triggers three knock-on effects. First, more sessions fit in a unit of GPU memory, cache residency lasts longer, and the hit window widens. Second, bandwidth pressure from swapping cache in and out drops, making scheduling less constrained. Third, multiple sessions that share a prefix can coexist more economically. Improved resource efficiency on the supply side is the other half of the reason prices can fall to one tenth of the launch price.

    4. How to Read a Hit-Based Pricing Model

    Understanding the billing model matters more than memorizing the discount figure. The tiered pricing approach widely used in the industry is: input tokens that miss the cache are billed at the standard rate, input tokens that hit are billed at a lower coefficient, and output is priced separately. This yields an approximate expression for the cost of a single request:

    1. cost ≈ Pin × price_miss + P × hit_rate × price_hit + Lout × price_out

    Here Pin is the total input length, hit_rate is the fraction that hits, and Lout is the output length. Three implications follow. First, a cheap hit price does not automatically mean a cheap bill; if the prefix is rewritten frequently and the hit rate is very low, total cost can actually rise. Second, output length often becomes the new cost bottleneck, so controlling output is more immediately effective than compressing input. Third, cache has a lifecycle and a capacity limit; after a long idle period it must be rebuilt, and cold-start requests get no discount.

    5. Actionable Engineering Practices

    1. Prioritize prefix stability. Put invariant content first and variable content last, and avoid embedding fields that break prefix consistency, such as timestamps, random identifiers, or auto-incrementing sequence numbers, at the start of the prompt.
    2. Version your prompt templates. A template change invalidates the cache, so bring templates under version control and roll them out gradually by version to avoid full-scale churn.
    3. Assemble context in layers. Summarize and compress long-term memory and retrieval results into the prefix, and inject large blocks of raw material into the suffix on demand, balancing hit rate against information completeness.
    4. Keep sessions sticky. Route multi-turn conversations to the same instance or the same cache domain as much as possible to reduce cross-node rebuilds.
    5. Build observability. Use logging services and monitoring alerts to separately track hit rate, the distribution of cached lengths, cache residency time, and time-to-first-token, and put hit rate on a first-class dashboard as a key metric.
    6. Attribute cost. Break the bill down by business line, scenario, and model tier, and identify and address anomalous calls with high input and low hit rates.
    1. # Pseudocode: a stable prefix assembly order
    2. prefix = render(system_prompt, tool_schema, repo_context, memory, summary) # versioned, cacheable
    3. suffix = render(observation, task, run_id) # changes every turn
    4. messages = prefix + suffix

    6. Common Misconceptions

    • Assuming a low hit price always saves money: ignoring output length and the uncached portion can lead to the opposite conclusion.
    • Assuming identical content is enough to hit: most implementations require the prefix to match byte for byte, so whitespace, line breaks, and field order all affect the result.
    • Treating cache as long-term storage: cache is a performance optimization with no durability or consistency guarantees, so business data should still live in object storage or a database.
    • Assuming a higher hit rate is always better and piling on prefixes without limit: an overly long prefix raises time-to-first-token and cost on misses, so you need to balance information density against length.

    7. Conclusion

    This round of price cuts results from both the shape of demand-side workloads and improved resource efficiency on the supply side, not from a simple price concession. For developers, the real dividend comes from reshaping applications into a “long stable prefix plus short changing suffix” form and continuously measuring hit rate and cost with observability tooling. The same methodology applies to model services on platforms such as Baidu AI Cloud: design a cacheable context structure first, then talk about cost optimization, and only then can a discount actually turn into a lower bill.