Why You Shouldn't Evaluate LLM API Costs by Unit Price Alone

    Evaluating LLM API costs goes beyond simply comparing unit prices per million tokens. Factors such as cache hit rates, input-output ratios, time-based pricing, and subscription plans significantly impact actual expenditure. This article provides a comprehensive guide to calculating blended prices, understanding cost drivers, and avoiding common pricing misconceptions to help optimize your LLM budget.

    1. Unit Prices Are Not Directly Comparable

    LLM service pricing is typically quoted per “million tokens,” but the actual cost for the same unit price can vary severalfold across different business scenarios. The cost of a single API call is determined by multiple variables: how much of the input hits the cache, the ratio of input to output tokens, the time of day the call is made, and whether a monthly subscription is used. Comparing unit prices alone only accounts for one variable in the cost equation.

    The basic approach to cost accounting is to calculate a weighted sum of the proportions of various token types and their corresponding unit prices to derive a blended price, which is then used to estimate the budget.

    2. Cache Hit Rate Determines Base Cost

    A cache hit occurs when a portion of the input prefix has already been processed by the server, allowing subsequent requests to be billed at a lower rate. Scenarios such as multi-turn conversations, fixed system prompts, and long-document Q&A often have high prefix repetition rates, leading to high cache hit rates.

    The impact of the hit rate can be illustrated with numbers. Assume the cached input price is 0.1 USD per million tokens, the uncached input price is 1.0 USD per million tokens, the output price is 4.0 USD per million tokens, and output accounts for 0.5% of the total volume.

    • 98% hit rate, uncached input at 1.5%: The blended price is approximately 0.133 USD per million tokens.
    • 95% hit rate, uncached input at 4.5%: The blended price is approximately 0.160 USD per million tokens.

    A 3-percentage-point drop in the hit rate increases the overall cost by about 20%. Therefore, before accounting for costs, you should analyze real hit rates from your logs rather than directly using ideal values.

    3. The Ratio of Input to Output

    The unit price for output tokens is typically much higher than for input. In the example above, the 0.5% output volume contributes 0.02 USD, accounting for about 15% of the total cost. Although the output proportion is small, its impact on the total cost is significant.

    Based on this, we can draw three practical recommendations:

    1. Control output length, such as by limiting response word count or using structured formats, which is highly effective for reducing costs.
    2. Log input and output token counts separately; do not just look at the total volume.
    3. Establish a separate budget model for output-intensive tasks like code generation and long-form writing.

    4. Weighted Calculation for Time-Based Pricing

    Some services set different prices for different time periods. If prices are lower during certain periods, you should weight the prices based on the proportion of API calls in each period rather than simply taking the average or lowest price.

    Example: Peak hours cost 1.0 USD per million tokens and account for 30% of calls; off-peak hours cost 0.5 USD per million tokens and account for 70% of calls. The weighted result is 0.3 × 1.0 + 0.7 × 0.5 = 0.65 USD per million tokens.

    If your traffic is concentrated during peak hours, the actual cost will approach the peak price, even if a lower off-peak price exists.

    5. Converting Subscription Plans

    Monthly or weekly subscription plans usually provide a usage quota rather than a unit price. When comparing a subscription plan to pay-as-you-go pricing, you must first convert the quota into an equivalent pay-as-you-go value:

    • Equivalent Value = Actual usable tokens within the cycle × Blended price
    • Plan Cost-Effectiveness = Equivalent Value ÷ Plan Price
    • Break-Even Usage = Plan Price ÷ Blended price

    Taking a monthly fee of 100 USD and a blended price of 0.133 USD per million tokens as an example, the break-even usage is approximately 752 million tokens. If your actual monthly usage is only 200 million tokens, the equivalent value is about 26.6 USD, making the subscription plan not cost-effective.

    Additionally, factors such as whether the quota is calculated based on cache hits, whether there is a per-call limit, and whether the quota resets per cycle will all affect the conclusion. You should review the official rules line by line before making a decision.

    6. Reusable Cost Calculation Script

    1. def blended_price(shares: dict, prices: dict) -> float:
    2. """
    3. shares: The proportion of each token type, summing to 1
    4. prices: The unit price of each token type, in USD/1M tokens
    5. Returns the blended unit price, in USD/1M tokens
    6. """
    7. if abs(sum(shares.values()) - 1.0) > 1e-9:
    8. raise ValueError("The sum of proportions must be 1")
    9. return sum(shares[k] * prices[k] for k in shares)
    10. def monthly_cost(tokens_million: float, unit_price: float) -> float:
    11. """Returns the cost in USD"""
    12. return tokens_million * unit_price
    13. def break_even_tokens(plan_price: float, unit_price: float) -> float:
    14. """Returns the break-even usage in million tokens"""
    15. return plan_price / unit_price
    16. if __name__ == "__main__":
    17. # The following prices are example values, not actual prices of any service
    18. shares = {"cache_hit": 0.98, "uncached_input": 0.015, "output": 0.005}
    19. prices = {"cache_hit": 0.1, "uncached_input": 1.0, "output": 4.0}
    20. unit = blended_price(shares, prices)
    21. print(f"Blended unit price: {unit:.3f} USD/1M tokens")
    22. print(f"Cost for 100M tokens: {monthly_cost(100, unit):.2f} USD")
    23. print(f"Break-even usage: {break_even_tokens(100, unit):.0f} Million tokens")

    The running result is a blended price of 0.133 USD per million tokens, a cost of 13.30 USD for 100 million tokens, and a break-even usage of 752 million tokens. You can reuse this directly by replacing the values with your own measured proportions and official unit prices.

    7. Common Misconceptions

    • Treating the cache price as the overall unit price. Caching only covers a portion of the input; ignoring uncached input and output will underestimate the cost.
    • Budgeting with ideal hit rates. You should rely on statistics from production logs and leave a margin for fluctuation.
    • Ignoring retries and repeated contexts. Retries after failed requests and the repeated sending of overly long contexts will all be billed.
    • Only looking at the subscription plan price. Estimate actual usage first to determine if the quota can be fully utilized.

    8. Implementation Recommendations

    1. Before launching, use a week’s worth of real traffic to calculate the proportions and hit rates of the three token types.
    2. Use the script to calculate the blended price and output a monthly budget.
    3. Review this monthly; recalculate immediately if pricing rules or business patterns change.
    4. Regardless of the service provider you choose, rely on their official billing documentation and keep your calculation records for auditing purposes.