LLM API Input Caching and Hit-Rate Billing: A Practical Cost Guide

    This article explains how input cache hits are billed in large language model APIs and why they have become a central cost lever. It traces the evolution of pricing models from flat rates to time-based peak and off-peak tiers, shows how to model per-request cost as a calculable function, and outlines a three-layer architecture for request construction, observability, and scheduling. Readers will also find a risk and governance checklist covering price changes, notification and exit mechanisms, hit-rate regression protection, and capacity limits.

    1. Why Input Cache Hits Have Become the Core Cost Driver

    In LLM API billing, the tokens of a single request are usually split into three categories: input (prompt) tokens, output (completion) tokens, and cached input tokens that sit between the two. An input cache hit means the prefix of the current request exactly matches a context already cached on the platform side, so the platform does not need to repeat the full prefill computation and bills that portion at a price significantly lower than the standard input rate.

    This mechanism exists for clear engineering reasons. The compute required by Transformer-based models during inference scales strongly with prefix length, and content such as system prompts, tool definitions, long documents, and few-shot examples often stays unchanged across thousands of requests. Recomputing it every time wastes a large amount of compute. Prefix caching reuses these intermediate states, reducing both latency and cost.

    In terms of cost structure, the cache hit price is typically a fraction of the standard input price. In high-concurrency scenarios with long fixed prefixes, every 10 percentage point increase in hit rate can produce a non-linear drop in overall call cost. What developers actually need to optimize is not the unit price but the product of hit rate and unit price.

    2. Three Stages of Billing Model Evolution: From Flat Rates to a Two-Dimensional View of Price and Time

    Looking back at how industry pricing has evolved over the past two years, three stages can be abstracted, and this path has general reference value:

    1. Flat unit price stage: the entire model family uses a uniform input/output unit price, with a separate discounted price for cache hits. The advantage is simplicity; the drawback is that there is no adjustment mechanism when compute is tight during peak hours.
    2. Permanent promotion stage: after releasing a new model, a platform first offers a limited-time discount and then converts the promotional price directly into long-term pricing, with the final price at roughly a quarter of the initial launch price. The lesson for architects: do not treat a promotional price as a temporary bonus when making architecture assumptions, but as a new cost baseline.
    3. Peak and off-peak tiered pricing stage: billing is split into peak hours and off-peak hours. As an example from a platform’s published rules, peak hours are 9:00–12:00 and 14:00–18:00 Beijing time each day, and the peak unit price is higher than the off-peak unit price; the platform notifies users by email 24 hours before a price change, and users who do not accept the new price may stop the service and request a refund of their balance.

    Further refinement has appeared on top of this. One platform completed a major price adjustment in mid-August, raising the cached input price from 0.025 CNY per million tokens to 0.30 CNY per million tokens, an increase of 1100%. Less than a week later, it added a rule that Saturdays and Sundays no longer distinguish peak from off-peak and are billed uniformly at the off-peak rate. The official rationale was to let users schedule workloads more flexibly and balance compute load across the network.

    The direct implication for developers is that the cost model must include a time dimension. The same code and the same prompt, executed at different moments, can produce bills that differ by several times.

    3. Cost Estimation: Turning the Bill into a Computable Function

    It helps to abstract the cost of a single request as follows:

    1. Cost = (T_in_hit * P_hit + T_in_miss * P_in + T_out * P_out) * F_time
    2. where:
    3. T_in_hit = input tokens served from cache
    4. T_in_miss = input tokens not served from cache
    5. P_hit = cached input unit price
    6. P_in = standard input unit price
    7. P_out = output unit price
    8. F_time = time-of-day factor (peak > off-peak, possibly off-peak on weekends)

    The hit rate can be broken down further:

    1. HitRate = stable prefix length / total input length

    This yields three clear optimization directions: lengthen the stable prefix, compress the variable content, and move batch jobs into off-peak and weekend windows.

    A sketch of scheduling logic:

    1. PEAK = {(9, 12), (14, 18)} # peak hours (Beijing time)
    2. def time_factor(now, weekday):
    3. if weekday >= 5: # Saturday and Sunday billed at off-peak
    4. return 0.6
    5. hour = now.hour
    6. for s, e in PEAK:
    7. if s <= hour < e:
    8. return 1.0 # peak factor
    9. return 0.6 # off-peak factor
    10. def schedule(batch_job, now, weekday):
    11. return time_factor(now, weekday) < 1.0 # run batch jobs off-peak

    4. Architecture: Making Hit Rate an Observable Metric

    Turning hit rate from luck into an engineering metric requires three layers:

    • Request construction layer: put fixed content first. Place the system prompt, tool schema, domain knowledge, and example samples at the very front of the prompt in a constant order; move volatile fields such as timestamps, random IDs, and user nicknames to the end or remove them. A single character difference anywhere breaks the prefix match.
    • Observability layer: use logging services and monitoring alerts to collect total input tokens, cached tokens, and time-window labels for every request, build a time-series dashboard of hit rate and per-request cost, and alert when the hit rate falls below a threshold.
    • Scheduling layer: separate online interaction from offline batch processing. Put offline jobs (data cleaning, batch summarization, offline evaluation) in a queue consumed during off-peak windows; give the online path priority on latency and accept the peak premium.

    On the cloud, you can combine a container platform to host the inference gateway, a message queue to smooth out task spikes, object storage to hold reusable long-context material, and a logging and monitoring stack for cost attribution. If you use the relevant general capabilities of Baidu AI Cloud, the same general pattern applies: stabilize the cached prefix, schedule with time-of-day awareness, and make cost observable.

    5. Risk and Governance Checklist

    • Price change risk: prices and billing rules may change frequently, so subscribe to official announcement channels and keep unit prices configurable in code rather than hard-coded.
    • Notification and exit mechanisms: watch the notice window before price changes and the balance refund policy, and reserve an abstraction layer for multi-platform canary releases and fast switching.
    • Hit-rate regression protection: roll out prompt template changes gradually and compare hit rate and bills before and after, so that “optimizing the prompt” does not end up increasing cost.
    • Capacity and rate limits: moving work off-peak increases instantaneous concurrency, so pair it with queues and rate limiting to avoid turning a cost problem into an availability problem.

    6. Conclusion

    Input cache hits are not just a discount line item but a core lever in LLM cost engineering. Understanding how they are computed, mastering the time dimension of peak, off-peak, and weekend rules, and closing the loop between observable hit rate and per-request cost is what lets you make cost decisions that are predictable, auditable, and optimizable through cycles of frequent price changes.