LLM Cache Hit Pricing: A Technical Breakdown of Reduced Input Costs

    This article explains a recent price adjustment in which a MaaS platform charges only 20% of the original input rate for cache hits, and what it means for developers. It covers how prefix caching works across the prefill and decode stages, why an 80% discount does not translate into an 80% smaller bill, and how to measure your actual hit rate. It also lists practical techniques for improving cache reuse, common pitfalls to avoid, and recommendations for applying these patterns on Baidu AI Cloud.

    1. Background: A Price Cut That Only Targets Cached Input

    A cloud provider’s model-as-a-service (MaaS) platform recently announced that, starting at midnight on a specified date, it will reduce certain billing items for a general-purpose LLM service in a specific region. When a request hits the cache, input-side billing is charged at 20% of the original rate; all other billing items remain unchanged. The significance of this kind of change is often underestimated. It is not a blanket price cut, but a targeted adjustment to the “reusable prefix” cost dimension. In effect, the platform is using price as a lever to encourage developers to optimize how they call the model.

    To understand this change, you first need to break down the bill for a single inference request. It typically has four parts: input charges, output charges, and optional custom or dedicated resource fees. The input side is further split into two tiers: “cache miss” and “cache hit.” This change compresses only the unit price of the latter, which means the platform is passing cost savings back to callers that can reliably reuse repeated context, while leaving the cost of the initial cache write and new content generation untouched.

    2. How Prefix Caching Saves Money

    LLM inference has two stages: prefill and decode. The prefill stage runs attention computation over all input tokens and produces the corresponding key-value cache; the decode stage then generates output autoregressively, token by token. For scenarios where long system prompts, long documents, or fixed tool descriptions reappear in every request, repeated prefilling is pure wasted compute.

    The idea behind prefix caching is to use the prefix of a token sequence as the matching criterion, keep the already-computed intermediate state, and reuse it directly when a later request has an identical prefix, performing incremental computation only for the newly added portion. This yields three benefits: lower time-to-first-token latency, higher throughput, and an input discount on billing. It is worth stressing that a hit usually requires the prefix to be byte-for-byte stable. Any timestamp, random ID, or reordering of retrieval results will invalidate the cache.

    A schematic way to organize requests looks like this (pseudocode that expresses structure only and does not represent any specific API):

    1. SYSTEM_PROMPT = load_stable_system_prompt() # Stable and unchanging, placed first
    2. TOOL_SCHEMA = load_tool_schema() # Fixed structure, placed right after
    3. def build_messages(user_query, docs):
    4. # Keep all variable content at the end to preserve a stable prefix
    5. return [
    6. {"role": "system", "content": SYSTEM_PROMPT + TOOL_SCHEMA},
    7. {"role": "user", "content": f"Docs: {docs}\nQuestion: {user_query}"},
    8. ]

    3. Cost Model: An 80% Discount Does Not Mean an 80% Smaller Bill

    Let the cache-miss input unit price be 1 and the hit unit price drop to 0.2, with a hit rate of h. The average input unit price becomes h*0.2 + (1-h)*1 = 1 - 0.8h. At a 50% hit rate, input cost falls by 40%; at an 80% hit rate, it falls by 64%. If the input/output cost structure already leans toward output, the overall reduction on the bill is diluted further.

    So to assess the real benefit of this kind of price cut, you must first measure your own hit rate distribution rather than looking at the unit price alone. A practical measurement approach is to group by business scenario and track “cached tokens / total input tokens,” while also recording the proportion of repeated prefilling caused by cache invalidation. In engineering terms, you can aggregate local counts for requests sharing the same prefix on the client side, then cross-check them against the usage details returned by the server.

    4. Key Practices for Improving Hit Rate

    1. Layer your prompts: order content as “stable - semi-stable - volatile,” with stable system settings and tool descriptions at the top and user input plus retrieved snippets at the bottom.
    2. Eliminate implicit variables: do not concatenate the current time, session ID, or random numbers into the system prompt; if time information is truly needed, place it at the end as a placeholder.
    3. Normalize retrieval results: apply a fixed sort order and truncation to recalled documents so the context order does not drift for the same question.
    4. Batch and concurrency orchestration: submit batch tasks that share a prefix together to shorten the window before the prefix is evicted, reducing jitter from cache eviction.
    5. Set retention policies sensibly: give high-frequency prefixes higher reuse priority, and keep long-tail content from occupying limited cache space.
    6. Observability first: bring hit rate, time-to-first-token latency, and cache invalidation reasons into monitoring, alerting, and logging services to form a continuous optimization loop.

    5. Common Pitfalls and Risks

    The first is placing variable content at the front, which produces “a cache that appears to exist but never hits.” The second is over-pursuing long context by stuffing an entire document store into the prompt, which both raises miss costs and amplifies latency. The third is ignoring consistency requirements, so prefixes diverge across replicas or canary environments. The fourth is treating the discount as unlimited capacity while overlooking the revenue volatility caused by cache capacity and eviction. In addition, when sensitive data is involved, evaluate which content is suitable for a reusable prefix in line with data minimization principles.

    6. Implementation Recommendations on Baidu AI Cloud

    In practice with Baidu AI Cloud’s LLM services, it is worth turning the above methods into calling standards: maintain a unified prompt template repository, normalize prefixes at the gateway layer, build a hit-rate dashboard in monitoring, alerting, and logging services, and attribute cost to specific business lines. For high-repetition scenarios such as long-document Q&A, coding assistants, and multi-turn customer service, restructuring requests often delivers more certain cost savings than switching models.