True Cost Calculation of LLM APIs: A Complete Guide to Cache Pricing, Off-Peak Discounts, and Subscription Plans

    Estimating the true cost of Large Language Model (LLM) APIs goes far beyond simply multiplying the listed input and output token prices by expected usage. This article breaks down the complete methodology for calculating actual API costs, focusing on three critical variables: cache hit rate, input-output token ratio, and off-peak discount periods. By providing a step-by-step calculation example and a comparison between subscription plans and pay-as-you-go pricing, it offers actionable best practices to help development teams optimize their LLM infrastructure spending.

    True Cost Calculation of LLM APIs: Don’t Be Fooled by Unit Price Lists

    1. Why “List Price” ≠ “Actual Price”

    LLM API billing typically consists of three parts: input token fees, output token fees, and cache hit token fees. Many teams estimate costs by simply multiplying the “input + output” list price by their expected usage. This often results in monthly bills far exceeding expectations—or, conversely, teams being scared away by seemingly high prices when a cheaper solution actually exists.

    The reason is that actual cost is a weighted average problem, not a flat unit price problem. Mainstream models have widely introduced context caching mechanisms. For repeated prefix content (such as system prompts, long document context, and multi-turn conversation history), the cache hit portion is billed at a rate far lower than the normal input price—often just a tenth or less. This means a model with a “more expensive” list price might actually be cheaper in practice if your business scenario has a high cache hit rate.

    2. Three Key Variables in True Cost Calculation

    1. Cache Hit Rate

    The hit rate depends on the business use case:

    • Agent/Coding applications: Context prefixes are highly repetitive, with hit rates reaching 95% or higher.
    • Multi-turn customer service bots: As conversation turns increase, historical content is cached, typically yielding an 80%~95% hit rate.
    • One-time long text summarization: Every input is new content, so the hit rate approaches 0.

    2. Input and Output Token Ratio

    Take a typical high-cache scenario: a common distribution assumption is 98% cached tokens, 1.5% uncached input, and 0.5% output. Since the unit price of output tokens is usually several times that of input, even a small output proportion has a non-negligible impact on the total cost.

    3. Off-Peak Discount Periods

    Some providers offer significant discounts during low-load periods (e.g., off-peak cache prices might drop to less than half of the regular price). If your business can shift workloads—such as batch data processing, offline evaluations, or scheduled tasks—off-peak pricing will significantly lower overall costs. However, note that each provider defines “peak hours” differently: some platforms have a daily peak window of only a few hours, while others cover much longer periods, directly determining the proportion of discountable time available.

    3. A Calculation Example

    Suppose two models have the following pricing structures (a generic illustrative structure; refer to official vendor sites for exact numbers):

    • Model A: Higher normal input price, but a better cache-to-list price ratio.
    • Model B: Lower overall list price, with highly attractive off-peak cache pricing.

    Using “weighted cost per 100 million tokens” as a unified metric, let’s plug in two hit rate assumptions:

    Scenario 1: 98% Cache Hit (1.5% Input, 0.5% Output)

    1. Weighted Cost = 0.98 × Cache Price + 0.015 × Input Price + 0.005 × Output Price

    The calculation result: Model A is about 12.6 units/100M tokens, while Model B’s off-peak rate is about 9.4 units/100M tokens. Model B’s off-peak price is indeed lower.

    Scenario 2: 95% Cache Hit (4% Input, 1% Output)

    Using the same formula, Model A is about 14.9 units/100M tokens, while Model B’s off-peak rate is about 18.3 units/100M tokens. Here, Model A is the better deal.

    This comparison reveals a crucial conclusion: When the cache hit rate is high enough, off-peak discount advantages are fully realized; as the hit rate drops, the unit price weight of uncached input and output rises, and the conclusion may reverse. Therefore, before selecting a model, you must measure your actual business hit rate distribution rather than blindly applying the vendor’s advertised best-case scenario.

    4. Converting Subscription Plans vs. Pay-As-You-Go

    In addition to pay-as-you-go APIs, most providers offer monthly subscription plans (common in coding assistant scenarios), typically divided into Starter, Pro, and Premium tiers. To evaluate whether a plan is worth it, follow these conversion steps:

    1. Verify plan usage quotas: Note that quotas are often labeled in “non-peak hour token volume”; peak hours may be rate-limited or throttled.
    2. Confirm peak window duration: For example, if a platform’s peak period is only 4 hours per weekday, the discount/available time ratio is very high. If the peak window lasts 12 hours, the actual usable quota takes a hit.
    3. Convert quota to equivalent API costs: Use the true cost calculation formula to convert the plan’s token volume into the original pay-as-you-go price.

    Taking a high cache hit scenario as an example, after conversion, the effective unit price of these plans is usually equivalent to 50%~70% of the original API price (a 30%~50% discount). For teams with stable, predictable usage, subscription plans are almost always better; for teams with volatile usage and sporadic peaks, a combination of pay-as-you-go and off-peak scheduling may offer more flexibility.

    5. Practical Recommendations

    1. Test hit rate before selecting: Log cache hit distributions under real traffic in a testing environment, plug them into the weighted formula, and calculate. Don’t just guess based on the price list.
    2. Establish a unified calculation metric: It is recommended to use “weighted cost per 100M tokens” or “cost per 1,000 requests” as a horizontal comparison metric to make different pricing structures comparable.
    3. Leverage off-peak scheduling: Schedule offline batch processing, evaluation tasks, and data cleaning during off-peak hours to save over 30% in costs.
    4. Mix plans and pay-as-you-go: Route baseline usage through subscription plans and peak overflow through pay-as-you-go APIs to avoid upgrading a plan just for sporadic spikes.
    5. Continuously review: Model pricing and caching strategies iterate quickly. Re-evaluate quarterly; your cost model should be version-controlled like code.

    6. Conclusion

    Cost evaluation in LLM selection is essentially a matching problem of “pricing structure × business traffic distribution.” The price list is only one input parameter. Cache hit rate, input-output ratio, and off-peak period distribution collectively determine the actual bill. Building a reusable calculation framework yields more long-term value than chasing a single “cheaper” quote. For teams currently selecting models, taking half a day to map out your traffic characteristics and calculating them against each platform’s billing rules will often save considerable costs every month going forward.