Why Input Cache Misses Happen and How to Cut LLM API Costs

    Input cache miss is billed separately from cache hit in LLM APIs. This article explains how KV cache reuse works in prefill, what causes misses, how time-of-day pricing changes the cost of miss tokens, and engineering practices to raise hit rate without changing model quality.

    1. Positioning: a billing line item alongside cache hit

    In usage-based LLM APIs, input is no longer a single “input tokens” bucket. It is split into two independent items: input cache hit and input cache miss (also called regular input).

    The difference comes from the prefill stage. For a Transformer, each input token needs Key/Value tensors stored as KV cache. If the request prefix matches a previous request, the server can reuse loaded KV cache and skip repeated prefill. The part that cannot be reused must run full prefill, using full compute and memory bandwidth, and is billed at the standard input rate.

    In short: hit is a lookup; miss is a recompute. Hits are cheaper; misses are expensive. That gap shows up on the bill.

    2. When a request is counted as a miss

    A miss typically falls into these cases:

    1. Prefix never existed: first request, new session, or any byte-level change in the prompt template.
    2. TTL expired: cache entries have a lifetime and drop after idle time.
    3. Eviction: GPU memory is scarce; semi-active entries may be dropped (e.g. LRU).
    4. Routing drift: the request lands on an instance that does not hold that prefix cache.
    5. Unstable prefix: timestamps, random IDs, or nicknames at the very front change the prefix hash for everything after—the most common and easy-to-miss “silent full miss.”

    Hit and miss often coexist in one request. A stable prefix is billed as hit; the new suffix as miss. Together they make the full input charge.

    1. Input cost for this request
    2. = hit tokens × hit unit price
    3. + miss tokens × standard input unit price

    In multi-turn chat, history can stay cached so later turns pay full price only on the increment; a poorly designed prefix turns every turn into a full miss.

    3. Pricing structure: time-of-day as another variable

    Billing is not only hit vs. miss. Some platforms also apply peak/off-peak rates. A representative 2026 change: after publishing API rates for a new model generation, peak vs. idle miss prices were introduced; later, Saturday and Sunday were billed at off-peak all day, with weekday peak and idle windows defined. Some invoices further split “input (cache miss)” into idle and busy columns.

    Implication: miss token price is a function of time, not a constant. Batch jobs that can wait (log summarization, document extraction, offline eval) should run in off-peak windows; online traffic trades latency against cost.

    Observability is also reaching end users. Some platforms show per-turn usage split into cache hit, cache miss, and output. That three-way split is the main lever for cost anomalies: if miss share stays high, the issue is almost always prefix stability or cache lifetime, not the model list price.

    4. Engineering practices to raise hit rate

    4.1 Prefixes must be byte-stable

    Order prompt parts from least to most volatile: system instructions → tool/function defs → few-shot examples → fixed knowledge → session history → current user turn. Put volatile fields (time, random values, session IDs) last.

    1. def build_prompt(system: str, tools: str, history: list, query: str, ts: str):
    2. # Stable prefix first: system + tools + history
    3. stable = f"{system}\n{tools}\n{history}"
    4. # Volatile content last: this-turn query and timestamp
    5. return stable, f"\n[ts={ts}]\n{query}"

    4.2 Control context length and redundancy

    Pasting the same long document repeatedly or stacking untrimmed history inflates miss volume. Summarize history; dedupe and rerank retrieved chunks.

    4.3 Session stickiness and warmup

    Keep a session on the same instance to reduce routing drift. For hot fixed prefixes, send a warmup request in a quiet period and keep enough traffic within TTL.

    4.4 Batch merge and off-peak scheduling

    Merge same-prefix small requests so one miss is amortized across samples. Queue offline work for off-peak windows to get a lower miss unit price.

    4.5 Close the cost observability loop

    Collect per-request hit tokens, miss tokens, output tokens, and time-band labels. Track hit rate and per-turn cost; alert on thresholds.

    1. def cost(hit, miss, out, p_hit, p_miss, p_out):
    2. return hit * p_hit + miss * p_miss + out * p_out
    3. # Hit-rate monitor: below threshold, inspect prefix stability
    4. hit_rate = hit / max(hit + miss, 1)
    5. assert hit_rate > 0.8, "Prefix may be unstable or cache expired"

    5. Common misconceptions

    • “Cache hit is free”: hit is cheaper, not free; it is still billed per token.
    • “Same content always hits”: TTL expiry and eviction also cause misses.
    • Timestamps at the start of the prompt: a classic anti-pattern that turns high-hit traffic into full misses.
    • Looking only at the total bill: without hit / miss / output split, you cannot optimize.

    6. Summary

    Input cache miss is the billing mapping of prefill that was not reused. Know the miss conditions, keep stable prefixes first and volatile content last, and combine time-of-day scheduling with three-way cost metrics. You can keep long chats and batch inference input cost in a reasonable range without sacrificing quality. In typical cloud setups—including practices on platforms such as Baidu AI Cloud—logging, monitoring/alerting, and container platforms often form the infrastructure for that cost-control loop.