How to Calculate Blended LLM Token Costs: Weighted Pricing Method and Practice

    Single-tier LLM pricing can be misleading because cache-hit input, cache-miss input, and output tokens are billed at different rates and used in different proportions. This article explains how to calculate a weighted blended unit price from real token ratios, estimate the hit, miss, and output ratios from call logs, use the metric for model comparison and cost optimization, and avoid common pitfalls such as inconsistent units and outdated ratio assumptions.

    1. Why a Blended Unit Price Is Needed

    In real-world LLM API usage, most platforms do not charge a single flat price for every request. Instead, a request is split into three billable token categories:

    1. Cache-hit input tokens: If the input of a request matches previously cached context, this part is billed at the “cache read” price, which is usually much lower than the regular input price.
    2. Cache-miss input tokens: New input that does not hit the cache is billed at the “input” price.
    3. Output tokens: The generated result is billed at the “output” price, which is usually the most expensive of the three.

    The problem is that the output price of the same model may be several times its input price, while the cache hit rate can vary significantly across business scenarios. Looking only at an officially published single-tier price can easily lead to misjudgment. For example, a model may have a low output price but a high input price, making its total cost higher in long-context scenarios. Therefore, we need a blended unit price weighted by actual usage proportions, converting the three price tiers into an average cost per 1K (or 1M) tokens so that different models can be compared on the same basis.

    2. Formula for the Blended Unit Price

    Assume the proportions of the three token categories are:

    • Cache hit ratio: h
    • Input miss ratio: m
    • Output ratio: o

    These satisfy h + m + o = 1. The corresponding unit prices are P_cache, P_input, and P_output (with the same unit, such as CNY per 1K tokens). The blended unit price is:

    1. P_weighted = h * P_cache + m * P_input + o * P_output

    The following Python function captures this calculation logic for batch comparisons:

    1. def weighted_price(p_cache, p_input, p_output,
    2. hit_ratio, miss_ratio, output_ratio):
    3. """
    4. Calculate the weighted blended price (CNY/1K tokens).
    5. hit_ratio + miss_ratio + output_ratio must equal 1.
    6. """
    7. assert abs(hit_ratio + miss_ratio + output_ratio - 1) < 1e-9
    8. return (hit_ratio * p_cache
    9. + miss_ratio * p_input
    10. + output_ratio * p_output)
    11. # Example: assume 60% hit, 30% miss, 10% output
    12. # Cache read CNY 0.08/1K, input CNY 0.8/1K, output CNY 3.2/1K
    13. print(weighted_price(0.08, 0.8, 3.2, 0.6, 0.3, 0.1))
    14. # Output: 0.552

    As shown, although the output price is as high as CNY 3.2 per 1K tokens, the blended unit price is reduced to CNY 0.552 per 1K tokens because output accounts for only 10% of usage. This is the value of the weighted approach: it reflects the average cost from the perspective of the actual bill, rather than the surface-level level of any single price tier.

    3. Where the Ratios Come From: Estimating h, m, and o

    This is the most critical and most easily overlooked step in the entire method. Different ratio assumptions can lead to completely opposite conclusions. The following are empirical approaches for several typical scenarios. Actual values should be based on your own call log statistics.

    1. Multi-turn dialogue / Agent scenarios: Each turn carries historical context. If the platform supports context caching, the hit rate is often high, so h can be set to 0.5–0.8. Output accounts for a relatively small share, with o around 0.05–0.15.
    2. Single-turn long-document summarization / document Q&A: The input is mostly new long text, so cache hits are low and m dominates, potentially reaching 0.7–0.9.
    3. Code generation / content creation: The input is shorter (instructions plus a small amount of context), while the output is longer. o may reach 0.2–0.4, significantly increasing the weight of the output price.

    From an engineering perspective, a recommended practice is to record the three token usage categories for each request at the gateway or application layer. Most platforms return prompt_tokens and completion_tokens in responses, and some also return a cached_tokens field. Aggregate the real ratios periodically and recalculate the blended unit price with the formula. Example statistics logic:

    1. SELECT
    2. model,
    3. SUM(cached_tokens) / SUM(total_tokens) AS hit_ratio,
    4. SUM(prompt_tokens - cached_tokens) / SUM(total_tokens) AS miss_ratio,
    5. SUM(completion_tokens) / SUM(total_tokens) AS output_ratio
    6. FROM call_logs
    7. GROUP BY model;

    4. Using the Blended Unit Price for Model Selection and Optimization

    With a consistent basis, two valuable tasks become possible.

    First, rank candidate models for selection. Apply the same set of ratios (for example, ratios measured from your own business) to the formula for each candidate model to produce a blended unit price ranking. You may find that the ranking differs significantly from one based only on output price or only on input price. Some models that look cheap at a single tier but are expensive overall may move down, while some models with expensive input but strong caching capabilities may move up in multi-turn scenarios. This is also why the same model can show large cost differences between “normal hours” and “peak hours,” or across different context-length tiers. Time-based pricing and tiered pricing should be weighted separately according to your actual time-of-day distribution and context-length distribution, rather than roughly estimated using a midpoint value.

    Second, guide cost optimization in reverse. The blended unit price formula reveals clear optimization levers:

    • Improve cache hit rate: Place stable system prompts, tool definitions, and knowledge snippets near the front of the request header to improve context cache hits. Each 10-percentage-point increase in h can reduce the blended unit price by roughly 10% of the input price.
    • Compress cache-miss input: Trim historical dialogue and streamline RAG retrieval results to directly reduce the absolute token volume of m.
    • Control output length: Use clear output format constraints and set a reasonable maximum generation length to reduce the most expensive output tokens.
    • Schedule off-peak: Move batch tasks that are not time-sensitive to off-peak hours to take advantage of lower time-based prices.

    5. Caveats

    1. Consistent units: When comparing models, ensure that all “per 1K token” prices are converted to the same unit. Some platforms quote per 1M tokens, while others quote per 1K tokens. Pay attention to the 1,000x relationship.
    2. Dynamic ratios: Cache hit rates change as the business evolves. It is advisable to review the weighted parameters once a month.
    3. Other billing items: Some platforms also charge request fees, concurrency charges, tool-call surcharges, and other fees. If present, they should be amortized into the calculation. The formula can be extended to “fixed cost + weighted token cost.”
    4. Do not rely on a single price tier: Any conclusion about whether a model is “cheap” or “expensive” based on only one price tier may be overturned when checked against the real bill.

    Summary: By abstracting the billing rules—cache hits at the read price, misses at the input price, and outputs at the output price—into a weighted formula and using real call logs to calculate the three ratios, you can obtain a fair, comparable, and actionable blended unit price metric. It brings model selection back to real cost and clearly identifies four optimization directions: cache hit improvement, input compression, output control, and off-peak scheduling. It is an essential tool for any team that needs to manage inference costs over the long term.