Understanding LLM API Input Cache Hit Billing

    This article breaks down how input cache hit billing works for large language model APIs and why it matters for cost management. It explains the prefix-matching principle behind cache reuse, traces how pricing rules evolved toward time-based peak and off-peak tiers, and outlines practical optimization techniques such as prompt layering, off-peak scheduling, hit-rate observability, configuration-driven pricing, and vendor-neutral gateways. It also highlights common mistakes that reduce cache efficiency and offers guidance for keeping API bills predictable as pricing rules continue to change.

    1. Why Input Cache Hits Deserve Separate Attention

    In the billing model of large model APIs, the input side is usually split into two categories: uncached input tokens and input tokens that hit the cache. The former requires the model to perform a full forward pass, while the latter can reuse intermediate representations that were already computed, so its unit price is significantly lower. The source material describes a series of price and rule changes that a cloud vendor rolled out around this billing item in 2026: reducing input cache hit prices across the entire API lineup, extending promotional periods, making the discounted price permanent, introducing time-based tiered pricing for peak and off-peak hours, and applying the off-peak price all day on weekends.

    For developers, the significance is not any single price cut, but two points. First, cache hits have shifted from a “performance optimization item” to a “cost structure item.” Second, billing rules have begun to couple with the time dimension, so bills are no longer determined by token count alone.

    2. How Cache Hits Are Determined: Prefix Consistency

    Cache reuse depends on an exact prefix match. The common industry approach is to chunk and hash-match the token sequence by prefix. The matched length is typically a multiple of a fixed number of tokens, and only fully identical prefix blocks can be reused.

    The following is an illustrative example of the matching logic:

    1. def estimate_cached_prefix(system_prompt, history, block=64):
    2. tokens = tokenize(system_prompt + history)
    3. full_blocks = len(tokens) // block
    4. # Only full blocks can be reused; the trailing partial block is billed as uncached
    5. return full_blocks * block, len(tokens) - full_blocks * block

    This leads to a few firm conclusions. Changing even a single character in the system prompt causes everything after it to become uncached. Placing volatile information (timestamps, random IDs, usernames) at the beginning of the prompt is the most common “hit-rate killer.” In multi-turn conversations, putting stable content first and variable content last is the only way to maximize the matched length.

    3. The Evolution of Billing Strategy

    Abstracting the timeline from the source material reveals a clear progression.

    • Stage 1, lower unit prices: The input cache hit price was reduced and applied uniformly across the entire API lineup, indicating that this billing item evolved from a marginal item into a core cost item.
    • Stage 2, promotions becoming standard: The promotion deadline was extended, and after the promotion ended, the new pricing was formally implemented. The final discounted price was about one quarter of the original launch price, meaning the “temporary discount became permanent.”
    • Stage 3, time-based pricing: A peak and off-peak tiered strategy was introduced. Peak hours are 9:00–12:00 and 14:00–18:00 daily, with a higher peak unit price than off-peak. Users are notified by email 24 hours before a price change, and those who disagree can stop the service and request a balance refund.
    • Stage 4, rule refinement: Weekends no longer distinguish between peak and off-peak, and the off-peak price applies all day. Less than a week earlier, the platform had completed a general price increase, in which the cache hit input price was adjusted starting from 0.025 yuan per million tokens.

    The direct implication of this path for architecture design is that the cost model must be parameterized. Pricing and time-window rules should be read as configuration rather than hard-coded in a budget sheet.

    4. Actionable Cost Optimization Practices

    1) Prompt layering. Fix the unchanging role settings, tool descriptions, and output format constraints as a prefix, and append session variables and retrieval results as a suffix. The more stable the prefix, the longer the match.

    2) Batch and off-peak scheduling. Place offline batch processing, log summarization, batch labeling, and other tasks without real-time requirements into off-peak and weekend windows to take advantage of lower prices and the all-day off-peak rule.

    3) Hit-rate observability. Add instrumentation on the application side to record the input tokens, cached tokens, and request time of each request, forming time-series metrics of hit rate and per-request cost, and use logging services and monitoring alerts to locate abnormal fluctuations.

    4) Budget guardrails. Manage unit prices and time-window tables with a configuration center, and reference only configuration items in code:

    1. pricing:
    2. cache_hit_input: 0.025 # yuan per million tokens, example placeholder
    3. peak_windows: ["09:00-12:00", "14:00-18:00"]
    4. weekend_all_offpeak: true

    5) Vendor neutrality. Wrap calls through a unified gateway, consolidating retries, fallbacks, caching strategies, and billing definitions in one layer to avoid business changes triggered by rule updates.

    5. Common Mistakes

    The first is assuming that “enabling the cache always saves money.” If requests are scattered and the prefix differs each time, the hit rate may be close to zero. The second is placing dynamic content first, which disables the entire cache chain. The third is ignoring the price-change notification mechanism and failing to evaluate alternatives within the 24-hour window. The fourth is focusing only on unit price while ignoring the multiplier effect of matched length and time-window distribution on total cost.

    6. Conclusion

    The adjustments to input cache hit prices and peak/off-peak rules essentially move large model inference costs from a “black-box unit price” to a stage of “engineered governance.” The capabilities developers truly need to build are a stable prefix structure, observable hit-rate metrics, parameterized pricing configuration, and off-peak scheduling. If an application runs in a cloud environment such as Baidu AI Cloud that offers general capabilities like container platforms, message queues, logging services, and monitoring alerts, these strategies can be consolidated into a platform-level cost governance process, keeping bills predictable even as pricing rules continue to change.