LLM API Cache Hit Pricing Breakdown: How Prefix Caching Cuts Input Costs

    This article explains why a cloud provider's decision to cut the input price for cache hits to 20% of the original rate matters more as a structural signal than as a discount. It breaks down the input-side cost of LLM API calls, explains how prefix caching reuses computed KV states, and shows how prompt design determines hit rates. Readers will find the core cost formula, four reusable prompt scenarios, common anti-patterns, measurement guidance, and a practical checklist for turning cache discounts into real savings.

    1. Background and the Technical Abstraction

    A cloud provider’s model-as-a-service (MaaS) platform recently announced that, starting November 23, 2026 at 00:00 (Beijing time), it will lower the price of a large model service deployed in a single region. The adjustment is narrow: the input price for the cache-hit portion drops to 20% of the original price, while all other billing items stay unchanged.

    The real information here is not the price cut itself but its structure. Only the cached input price moves; uncached input, output, and other charges are untouched. In other words, the platform is pointing its cost-optimization effort squarely at prefix reuse in the inference path. For developers, three general questions matter:

    1. What components make up the input-side cost of an LLM API?
    2. Why can a cache hit be priced far below an uncached request?
    3. How can application-side engineering reliably raise the hit rate so the discount actually shows up on the bill?

    One caveat: platforms differ in cache granularity, minimum prefix length, cache time-to-live (TTL), and whether caches are shared across requests. This article covers only the general mechanisms and engineering practices widely accepted in the industry, not the proprietary parameters of any specific product.

    2. The Cost Structure of LLM Inference: Why the Input Side Is Worth Optimizing

    A typical LLM call is billed in two parts: input (prompt) tokens and output (completion) tokens. Some scenarios add long-context surcharges, batch inference discounts, or fine-tuned inference rates. Output tokens usually cost more per token than input tokens, but the input side has a distinct property: it is high-volume and highly repetitive. In agents, RAG, coding assistants, and customer service bots, system prompts, tool definitions, knowledge base chunks, and conversation history reappear across hundreds or thousands of requests.

    That creates obvious waste. Even when this content is numerically identical, a traditional implementation recomputes full attention over it on every request. Inference cost therefore scales roughly with “number of requests × prompt length” rather than with the amount of genuinely new information.

    3. How Prompt Caching Works (General View)

    The core idea of prefix caching is to store the computed key-value (KV) state of a request, keyed by the token sequence prefix. When a later request shares an identical prefix, that intermediate state is reused and only the new suffix is computed.

    Two conditions must hold:

    • Deterministic prefix: the prefix token sequence must match byte for byte. Inserting a timestamp, random ID, or username breaks the match.
    • Order sensitivity: matching is prefix-based, so any variable content inserted in the middle prevents everything after it from hitting.

    The first engineering principle follows directly: put stable content first and volatile content last.

    An illustrative prompt layout:

    1. [Stable] System role definition + output format constraints + tool/function schema + long domain knowledge
    2. [Semi-stable] Conversation summary (updated in batches per turn group, not rewritten every turn)
    3. [Volatile] Current user input + timestamp + request trace ID

    Matching call-side pseudocode, kept vendor-neutral:

    1. def build_prompt(system_block, knowledge_block, summary, user_input, trace_id):
    2. # Keep the stable segment first so the prefix stays byte-identical
    3. stable = system_block + "\n" + knowledge_block
    4. volatile = f"\n[trace={trace_id}]\nUser: {user_input}"
    5. return stable, volatile
    6. # The first request establishes the cache; later requests reuse the same stable prefix
    7. messages = [
    8. {"role": "system", "content": stable},
    9. {"role": "user", "content": volatile},
    10. ]
    11. resp = client.chat.completions.create(model=MODEL, messages=messages)
    12. print(resp.usage) # Look for cache-hit fields here (if the platform exposes them)

    4. Where Hit Rates Come From: Four Reusable Scenarios

    1. Fixed system prompts and tool definitions. In agent scenarios, tool schemas often run to thousands of tokens and stay unchanged for a long time, making them the highest-quality cacheable asset.
    2. Long-document and knowledge base Q&A. When the same document is queried across multiple turns, the document body is reused as a prefix, and the benefit scales linearly with document length.
    3. Multi-turn conversation history. Appending prior turns after a stable prefix lets each turn compute only the new content.
    4. Batch offline jobs. When one template processes many samples, the template portion approaches a 100% hit rate.

    Counter-examples matter just as much: prepending the current time, a random request number, or a user nickname to the prompt drives the hit rate toward zero; reordering or re-summarizing knowledge base chunks every turn continuously breaks prefix consistency.

    5. A Framework for Quantifying Cost and Benefit

    Let a single request have L input tokens, of which a cacheable prefix is h tokens, and let the cache-hit input price be r times the original (r = 0.2 in this case). Input-side cost is approximately:

    1. Cost ≈ (h × r + (L - h) × 1) × P_in × N

    where P_in is the uncached input price and N is the number of requests. Two levers are visible: raising the h/L ratio and lowering r. A vendor adjusting r is an external windfall, while h/L is entirely determined by application design. So under the same price cut, a well-designed prefix strategy can yield several times the savings of a poorly designed one.

    A recommended measurement approach: instrument the gateway to log input tokens, hit tokens, hit ratio, and cache invalidation counts per request, then build a “cache hit rate vs. cost per request” dashboard broken down by business line. Pair it with alerting to attribute sudden hit-rate drops, a common cause being a prompt template release.

    6. Implementation Checklist

    • Prompt layering: use the stable / semi-stable / volatile three-part structure and never inject variables at the head.
    • Template versioning: roll out template changes gradually to avoid invalidating the entire cache at once.
    • Serialization stability: normalize JSON field order, float formatting, and whitespace.
    • TTL friendliness: schedule batch jobs together to shorten idle gaps for the stable prefix.
    • Observability: log hit rate, invalidation reasons, and cache-related usage fields, and feed them into monitoring and alerts.
    • Cost attribution: split bills by business and environment to verify the price cut actually reaches unit cost.
    • Fallback plan: revert to normal calls automatically when the cache is unavailable, prioritizing availability.

    7. Conclusion

    This structural cut, applied only to the cached input price, essentially makes “repeated computation” visible and prices it. For engineering teams, the lasting gain does not come from any single price adjustment but from treating prompts as a cacheable asset to be governed: stable prefixing, template versioning, and observable hit rates. Get those three right, and unit cost per request keeps room to decline no matter how prices move.