LLM Token Billing and Caching: A Technical Breakdown

    This article breaks down how large language model usage is metered and billed, covering why tokens are the unit of measurement, how input and output are priced separately, and how prefix caching turns repeated computation into discounted input. It also explains peak and off-peak pricing, rate and quota limits, and a practical cost-optimization checklist for developers. All prices are illustrative; refer to your platform's official billing page for actual rates.

    1. Start With a Simple Greeting

    In an LLM chat service, even the most ordinary greeting can be converted into an amount precise to six decimal places. Using off-peak rates for a rough estimate: about sixty input tokens and twenty output tokens, with input at one unit per million tokens and output at four units per million, a single exchange costs roughly 0.00015 units — less than a thousandth.

    The number itself does not matter. What matters is what it reveals: natural language interaction, once considered hard to measure uniformly, has been fully decomposed into measurable, priceable, and auditable engineering metrics. For developers and enterprise users, this means inference cost has shifted from “review the total at month end” to “attribute cost to every single turn.”

    Note that this article does not discuss any specific vendor’s pricing. All prices here are illustrative values for explanation only; actual prices should follow the official billing page of the platform you use.

    2. Tokens: Why They Are the Unit of Measurement

    A token is the smallest unit of text an LLM processes. It is neither a character nor a word. It comes from how a tokenizer splits text, and the common patterns are:

    • In English, one token roughly corresponds to three or four characters, or a fraction of a word;
    • In Chinese, one character usually consumes one to two tokens, and punctuation and whitespace are counted as well;
    • Structured or high-entropy text such as code, JSON, regular expressions, and Base64 shows a markedly higher token density.

    An illustrative way to count (pseudocode, expressing the idea only):

    1. usage = response.usage
    2. total = usage.prompt_tokens + usage.completion_tokens
    3. print(f"Tokens used this turn: {total}")
    4. print(f"Input: {usage.prompt_tokens}, Output: {usage.completion_tokens}")

    The first engineering fact to internalize is this: input and output are priced separately, and the output unit price is usually significantly higher than the input one. The reason is that generation is autoregressive; decoding token by token cannot be parallelized as fully as prefill, so compute utilization is lower. As a result, the marginal cost of “having the model say one more sentence” is often higher than that of “having the model read one more paragraph.”

    3. The Three Components of a Single Turn’s Bill

    A mature metering scheme usually splits one request into three items:

    1. Input (cache hit): tokens that hit a prefix cache and can directly reuse computed results;
    2. Input (cache miss): tokens that must fully participate in this turn’s prefill computation;
    3. Output: tokens newly generated by the model.

    These three are separated because their compute costs are entirely different. Understanding this is what explains why “the same question can differ in price by tens of times.”

    4. Prefix Caching: Turning Repeated Computation Into a Discountable Asset

    4.1 How It Works

    In a long conversation, each time the user sends a new message, the model usually has to process it together with all prior history. But the history portion was already computed in the previous turn or earlier, and its results can be stored temporarily to form a prefix cache (also commonly called KV cache reuse or context caching). When the prefix of a new request matches the cache exactly, those tokens need no recomputation and are reused directly.

    A hit depends on strict prefix identity: it counts as a hit only if the tokens match position by position starting from the first token of the sequence. If any part of the system prompt, tool definitions, retrieved snippets, or history messages changes, everything from the point of change onward degrades to a miss.

    4.2 Price Effect

    Because what is saved is real prefill compute, cached input usually enjoys a large discount. With illustrative prices: a cache-miss input costs one unit per million tokens during off-peak hours, while a hit costs only 0.02 units — one fiftieth of the original price.

    4.3 Engineering Implications

    • Put stable, unchanging content (system instructions, tool schemas, long documents, knowledge snippets) at the front of the context;
    • Put fields that change over time (timestamps, usernames, random IDs, retrieval results) at the end;
    • Avoid rewriting the system prompt mid-session, or the entire cache is invalidated;
    • Reuse the same session context across turns rather than rebuilding it each turn.

    A typical stable-prefix layout:

    1. [System instructions - constant]
    2. [Tool/function definitions - constant]
    3. [Long document or knowledge base snippet - constant]
    4. --------------------------------
    5. [Conversation history - grows by appending]
    6. [This turn's retrieval results/timestamp - variable]
    7. [User input this turn - variable]

    5. Time-Based Pricing: Bringing “When You Chat” Into the Cost Function

    The original text mentions that peak-hour prices double, which reflects the tidal nature of compute supply. During off-peak hours (usually at night or regional lows), resource utilization is low, so prices drop to stimulate demand; during peak hours, resources are tight, so prices rise to suppress non-critical workloads.

    Cost-sensitive businesses can design scheduling strategies accordingly:

    • Move all batch tasks (offline summarization, bulk labeling, data cleaning, report generation) down to off-peak hours;
    • Keep the online interaction path in peak hours, but control unit price by shortening context and capping maximum output length;
    • Tag tasks as “deferrable” and let a queue execute them opportunistically within price windows.

    6. Limits and Quotas: The Inevitable Convergence of Free Supply

    When call volume grows while compute supply is tight, providers usually resort to three measures: rate limiting (requests or tokens per minute), quota limiting (total per day or per cycle), and priority tiering (paid requests scheduled first).

    A notable reversal in user behavior: from “can’t be driven away” to actively asking about paid plans. This shows that once free quotas begin to affect availability, what users are really buying is not tokens but certainty — a certain response speed, a certain context length, a certain concurrency level. In product design, this means quotas and billing must be presented in an observable and predictable way, rather than making users trial-and-error in production.

    7. A Cost-Optimization Checklist for Developers

    1. Compress input: deduplicate history, summarize early conversation, rerank and truncate retrieved snippets;
    2. Control output: explicitly set maximum generation length, and constrain structured output with a schema rather than leaving it free-form;
    3. Stabilize the prefix: fix the system prompt and tool definitions, and place variable content later;
    4. Semantic caching: build a result cache for high-frequency similar questions and return hits directly, with an expiration policy in place;
    5. Model tiering: use small models for intent recognition, classification, and extraction, and escalate to large models only for complex reasoning;
    6. Observability: log input/output/cache-hit token counts and costs into logging and monitoring/alerting systems, attribute them by business line, tenant, and endpoint, and set budget threshold alerts;
    7. Load-test metrics: capacity evaluation must look at request count, token count, and cache hit rate together; looking at QPS alone will severely underestimate cost.

    8. Conclusion

    Breaking chat down into tokens, tokens down into hits and misses, and unit prices down into time slots and priority — the significance of this refined metering system for the industry is not that “free things start charging,” but that inference cost has finally become an engineering metric that can be designed, optimized, and budgeted. Whoever raises the cache hit rate, pushes down useless context, and moves deferrable workloads to off-peak hours will serve more users with the same compute.