Large Model API Input Cache Hit Billing Explained

    This article breaks down how input cache hit billing works for large model APIs and why it has become a major cost variable. It explains the three-part metering structure of cached input, uncached input, and output, traces the shift from flat pricing to cache discounts and peak/off-peak tiers, and covers the prefix-matching principles behind cache hits along with common mistakes. Readers will find practical optimization methods, observability metrics, architecture guidance, and a launch checklist for keeping API bills predictable as call volume grows.

    1. Why Input Cache Hits Have Become a Key Billing Variable

    In large-scale large model API usage, the input side (the prompt) often accounts for the majority of token consumption. System prompts, tool definitions, long document context, and few-shot examples are highly repetitive across requests. If every request were billed at the full “cache miss” rate, costs would grow linearly or even faster as call volume increases. The purpose of the input cache hit billing item is to move reusable input portions from full price to a discounted price, giving requests that repeat the same prefix a significant cost advantage.

    From a billing model perspective, a request is typically split into three metered categories: cached input, uncached input, and output. Each has a different unit price and measurement basis, so the bill is no longer determined by “total tokens × a single unit price” but by this three-part structure. Understanding this is the prerequisite for all subsequent optimization work.

    It is worth emphasizing that a cache hit is not “free” but “cheaper.” At the same time, the hit rate is not random system behavior; it is an engineering outcome strongly tied to how requests are constructed. Treating the hit rate as a designable metric rather than an external condition left to chance is the dividing line in cost governance.

    2. Billing Evolution: From Flat Unit Price to Peak/Off-Peak Tiers

    Pricing practices in the industry have roughly gone through three stages, and understanding this evolution helps anticipate future billing changes.

    The first stage is flat unit pricing: all input tokens cost the same. Bills are predictable but lack flexibility, and high-frequency callers with repetitive requests bear unreasonable costs.

    The second stage introduces cache hit discounts: input is split into hit and miss tiers, encouraging callers to actively reuse prefixes. The bill begins to show “structural differences,” where the same business request volume can differ by several times depending on how calls are made.

    The third stage is peak/off-peak tiered pricing: time is divided into peak hours (for example, several hours each in the morning and afternoon, based on Beijing time) and off-peak hours, with peak unit prices higher than off-peak. Platforms usually notify users in advance by email or other means before a price change, and users who do not accept the new price can stop the service and request a balance refund. The goal of such mechanisms is to “shave peaks and fill valleys” in compute demand along the time dimension and improve overall resource utilization.

    Furthermore, some platforms charge a uniform off-peak rate all day on weekends, no longer distinguishing peak from off-peak. Such rules are often introduced shortly after a comprehensive price adjustment, indicating that billing strategies are in a period of frequent iteration. The direct takeaway for callers is that the billing model itself is a variable, and the architecture must reserve the ability to make “billing strategy configurable” rather than hard-coding unit price and time-window assumptions into business logic.

    3. How Hit Determination Works and Common Misconceptions

    The widely accepted implementation approach is based on matching and reusing the input prefix: the system computes a fingerprint of the prefix portion of the request input, and if it matches cached content, it reuses the intermediate computation results and only performs full computation on the newly added portion. This leads to several engineering conclusions:

    1. Prefix stability determines the hit rate. The more stable the content at the very front of the request, the more likely it is to be hit; putting timestamps, random IDs, or user nicknames at the front will directly break hits.
    2. Hits typically exhibit a “longest common prefix” characteristic. Once content at a certain position changes, everything after it degrades to a miss.
    3. Caches have lifecycle and capacity constraints. Long periods without calls, overly large content volume, or platform-side policy changes can all reduce the hit rate.
    4. A hit is a probabilistic engineering optimization and should not be relied upon for correctness. Business logic must not assume that “a cache always exists.”

    Common misconceptions include: concatenating dynamic content at the beginning of the system prompt; re-concatenating fragments in a different order each time in long-document scenarios; using multiple semantically identical but differently worded prompt templates, causing inconsistent fingerprints; and evaluating costs with randomized inputs during load testing, leading to non-reproducible conclusions.

    4. Actionable Cost Optimization Methods

    4.1 Prompt Layering and a Stable Prefix

    Divide the input into a “stable layer—semi-stable layer—dynamic layer” and keep the order fixed:

    1. [Stable layer] Role definition, output format constraints, tool definitions, safety policies
    2. [Semi-stable layer] Domain knowledge, long document context, few-shot examples
    3. [Dynamic layer] User question, conversation context, timestamps and random identifiers

    Once the stable layer content is determined, it should be version-controlled to avoid a hit-rate collapse caused by “casually changing a word.”

    4.2 Standardizing Templates and Fragments

    Use a single template for the same semantics, and order fragments using explicit constants rather than set iteration order. Illustrative code:

    1. def build_prompt(system_v3, docs, user_query):
    2. # Fixed order, stable content first
    3. parts = [system_v3]
    4. parts.extend(sorted(docs, key=lambda d: d.doc_id)) # Explicit sorting to avoid order jitter
    5. parts.append(user_query)
    6. return "\n\n".join(parts)

    4.3 Batching and Merging Strategies

    Merging multiple small requests into a batch request that shares a prefix can significantly increase the hit ratio; however, you must weigh latency and failure-retry costs. It is recommended to enable this first for latency-insensitive offline tasks.

    4.4 Off-Peak Scheduling

    Under peak/off-peak pricing, scheduling offline batch processing, evaluation, and data cleaning tasks to off-peak hours is a discount obtainable without changing business logic. In engineering terms, this can be achieved through delayed delivery in a task queue:

    1. # Pseudocode: deliver offline tasks with a delay to off-peak hours
    2. def schedule_offpeak(task, peak_hours=((9,12),(14,18))):
    3. if in_peak_hours(now(), peak_hours):
    4. enqueue_delayed(task, delay=seconds_until_next_offpeak())
    5. else:
    6. enqueue(task)

    4.5 Observability and Cost Attribution

    You must build monitoring and alerting around the three usage dimensions of hit/miss/output, rather than only looking at total tokens. Recommended core metrics:

    • Cache hit rate = cached input / total input
    • Average cost per request, and cost per unit of business output (such as cost per thousand Q&A interactions)
    • Month-over-month change in the proportion of uncached input (a sudden spike often means a template was modified)
    • Proportion of calls during peak hours

    Associating metrics with log services, monitoring alerts, and raw request samples in object storage makes it quick to identify which template change caused the hit rate to drop.

    5. Robustness Design at the Architecture Level

    Since billing rules will keep evolving (extended promotions, permanent discount prices, adjusted peak/off-peak divisions, uniform weekend off-peak pricing, etc.), the architecture should do three things:

    1. Externalize the billing strategy. Put unit prices, time-window tables, and discount rules into a configuration center that supports hot updates and canary releases, avoiding the need to release a new version just to change prices.
    2. Cost budgets and circuit breaking. Set budget thresholds per project; when exceeded, degrade to a smaller parameter scale or lower call frequency, while retaining queued retries.
    3. Keep multiple options switchable. Within what the business allows, retain implementation paths with different parameter scales and different context organizations, so you can choose the more cost-effective combination under a new billing strategy.

    Also pay attention to compliance and experience boundaries: off-peak scheduling should not sacrifice the response latency of critical paths; cache reuse should not cause cross-user information leakage, and stable prefixes must never contain any user private data.

    6. Launch Checklist

    • Is the stable prefix version-controlled, and do changes go through review?
    • Are all dynamic fields pushed to the end of the input?
    • Are the hit rate and miss proportion included in monitoring with alerts configured?
    • Are offline tasks scheduled to off-peak hours?
    • Are billing parameters externalized as configuration, supporting an advance-notification and balance-refund process?
    • Have you run a failure drill for “a minor template tweak causing a sudden hit-rate drop”?

    7. Conclusion

    Input cache hits essentially shift cost optimization from “pushing down unit price” to “changing structure.” As billing moves from flat unit pricing toward cache discounts and peak/off-peak tiers, the competitiveness of callers depends on the maturity of their prompt engineering, scheduling strategy, and observability systems. Only by treating the hit rate as a first-class metric and continuously governing it can you keep bills predictable and controllable as call volume expands.