Understanding LLM API Input Cache Hit Billing

    This article explains how input cache hit billing works in large language model APIs, why cached input is priced separately, and how hit detection, cache lifecycle, and pricing rules affect cost. It covers common misconceptions, peak and off-peak tiered pricing logic, and practical strategies such as stabilizing prefixes, layering context, scheduling workloads off-peak, building observability, and parameterizing cost models so teams can keep spending predictable when platform prices change.

    1. Why Input Cache Hits Became a Separate Billing Item

    In large language model inference, most of the input-side compute cost comes from repeatedly encoding the prefix of a prompt. When many requests share the same system prompt, tool definitions, long-document context, or few-shot examples, recomputing the key-value states for that prefix on every request wastes a significant amount of compute. To address this, the industry commonly uses prefix caching or context caching: the states of an already-computed input prefix are stored temporarily, and later requests that hit that prefix reuse them directly, substantially reducing time to first token and compute consumption.

    Because this compute cost is genuinely reduced, billing systems typically split input into two categories:

    • Input that misses the cache: billed at the standard input rate;
    • Input that hits the cache: billed at a rate clearly lower than the standard input rate, which is the input cache hit billing item.

    For developers, the significance of this billing item is that it is not a marketing gimmick; it passes part of the savings from lower-level resource reuse on to the caller. Understanding how it is measured is the first step in cost governance for LLM applications.

    2. How Billing Is Measured and Common Misconceptions

    1. Hit detection is usually based on prefix consistency

    Cache reuse generally requires the prefix to match token by token, with order, whitespace, and line breaks all participating in the match. Many cases of low hit rates stem from inserting timestamps, random IDs, or request-level variables into templates, which repeatedly break the prefix.

    2. Hits have a lifecycle

    Cache entries are affected by capacity limits, eviction policies, and expiration times. Scenarios with high concurrency but scattered prefixes often see lower hit rates than expected, while low-frequency long-prefix scenarios may repeatedly miss because entries expire.

    3. A hit does not mean free

    The hit portion is billed only at the lower rate; the missed portion and output tokens are still billed under their respective rules. Treating a hit as free is a common misjudgment.

    4. Billing items change with platform policy

    Input cache hit pricing is adjustable by the platform. Promotional prices, permanent prices, and time-of-day prices may coexist, so cost models must support parameterized configuration rather than hard-coding unit prices into business code.

    3. General Logic of Price Adjustments and Peak-Off-Peak Tiered Pricing

    The industry has already seen multiple rounds of price adjustments related to input cache hits. Their typical forms fall into three categories:

    1. A promotional price cut with an extended activity period: a lower price first attracts calls, the discounted price is then made permanent, and the final price may be only a fraction of the initial listed price;
    2. Peak-off-peak tiered pricing: the day is divided into peak and off-peak periods, with a higher unit price during peak hours to use price signals to encourage shifting demand;
    3. Rule refinement: for example, charging the off-peak price all day on weekends, or lowering prices separately for specific model families.

    The direct requirement of these mechanisms for architecture is that cost calculation must be time-aware. Example pseudocode:

    1. def unit_price(model, kind, ts, is_peak):
    2. # kind: "input_miss" / "input_cache_hit" / "output"
    3. base = PRICE_TABLE[model][kind]
    4. if kind == "input_cache_hit":
    5. return base * PEAK_FACTOR if is_peak else base
    6. return base * PEAK_FACTOR if is_peak else base
    7. def is_peak(ts):
    8. # Peak hours and weekend rules must be configurable to avoid hard-coding
    9. return CALENDAR_RULES.is_peak(ts)

    At the same time, platforms usually promise to notify users in advance by email or other means before a price change, and allow users to stop service and request a refund of their balance if they do not accept the new price. In engineering terms, price change notifications should be built into the change management process rather than investigated only after an anomaly appears on a bill.

    4. Cost Optimization Practices for Developers

    1. Stabilize the prefix to maximize hits

    Place the system prompt, tool definitions, output format constraints, and fixed examples at the front and keep them unchanged; put user input and session variables afterward. Avoid concatenating the current time, random numbers, or request IDs into the prefix.

    2. Control prefix length and reuse granularity

    The longer the prefix, the higher the cost of a single miss. Organize context in layers such as stable, semi-stable, and dynamic, keeping the stable layer as long and unchanged as possible and the dynamic layer as short as possible.

    3. Coordinate batching and concurrency with peak and off-peak periods

    Schedule deferrable workloads such as offline batch processing, evaluation tasks, and log summarization to off-peak periods; keep online interactive paths in peak periods, trading cost reductions for the price lever.

    4. Build observability

    For each call, record the model, hit flag, input and output token counts, timestamp, and converted cost. Use monitoring dashboards and alerts to watch hit rate and per-request cost trends; a sudden drop in hit rate often means a template was changed or the cache is being evicted frequently.

    5. Parameterize the cost calculation sheet

    Make unit prices, peak-off-peak factors, and promotional validity periods configuration items, and retain historical versions to make it easier to trace billing discrepancies.

    5. Recommendations for Platform Providers and Architects

    • Billing item names and measurement definitions should be stable, and price changes should be announced in advance with a migration window;
    • Peak-off-peak rules should be configurable and queryable to avoid hard-coding on the user side;
    • Observability metrics such as cache hit rate and eviction reasons should be opened up appropriately to help users optimize;
    • When a promotional price becomes a permanent price, keep the price curve predictable to reduce uncertainty in enterprise procurement and budget planning.

    6. Summary

    Input cache hit billing is essentially a billing design that makes the benefits of compute reuse explicit. As long as developers stabilize prefixes, organize context in layers, schedule workloads off-peak, parameterize costs, and build observability, they can keep costs under control even when pricing strategies change repeatedly. In the face of peak-off-peak pricing and promotional changes, the safest approach is not to chase the lowest price at a given moment, but to turn the cost model into a configurable, rollback-capable, and auditable engineering asset.