Understanding LLM API Input Cache Hit Billing: Pricing Logic and Cost Optimization

    This article explains how input cache hit billing works for large language model APIs, covering prefix matching rules, tiered pricing, time-based rate changes, and architecture practices. It outlines how to structure prompts for higher cache reuse, build a cost model around hit and miss pricing, avoid common pitfalls, and use a deployment checklist to keep inference costs predictable.

    1. Why “Input Cache Hit” Became a Core Billing Concept

    As LLM applications move from demos to production, the cost structure of API calls has evolved from simple per-output-character billing into a multi-factor model. On the input side, tokens are now split into a “cache hit” portion and a “cache miss” portion, which is a direct result of this evolution. The reason is that many real-world requests share a highly repetitive prompt prefix, such as system role definitions, tool descriptions, fixed knowledge base passages, and few-shot examples. If this content had to go through the full attention computation every time, compute would be wasted; if the intermediate results can be reused, providers have room to offer a significantly lower price for the hit portion.

    It is important to note that a cache hit is not “free” but “cheaper.” It only applies to reusable prefix computation. Output tokens, newly added input that misses the cache, and everything after the earliest changed position that cannot be aligned are still billed at the standard rate. Understanding this is the prerequisite for building a cost model.

    2. The Technical Logic of Hit Determination

    The industry generally uses prefix matching to determine hits: starting from the beginning of the request input sequence, segments are compared against cached content, and the longest reusable prefix becomes the hit length. This leads to several conclusions with major implications for engineering practice:

    • The prefix must be stable. Any variable content placed near the front (timestamps, random identifiers, usernames, request IDs) will cause everything after it to degrade to a cache miss.
    • Hits are time-sensitive. Cache entries typically have an expiration time, and long gaps between calls will naturally reduce the hit rate.
    • Billing is tiered by hit status. Bills usually show three measurements: “hit input,” “missed input,” and “output,” rather than a single unit price.

    An illustrative way to organize a request (pseudocode, showing structure only, not any specific API):

    1. [Stable prefix] Role definition + tool definitions + domain rules + fixed examples
    2. [Semi-stable segment] Knowledge base retrieval snippets (cacheable at document granularity)
    3. [Volatile segment] User question + conversation context + timestamp

    3. Three Lessons from Price Adjustment Events

    A cloud provider adjusted its LLM API prices multiple times in 2026: in late April, it lowered the input cache hit price and extended the promotional period for new models; in late May, it announced re-pricing after the promotion ended, effective at month-end, ultimately making the discounted price permanent at about one quarter of the original launch price; at the end of June, it introduced peak and off-peak tiered pricing, designating 9:00-12:00 and 14:00-18:00 Beijing time each day as peak hours and the rest as off-peak, with higher peak unit prices; in late August, it further adjusted billing rules so that weekends are billed at the off-peak rate all day; in early September, it lowered prices for the lightweight model series.

    From an engineering perspective, three lessons emerge:

    1. Price is a variable, not a constant. The cost model must make unit prices configurable and support hot updates to avoid budget distortion from price changes.
    2. The time dimension enters the cost function. For the same call volume, the bill can differ by several times depending on whether it falls in peak or off-peak hours, or on a weekday or weekend.
    3. Cache hits are a controllable lever. Compared with waiting for price cuts, optimizing prefix structure yields more immediate and predictable benefits.

    4. Architecture Practices for Cache Hits

    • Prefix freezing: Put prompt templates under version control, route changes through a release process, and prohibit concatenating random content into the header at runtime.
    • Segmented caching: Organize long documents by a stable splitting granularity to increase the reuse probability of retrieval snippets.
    • Batching and off-peak scheduling: Schedule offline batch jobs to off-peak hours and weekends, leaving interactive requests for peak hours.
    • Observability: Log the hit length, missed length, output length, and time-period label for each request in a logging service, build a cost dashboard, and configure monitoring alerts.
    1. Cost ≈ Hit input volume × Hit unit price (time-period factor)
    2. + Missed input volume × Standard input unit price (time-period factor)
    3. + Output volume × Output unit price

    5. Common Misconceptions

    • Misconception 1: A hit means zero cost. In fact, the hit portion is still billed, just at a lower unit price.
    • Misconception 2: Placing the entire conversation history at the front. The earlier the history, the more frequently it changes, which actually lowers the hit rate.
    • Misconception 3: Ignoring rollback risk. A hotfix to a template without gradual rollout can cause the hit rate to drop sharply across all requests.
    • Misconception 4: Optimizing only unit price, not structure. Structural optimization usually delivers more stable gains than price fluctuations.

    6. Deployment Checklist

    Before going live, confirm: whether the prompt prefix is frozen and versioned; whether hit and miss measurements are logged; whether requests are tagged by time period and day type; whether budget thresholds and alerts are configured; whether template changes have gradual rollout and rollback; and whether offline jobs have been moved to off-peak and weekend windows. Once these items are complete, the cost benefits from cache hits become sustainable and verifiable.