Million-Token Contexts: How Cache Pricing Determines the Real Cost

    Long-context models can accept far more tokens, but a larger window does not automatically make long-context applications economically viable. This article explains how token pricing, prefix caching, cache hit rates, stable-prefix share, and effective utilization determine the real cost of long-context workloads. It also provides a unit-task cost model, a decision framework, and engineering practices for controlling costs when using million-token contexts.

    1. Background: Larger Windows Mean Larger Bills

    Context windows have expanded from hundreds of thousands of tokens to million-level tokens. On the surface, this is just a bigger number, but in practice it changes three things at once: the computation per request, the cost per request, and the amount of information engineers can place into the context. The first two directly affect cost, while the third determines whether a feature is actually feasible.

    Many teams evaluate long-context capability only by checking whether the window limit is large enough, while ignoring the billing model. If usage is charged by input token count, and the unit price does not decrease as context length grows, then expanding the window by five times means the same request will incur roughly five times the input cost. This means that a so-called “million-token context” without a matching pricing mechanism will remain at the demo stage for most businesses.

    Therefore, when evaluating long-context capability, two questions should be answered together: What is the maximum window size, and under the current pricing structure, can the business afford the real cost of each request?

    2. Basic Cost Calculation

    For pay-as-you-go large model services, the input cost of a single request can be written as:

    Input cost = input tokens × input unit price

    Output cost = output tokens × output unit price

    Total cost per request = input cost + output cost

    Without any optimization, a multi-turn conversation or a code agent resends the full history to the model on every round. Suppose the context per round grows from 200,000 tokens to 1 million tokens, while output length and unit prices remain unchanged. The input portion of the cost will then scale by five times. The longer the context, the higher the cost per round, and as the conversation progresses, historical content only accumulates.

    This calculation has two premises. First, billing is linear with input length. Second, every round is billed in full. The second premise is exactly what caching mechanisms are designed to change.

    3. How Cache Pricing Changes the Ledger

    The idea behind prefix caching is that when the beginning of a new request exactly matches the beginning of a previous request, the server can reuse intermediate results that have already been computed and bill that prefix at a lower price. These tokens are usually called “cache-hit tokens,” and their unit price is significantly lower than that of ordinary input tokens.

    The significance of this mechanism for long context is that it separates “long context” from “expensive every round.” As long as the stable prefix is large enough and the hit rate is high enough, long context can run at a cost close to that of short context. Conversely, if the cache price is not significantly lower than the ordinary input price, or if the prefix changes frequently and cannot be hit, the cost pressure from a larger window falls entirely on the user.

    The following hypothetical example illustrates the difference. The unit prices in this example are fictional and are used only to show the calculation method; they do not represent the pricing of any actual service.

    Assume the ordinary input price is CNY 1 per million tokens, and the price for the cache-hit portion is CNY 0.1 per million tokens. A multi-turn task has 50 rounds, with 800,000 tokens of context per round. Of that, 750,000 tokens are stable system instructions and codebase summaries, and 50,000 tokens are new content for the current round. To simplify the calculation, ignore output cost and ignore the possibility that new content may be cached in later rounds.

    Without caching, total input volume is 50 × 800,000 = 40 million tokens, and the cost is CNY 40.

    With caching, the first round is billed entirely at the ordinary price, or CNY 0.8. For rounds 2 through 50, the cached portion is 750,000 tokens per round, costing CNY 0.075; the new portion is 50,000 tokens, costing CNY 0.05. Each round totals CNY 0.125, and across 49 rounds the total is about CNY 6.125. The combined total is about CNY 6.9.

    In this example, caching reduces total input cost to about one-sixth. The key premises are that the stable prefix accounts for a high share of the context and that the prefix is exactly identical in every round.

    4. The Gap Between Nominal and Effective Context

    The window limit is the maximum input length the model can accept. It is not the same as the model being able to stably use every piece of information within that window. Common situations in real engineering work include:

    • Key information is located in the middle of a very long text, the model pays less attention to it, and answer quality fluctuates.
    • Historical conversation keeps accumulating, and irrelevant content crowds out the instructions and evidence that are actually needed.
    • Multiple documents are concatenated, and contradictory descriptions increase the difficulty of reasoning.

    Therefore, it is useful to introduce an “effective utilization” metric, defined as the ratio of information that actually affects the output to the total input in a long context. This metric is difficult to measure directly, but it can be approximated through sampled evaluations, for example by comparing accuracy and human adoption rates at different context lengths on a fixed task set.

    If effective utilization is only 10% to 20%, then expanding the window from 200,000 to 1 million tokens will not bring proportional benefits. Instead, a large amount of cost will be spent on ineffective content.

    5. Unit-Task Cost Model

    When evaluating long-context solutions, it is advisable to use “unit-task cost” as the core metric rather than per-request cost. Unit-task cost can be defined as the sum of all model call costs required to complete one business task. Below is a generic estimation function:

    1. def estimate_task_cost(
    2. rounds: int,
    3. context_tokens: int,
    4. stable_prefix_tokens: int,
    5. output_tokens_per_round: int,
    6. price_input: float,
    7. price_cached: float,
    8. price_output: float,
    9. cache_hit_rate: float,
    10. ) -> float:
    11. """
    12. rounds: number of model calls in the task
    13. context_tokens: total input tokens per round
    14. stable_prefix_tokens: number of stable prefix tokens per round that can be cached
    15. cache_hit_rate: probability that the prefix hits the cache, between 0 and 1
    16. All prices use the same unit: CNY per million tokens
    17. """
    18. scale = 1_000_000
    19. dynamic_tokens = context_tokens - stable_prefix_tokens
    20. cached_part = stable_prefix_tokens * cache_hit_rate * price_cached
    21. uncached_part = stable_prefix_tokens * (1 - cache_hit_rate) * price_input
    22. dynamic_part = dynamic_tokens * price_input
    23. input_cost = (cached_part + uncached_part + dynamic_part) * rounds / scale
    24. output_cost = output_tokens_per_round * rounds * price_output / scale
    25. return input_cost + output_cost

    The value of this function is that it brings price, cache hit rate, prefix share, and number of rounds into a single model. Teams can first estimate the parameters from historical logs, then compare the expected costs of different solutions. Note that the hit rate in the function is not a fixed value. It is affected by factors such as request intervals, cache retention time, and prefix consistency, and should be based on production monitoring data.

    6. Selection Framework

    Whether to adopt long context can be judged in the following order.

    1. Does the task require reading a large amount of material at once? If the answer can be completed from retrieved snippets, prefer retrieval plus short context.
    2. Can the stable prefix be large enough? If system instructions, coding standards, domain knowledge, and similar content remain unchanged for a long time, the cache benefit is obvious.
    3. Does the pricing structure support caching? If the cached unit price is close to the ordinary input price, the cost advantage of long context will be significantly weakened.
    4. Can effective utilization reach an acceptable level? This needs to be confirmed through evaluation, not inferred from window size.
    5. Is unit-task cost below the acceptable range for the business? For batch tasks, it is also necessary to multiply by task volume to estimate an annual budget.

    7. Engineering Optimization Practices

    Even without changing the model, engineering measures can reduce long-context cost.

    Prioritize stable prefixes. Put unchanged instructions, templates, and knowledge at the beginning of the request, and place dynamic content at the end. Even a single character change in the prefix may invalidate the cache, so avoid inserting timestamps, random IDs, and other dynamic fields into system prompts.

    Layer the context. Divide historical conversation into three layers: recent raw text, mid-term summaries, and long-term indexes. Keep recent content complete, compress mid-term content into key points, and recall long-term content through retrieval on demand.

    Use retrieval instead of full filling. For document question-answering tasks, first use retrieval to find relevant passages, then send a small number of snippets to the model. This reduces input volume and often improves effective utilization.

    Set budgets and alerts. Set per-request and daily cost caps for each task type, and monitor cache hit rate and average input length. A sudden drop in hit rate usually means the prefix structure has been changed and should be investigated promptly.

    Batch and truncate. For non-real-time tasks, split large tasks into multiple subtasks and limit the context length of each subtask. When truncating, prioritize content directly related to the current goal.

    8. Conclusion

    The value of long-context capability depends on the combination of three factors: window limit, pricing mechanism, and effective utilization. The window limit determines whether the material can fit; the pricing mechanism determines whether it is affordable after it fits; and effective utilization determines whether the model can use it well after it fits.

    For technical teams, a more reliable approach is to first use a unit-task cost model to estimate the budget, then confirm effective utilization through evaluation, and finally control cost with engineering measures such as stable prefixes, layered context, and retrieval. Only when all three are satisfied can long context turn a parameter advantage into business benefit.