LLM API Cost Breakdown: Why the Same Unit Price Can Produce Very Different Bills

    This article explains why two LLM APIs with identical per-token list prices can generate very different monthly bills. It examines usage mix, caching rules, offline batch processing, subscription break-even, time and region factors, and model version changes, then provides a worked cost example with Python code and an implementation checklist.

    1. Same Unit Price, Different Bills

    When comparing LLM API prices, many people look only at the input price and output price per million tokens. This comparison is useful but incomplete. Actual spending is determined by three parts: usage mix (how much is input, output, and cache-hit), call method (real-time or offline), and billing method (pay-as-you-go or subscription). Two platforms may have the same base unit price, but if any one of these rules differs, the monthly bill can differ significantly.

    Cost optimization should therefore proceed in two steps. First, break your own calls down into quantifiable metrics. Second, check each platform’s billing rules one by one to identify where the difference comes from.

    2. Base Billing Dimensions

    Most APIs bill on the following dimensions.

    1. Input tokens: prompts, context, historical conversation, and other content in the request.
    2. Output tokens: content generated by the model. The unit price is usually higher than input.
    3. Cache-hit tokens: when repeated prefixes are reused, they are billed at a unit price significantly lower than ordinary input.

    The base unit price determines the cost baseline, but the share of the three token types determines how high that baseline is. For example, in a scenario with a long system prompt and a few user questions, input tokens far exceed output tokens, and the cache hit rate significantly affects the result. In a code generation scenario, output tokens account for a higher share, so the output unit price is the main variable.

    3. Hidden Costs of Cache Billing

    Caching is one of the most effective ways to reduce costs, but its billing rules are often overlooked. The following points need attention during evaluation.

    • Automatic cache trigger conditions: Some services automatically enable caching for repeated prefixes, provided that the prefix content is exactly the same and is located at the beginning of the request. A dynamic field such as a timestamp placed at the front can invalidate the entire prefix.
    • Cache write fees: Some platforms charge separately for cache writes, and the write unit price may be higher than ordinary input. This cost can be offset only if the cache is hit after writing.
    • Cache TTL: The shorter the TTL, the more easily the cache expires. If the interval between two requests exceeds the TTL, a write fee is incurred each time, making caching more expensive than not using it.
    • Actual hit rate measurement: Use the usage statistics returned by the service, not estimates based on experience.

    To judge whether caching is worthwhile, use the following logic. Assume a prefix is written once and then hit N times within the TTL. Caching pays off only when the savings from N hits exceed the write cost.

    4. Offline Batch Processing and Real-Time Call Separation

    Many platforms offer discounts for offline batch processing. These tasks usually do not require immediate responses, such as data labeling, document archiving, nightly report generation, and batch summarization.

    The main difference between real-time and offline calls is latency requirements. Mixing both types in the same channel causes requests that could receive a discount to be billed at standard rates. The separation approach is as follows.

    1. Review requests in the business and mark the maximum waiting time each request can tolerate.
    2. Put tasks that can tolerate delays of hours or even a day into a batch processing queue.
    3. Keep user-facing interactive requests in the real-time channel.
    4. Set separate monitoring metrics for both channels to prevent batch backlog from affecting the main workflow.

    5. Subscription vs Pay-as-You-Go Break-Even

    Subscription billing usually includes a fixed monthly fee and a certain included quota, with overage billed by usage. To determine which method is cheaper, calculate the break-even point.

    Let the monthly fee be F, the included quota be Q (million tokens), the overage unit price be p, actual usage be U (million tokens), and the weighted average pay-as-you-go unit price be c. A subscription is more cost-effective when the fixed fee plus overage cost is less than the total pay-as-you-go cost, that is:

    F + max(0, U − Q) × p < U × c

    This formula has several points to note. First, U should be the actual value for a calendar month and should account for peaks. Second, the models and call methods included in a subscription may be limited, so confirm that they cover the target scenarios. Third, if usage fluctuates widely, calculate low-usage and high-usage months separately instead of looking only at averages.

    6. Time and Region Factors

    Some services bill differently by time period or region.

    • Time rules: Some platforms offer discounts during specific periods, often off-peak. If call times can be adjusted, schedule batch tasks in these periods to reduce cost. Verify such rules against official documentation rather than assumptions.
    • Region differences: The same model may have different prices in different regional nodes, and overseas nodes are often more expensive. Cross-region calls also add network latency and affect the interactive experience. When choosing a region, compare price, latency, and data compliance requirements together.

    7. Cost Changes from Model Version Iterations

    Models are updated continuously. Older versions may stop being available to new users after a certain date and may be retired later. This means cost evaluation cannot be done only once. The following measures are recommended.

    1. Manage model names with configuration items in code instead of hardcoding them.
    2. Before each version switch, compare the quality and cost of the new and old versions using the same sample set.
    3. Reserve a testing period for migration, including prompt adjustment and output format validation.

    8. Cost Calculation Example

    The following example uses hypothetical unit prices solely to illustrate the calculation method and does not represent real prices from any platform. Assume the input price is CNY 10 per million tokens, the cache hit price is CNY 1, and the output price is CNY 50.

    Monthly usage is as follows: 500 million input tokens, 60% of which hit the cache; 50 million output tokens.

    • Without cache: 500 × 10 + 50 × 50 = CNY 7,500
    • With cache: 200 × 10 + 300 × 1 + 50 × 50 = CNY 4,800

    Caching alone saves 36%. If 30% of requests are moved to offline batch processing and the offline discount is 50%, total cost further drops to:

    4800 × (1 − 0.3 × 0.5) = CNY 4,080

    The corresponding calculation code is below. You can replace the unit prices and usage data with your own.

    1. from dataclasses import dataclass
    2. @dataclass
    3. class Pricing:
    4. input_per_m: float # ordinary input, CNY per million tokens
    5. cache_hit_per_m: float # cache hit, CNY per million tokens
    6. output_per_m: float # output, CNY per million tokens
    7. def monthly_cost(
    8. price: Pricing,
    9. input_m: float,
    10. cache_ratio: float,
    11. output_m: float,
    12. batch_share: float = 0.0,
    13. batch_discount: float = 0.5,
    14. ) -> float:
    15. """Calculate monthly cost. Usage units are million tokens.
    16. batch_share: share of requests sent to offline batch processing (0 to 1)
    17. batch_discount: price factor for offline tasks; 0.5 means 50% off
    18. """
    19. if not 0 <= cache_ratio <= 1 or not 0 <= batch_share <= 1:
    20. raise ValueError("share parameters must be between 0 and 1")
    21. cached = input_m * cache_ratio
    22. uncached = input_m - cached
    23. realtime = (
    24. uncached * price.input_per_m
    25. + cached * price.cache_hit_per_m
    26. + output_m * price.output_per_m
    27. )
    28. # Offline portion is discounted by the factor; real-time portion stays at full price
    29. return realtime * (1 - batch_share * (1 - batch_discount))
    30. def subscription_cost(
    31. monthly_fee: float,
    32. quota_m: float,
    33. overage_per_m: float,
    34. usage_m: float,
    35. ) -> float:
    36. """Subscription monthly cost: fixed fee plus overage."""
    37. return monthly_fee + max(0.0, usage_m - quota_m) * overage_per_m
    38. if __name__ == "__main__":
    39. price = Pricing(input_per_m=10, cache_hit_per_m=1, output_per_m=50)
    40. print(monthly_cost(price, 500, 0.6, 50)) # 4800.0
    41. print(monthly_cost(price, 500, 0.6, 50, batch_share=0.3)) # 4080.0

    The example shows that even when two platforms have the same base unit price, different caching, offline, or subscription rules can lead to different bills for the same usage.

    9. Implementation Steps

    It is recommended to proceed with cost optimization in the following order.

    1. Collect usage data: Record input, output, and cache-hit token counts for each request, along with call time and scenario tags.
    2. Profile and classify: Divide requests into real-time interactive, offline batch, and background asynchronous categories, and calculate statistics separately.
    3. Estimate options: For each request category, use the functions above to compare the cost of pay-as-you-go, offline, and subscription options.
    4. Roll out gradually: Migrate a small portion of traffic first, and monitor quality metrics and cost changes at the same time.
    5. Monitor continuously: Set monthly budget alerts and track changes in cache hit rate, offline share, and overage usage.
    6. Review regularly: Prices and rules change, so recheck official billing documentation every quarter and record the verification date.

    10. Conclusion

    The cost of LLM APIs is determined by unit prices, usage mix, call methods, and billing rules together. Comparing only base unit prices can easily miss cache writes, offline discounts, subscription overages, region differences, and other factors. Only by breaking usage down into quantifiable metrics, checking rules item by item, and comparing options with a consistent calculation method can you find the real opportunities for cost reduction.