Cache-Hit Billing for Cloud LLM Services Explained

    Cloud model-as-a-service billing usually charges input and output tokens separately. This article explains how prefix cache-hit pricing discounts repeated input prefixes, why stable prompt order drives hit rate, and how to organize requests so input cost falls without changing application logic.

    1. Background: The Basic Structure of MaaS Billing

    When large models are offered as a service, callers usually do not run their own inference clusters. They pay by usage through a shared API. In this model-as-a-service (MaaS) pattern, the industry commonly uses the token as the unit of measure and prices a request in two parts: input and output. Input covers the prompt and context; output covers what the model generates. The two rates often differ, and output is usually more expensive.

    As context windows grow, a single request can carry tens of thousands of input tokens or more. Many requests share the same prefix, such as a fixed system prompt, a long document, a code snippet, or retrieved knowledge. Charging the full input every time makes cost rise quickly. Cache-hit billing is designed to ease that problem.

    2. How Cache-Hit Billing Works

    Cache-hit billing discounts input prefixes that repeat. The flow can be summarized as follows:

    1. When a request arrives, the service computes a fingerprint of the input prefix, usually from a content hash.
    2. If that prefix is already in cache and has not expired, the request is a cache hit. The matched portion is billed at a discounted rate.
    3. If it is not cached, the request is a cache miss. That portion is billed at the standard input rate, and the result is written to cache for later reuse.

    Input cost for one request is therefore often two parts:

    1. Total input cost = hit prefix tokens × hit unit price + miss tokens × standard unit price

    A common industry practice is to bill the hit portion at a lower fraction of the standard price, while leaving the output price and other charges unchanged. Discount ratios, cache lifetime, and the minimum cacheable length are defined by each provider. Callers should follow the official documentation. This article does not assume any fixed numbers.

    3. Why a Stable Prefix Is the Key to Hit Rate

    Cache matching is usually based on the prefix, not on arbitrary spans. The request hits only when the leading content matches byte for byte. If any character in the prefix changes, everything after it is treated as a miss. That leads to a simple rule:

    Put stable content first and changing content last.

    System prompts, tool definitions, and fixed background knowledge belong at the head of the context. The current user input, timestamps, and random IDs belong at the end. The contrast below shows the difference:

    1. Recommended order
    2. [System prompt (fixed)]
    3. [Tool / function definitions (fixed)]
    4. [Knowledge base / long documents (changes infrequently)]
    5. [Conversation history (appended over time)]
    6. [Current user input (changes every time)]
    7. Not recommended
    8. [Current user input]
    9. [System prompt]
    10. ... the prefix changes often, so hits are rare

    4. Practical Ways to Raise Cache Hit Rate

    • Keep the system prompt stable. Freeze role instructions and output-format constraints. Do not embed volatile fields such as timestamps inside them.
    • Align batch structure. In batch workloads, give every request in a batch the same header and vary only the tail.
    • Respect cache expiry. Learn the service’s expiration policy and send similar requests while the cache is still valid, instead of rebuilding it often.
    • Avoid meaningless variation. Do not add random ordering, changing whitespace, or dynamically concatenated debug text to a fixed prefix.
    • Split long context. Separate rarely changing background from frequently changing content so the reusable prefix stays as long as possible.

    5. How This Affects Cost

    Consider a high-volume request type with a long input and a highly repeated prefix. After cache-hit discounts are enabled, the unit price of the hit portion drops sharply. Because input cost is split into “hit + miss,” total input cost falls as the hit rate rises. The higher the hit rate and the longer the hit prefix, the larger the savings. If a poorly ordered prefix causes frequent misses, the cache mechanism yields almost no benefit and may add only a very small fixed cost from fingerprinting.

    6. Caveats and Summary

    1. Follow the provider’s rules. Discount ratios, minimum cache length, and expiry time differ by service. Check the billing description in the official documentation for the platform you use.
    2. A hit is not free. The matched portion is still billed, only at a lower unit price.
    3. Correctness comes first. Sacrificing prompt clarity just to raise hit rate is a poor trade. Optimize structure only after quality is preserved.
    4. Measure it. Record the input-token breakdown and hit status of each request, and use monitoring and logs to judge whether the change helps.

    Overall, cache-hit billing trades structure for cost. If developers keep prefixes stable, put dynamic content at the end, and reuse fixed content in batch and long-context workloads, they can lower input spend on large-model calls without changing business logic.