How to Calculate a Blended Unit Price for Mixed-Billing LLM APIs

    A practical framework for estimating the average cost per million tokens when an LLM API charges separately for cached input, uncached input, and generated output. This guide explains how to define token-based weights, standardize billing data, calculate blended prices and total costs, perform sensitivity analysis, and monitor cost drivers in production.

    1. Why You Need a Blended Unit Price

    Large language model services are typically billed using multiple rates rather than a single price. One request may include three billable token categories:

    • Cached input tokens, charged at a read or cache-hit rate
    • Uncached input tokens, charged at the standard input rate
    • Output tokens, charged at the generation rate

    These prices can differ substantially. Output tokens are often more expensive than input tokens, while cached tokens are usually cheaper than uncached input tokens. As a result, overall cost cannot be represented accurately by simply dividing total spend by the number of requests. Using only the input or output price as a proxy is also misleading.

    A more useful metric is the blended unit price: the average cost per million tokens under a specific token mix.

    The general formula is:

    1. Blended unit price =
    2. w_read × P_read +
    3. w_input × P_input +
    4. w_output × P_output

    Where:

    • P_read is the price for cached or read tokens
    • P_input is the price for uncached input tokens
    • P_output is the price for output tokens
    • w_read, w_input, and w_output are the shares of each token category in total billable tokens

    The weights must satisfy:

    1. w_read + w_input + w_output = 1

    For example, if cached tokens account for 80% of all billable tokens, uncached input tokens account for 10%, and output tokens account for 10%, then:

    1. Blended unit price =
    2. 0.8 × read price +
    3. 0.1 × input price +
    4. 0.1 × output price

    The unit is generally the same as the pricing table, such as currency per million tokens.

    Total cost can then be estimated as:

    1. Total cost = Blended unit price × Total tokens ÷ 1,000,000

    The weights must represent the share of billable token volume, not the share of requests. If only request proportions are available, they must first be normalized using the average input tokens, output tokens, and cache-hit behavior of each request category. Otherwise, the result may significantly understate or overstate the actual cost.

    2. Standardize Five Definitions Before Calculating

    Although the blended-price formula is simple, different teams can produce inconsistent results unless they use the same measurement definitions.

    1. Use the same billing period

    Aggregate the three token categories over the same billing period, model configuration, region, and billing item. Avoid combining data across different periods or pricing scopes.

    2. Use a consistent token-counting method

    Input and output tokens should be tracked separately. Whether cached tokens are measured independently, and how cache hits are identified, should follow the service’s actual billing rules and the billing statement. Do not make assumptions that are not supported by the service definition.

    3. Standardize units

    Pricing tables often use a unit such as currency per million tokens, while monitoring systems may record thousands of tokens or individual tokens. Convert all values to a common unit before calculating to avoid order-of-magnitude errors.

    4. Distinguish list prices from actual prices paid

    A blended price can first be calculated using list prices for architecture comparisons. Actual budgeting should also account for discounts, tiered pricing, free quotas, committed-use packages, or other billing adjustments. The final invoice remains the source of truth.

    5. Document the source of the weights

    Weights should come from real traffic samples or load-testing data rather than arbitrary assumptions. Applications with high cache-hit rates should track read tokens separately. Applications that generate long responses should pay particular attention to the output-token share.

    3. Calculation Steps and Pseudocode

    The calculation can be implemented as follows:

    1. Collect q_read, q_input, and q_output under the same measurement definition.
    2. Calculate the total token volume:

      1. total = q_read + q_input + q_output
    3. If total is zero, stop. Otherwise, calculate:

      1. w_read = q_read / total
      2. w_input = q_input / total
      3. w_output = q_output / total
    4. Load the corresponding prices: p_read, p_input, and p_output.

    5. Calculate the blended unit price:

      1. p_avg =
      2. w_read × p_read +
      3. w_input × p_input +
      4. w_output × p_output
    6. Calculate the estimated total cost:

      1. cost = p_avg × total / 1,000,000
    7. Store the weights, individual prices, and blended price in a monitoring report, and update the report on a daily, weekly, or monthly basis.

    Example pseudocode:

    1. function blendedUnitPrice(pRead, pInput, pOutput, qRead, qInput, qOutput) {
    2. total = qRead + qInput + qOutput;
    3. if (total <= 0) return error;
    4. wRead = qRead / total;
    5. wInput = qInput / total;
    6. wOutput = qOutput / total;
    7. return wRead * pRead + wInput * pInput + wOutput * pOutput;
    8. }
    9. function estimatedCost(pRead, pInput, pOutput, qRead, qInput, qOutput) {
    10. total = qRead + qInput + qOutput;
    11. return blendedUnitPrice(pRead, pInput, pOutput, qRead, qInput, qOutput)
    12. * total / 1000000;
    13. }

    Consider this hypothetical example, which is intended only to demonstrate the formula:

    • p_read = 0.2
    • p_input = 1.0
    • p_output = 2.0
    • Token weights: 0.8, 0.1, and 0.1

    All prices are expressed in currency units per million tokens. The blended price is:

    1. 0.8 × 0.2 + 0.1 × 1.0 + 0.1 × 2.0
    2. = 0.46 currency units per million tokens

    If total usage is 10 million tokens, the estimated cost is:

    1. 0.46 × 10 = 4.6 currency units

    This example is for explaining the calculation only and does not represent the price of any actual service.

    4. Sensitivity Analysis: What Drives the Blended Price?

    Changes in the blended price mainly come from two sources: changes in token weights and changes in unit prices.

    Effect of cache-hit rate

    Let:

    • I be the total input-token volume
    • O be the output-token volume
    • h be the cache-hit rate

    The cached token volume is hI, the uncached input volume is (1-h)I, and the output volume is O. The blended price can therefore be written as:

    1. P(h) =
    2. [hI × P_read + (1-h)I × P_input + O × P_output]
    3. ÷ (I + O)

    If the cache-hit rate increases by one percentage point while I and O remain unchanged, the approximate change in the blended price is:

    1. ΔP =
    2. 0.01 × I × (P_read - P_input) ÷ (I + O)

    Because P_read is typically lower than P_input, this value is negative. In other words, improving the cache-hit rate generally reduces the blended unit price.

    Effect of output-token volume

    Output share is also an important factor. As the proportion of output tokens increases, the blended price moves closer to the output price. If output tokens are expensive, reducing response length, eliminating unnecessary generation, and applying structured-output constraints may be more effective than simply compressing the input.

    In the example with weights of 0.8 for read tokens, 0.1 for uncached input tokens, and 0.1 for output tokens, the blended price is driven primarily by the read price. However, the output price cannot be ignored. If the output-token share rises while the cache-hit rate remains unchanged, the blended price will also increase.

    Cost optimization should therefore consider more than cache-hit rate. Teams should also monitor input repetition, output-length distributions, and request structure.

    5. Monitoring, Budgeting, and Common Mistakes

    In production, collect q_read, q_input, and q_output across dimensions such as:

    • Model
    • Business line
    • Tenant
    • Feature or module

    Use these metrics to calculate the daily blended price, cost per thousand requests, and total cost. Set budget thresholds and anomaly alerts for events such as:

    • A sudden drop in the cache-hit share
    • A sharp increase in average output-token volume
    • A month-over-month increase in the blended price beyond a defined threshold

    After a model-version change, prompt update, or context-length adjustment, recalculate and compare the blended price. This helps identify gradual cost drift before it becomes significant.

    Common mistakes include:

    • Using request proportions instead of token proportions
    • Tracking input tokens while ignoring output tokens
    • Treating cache-hit rate as the read-token weight without normalizing against total token volume
    • Failing to convert between tokens and units such as million tokens
    • Using the unit price of one model to estimate traffic distributed across multiple models
    • Ignoring discounts, free quotas, and tiered pricing when estimating actual spend

    The blended unit price is an estimation and governance metric. Final budgeting should always be calibrated against the billing statement and its actual pricing rules.

    6. Conclusion

    For LLM APIs with mixed billing, the blended unit price is the weighted average of the prices for three token categories:

    1. Blended unit price =
    2. w_read × read price +
    3. w_input × input price +
    4. w_output × output price

    The three weights must add up to one.

    The 0.8 / 0.1 / 0.1 distribution can serve as a quick template for illustrating the calculation, but production use requires consistent measurement definitions, dynamic data collection, and rolling monitoring. Sensitivity analysis can reveal whether cost is primarily driven by cache behavior, input volume, or output generation.

    By incorporating the blended unit price into architecture reviews and budget management, teams can make LLM API costs more explainable, traceable, and controllable without compromising application quality.