LLM API Cost Optimization: Why Identical Prices Still Produce Very Different Bills

    When two LLM APIs advertise the same input, cache-hit, and output prices, their monthly bills can still diverge sharply. This article breaks LLM API billing into four factors you can calculate yourself — token pricing units, cache hits and writes, offline discounts and subscription plans, and call structure — and shows why the effective bill depends on all of them, not just the per-token rate. It includes a runnable Python cost-estimation script and a worked example that runs the same usage through four scenarios, cutting the bill by roughly 36% from baseline. You'll also get a platform-rule checklist, answers to common billing pitfalls (why caching sometimes doesn't help, why output tokens dominate cost, how retries double-bill), and a five-step cost-reduction playbook.

    1. Why the Same Price Can Still Mean Bills That Differ by 40%+

    Almost every team runs into the same question the first time it compares prices across multiple LLM API platforms: the model is the same, and the input, cache-hit, and output unit prices look nearly identical — so why do the month-end bills differ so much?

    First, a caveat. The claim that bills differ by “more than 40%” usually only holds under a specific condition: same model, same usage volume, and the same availability of discounts. If the tasks differ in whether they can run offline, whether a subscription plan is purchased, or whether call timing is flexible, the bills will diverge even further.

    “An identical unit price” only means the pay-as-you-go rate is the same for one price channel. It does not mean the entire billing pipeline is the same. A real monthly bill is built up from something much closer to:

    Monthly bill = real-time pay-as-you-go calls + offline pay-as-you-go calls + subscription plan fees and overage + off-peak discounts + hidden costs from cache writes and retries

    Platforms differ in their default values, available options, stacking rules, and settlement order. To avoid tying the discussion to any one vendor, this article does not name specific platforms. Instead, it abstracts cross-platform price differences into four billing factors you can plug into your own calculations: token pricing units, cache hits and writes, offline discounts and subscription plans, and call structure.

    2. The Four Billing Factors That Decide How Different the Bills Are

    2.1 Token Pricing Units

    LLMs bill by token, but the way each vendor’s pricing page expresses it can vary: some use price per million tokens, some per thousand tokens, and some split the input side into two tiers — “cache miss” and “cache hit.” The first thing to do before comparing prices is to convert every price to the same denominator. This article uses price per million tokens throughout.

    You also need to confirm whether the output side includes structured output, function-call arguments, special control tokens, and so on. Mixing different pricing conventions in one table will always distort the conclusion.

    2.2 Cache Hits and Writes

    Cache hits are the most easily underestimated item on a modern API bill. The common pattern is this: stable prefixes — system prompts, fixed examples, tool definitions — are marked as reusable context. After a hit, they are billed at the cache-hit price, which is usually far below the cache-miss input price.

    But caching is not “turn it on and save money.” Two things deserve close attention:

    • A cache hit requires the prefix to match exactly. If the system prompt mixes in timestamps, request IDs, randomly ordered examples, or dynamic user information, the whole prefix can be invalidated and fall back to full-price input.
    • Cache writes are usually billed separately. The write price may equal the cache-miss input price, or it may be tiered by TTL. In the examples in this article, write_ratio is defined as the proportion of cache-miss input tokens that need to be written to cache. For instance, write_ratio=0.05 means that 5% of the tokens in the cache-miss input need to be written to cache, and this portion is billed separately at cache_write_price.

    Low-frequency call scenarios deserve special care: if the cache rarely hits but a large number of requests still write to it, the write cost can eat up the savings.

    2.3 Offline Discounts and Subscription Plans

    This item is usually the main source of “same price, different bill.”

    • Offline/batch channel. Tasks that don’t require second-level responses — log analysis, batch rewriting, offline extraction, data backfill — are often priced lower than real-time pay-as-you-go if the platform offers an asynchronous batch channel.
    • Subscription/committed-volume plans. Prepay for a certain token allowance and the unit price is usually lower than pay-as-you-go; but the overage portion may fall back to the pay-as-you-go price or an average unit price.
    • Off-peak discounts. Nighttime and low-traffic periods may carry additional discounts, provided calls can be moved to those windows.

    Plan calculations require special attention to order. The example in this article uses: calculate the plan first, then the offline discount, then the off-peak discount. It also assumes the plan covers “input + output” tokens and does not include cache writes; the overage falls back to the average input/output unit price. If a real platform’s rules differ, adjust the script to match the actual rules.

    2.4 Call Structure: The Real-World Multiplier

    At the same unit price, different businesses produce different bills because their call structures differ:

    • the ratio of real-time to offline calls;
    • time-of-day distribution;
    • context length and cache-hit rate;
    • retries and failure rate;
    • model-version changes and shifts in free-tier allowances.

    When two platforms quote the same unit price, what you are really comparing is how well your usage profile matches their rules.

    Platform Rule Checklist

    Before doing a cross-platform comparison, confirm at least the following five items:

    Rule What to confirm
    Pay-as-you-go price Whether input, cache-hit, cache-write, and output are all converted to the same unit
    Cache TTL Whether writes are tiered; whether a hit requires the prefix to match exactly
    Offline discount The proportion of tasks that can go offline, the discount size, whether it stacks with plans
    Subscription plan Coverage scope, overage price, whether it is calculated before the offline discount
    Off-peak discount The discount window; whether it applies only to the real-time portion

    3. Cost Model and a Runnable Script

    Below is a corrected estimation script. It splits the bill into input, output, cache write, plan, offline, and off-peak parts. The key fix is: the off-peak discount applies only to the real-time portion and is no longer mistakenly applied to the part that already received the offline discount.

    1. from dataclasses import dataclass
    2. @dataclass
    3. class Price:
    4. """Unit price: CNY per million tokens"""
    5. input_price: float # cache-miss input
    6. cache_hit_price: float # cache-hit input
    7. cache_write_price: float # cache write
    8. output_price: float # output
    9. def estimate(
    10. requests: int,
    11. in_tokens: int, # average input tokens per request
    12. out_tokens: int, # average output tokens per request
    13. cache_ratio: float, # proportion of input that hits cache, 0~1
    14. price: Price,
    15. write_ratio: float = 0.0, # proportion of cache-miss input that needs to be written to cache
    16. offline_ratio: float = 0.0, # proportion of requests that can go through the offline channel
    17. offline_discount: float = 0.0,# offline discount, 0.6 means paying 60% of the price
    18. package_tokens: float = 0.0, # tokens covered by the plan, unit: million tokens
    19. package_price: float = 0.0, # effective unit price of the plan
    20. offpeak_ratio: float = 0.0, # proportion of the real-time portion that can be moved to off-peak hours
    21. offpeak_discount: float = 0.0 # off-peak discount, 0.8 means paying 80% of the price
    22. ):
    23. m = 1_000_000
    24. total_in = requests * in_tokens / m
    25. total_out = requests * out_tokens / m
    26. hit_in = total_in * cache_ratio
    27. miss_in = total_in - hit_in
    28. write_tokens = miss_in * write_ratio
    29. # Input side: cache-hit input + cache-miss input
    30. cost_in_no_write = hit_in * price.cache_hit_price + miss_in * price.input_price
    31. # Cache writes are billed separately
    32. write_cost = write_tokens * price.cache_write_price
    33. # Output side
    34. cost_out = total_out * price.output_price
    35. base = cost_in_no_write + write_cost + cost_out
    36. # Plan deduction: assume it covers input + output, not cache writes
    37. billable_tokens = hit_in + miss_in + total_out
    38. covered = min(billable_tokens, package_tokens) if package_tokens > 0 else 0.0
    39. base_io = cost_in_no_write + cost_out
    40. avg_io = base_io / billable_tokens if billable_tokens > 0 else 0.0
    41. pkg_cost = covered * package_price
    42. remaining = max(0.0, billable_tokens - covered)
    43. over_cost = remaining * avg_io
    44. after_pkg = pkg_cost + over_cost + write_cost
    45. # Offline discount: approximate by proportion of the total bill after the plan
    46. offline_part = after_pkg * offline_ratio
    47. realtime = after_pkg - offline_part
    48. after_offline = realtime + offline_part * offline_discount
    49. # Off-peak discount: applies only to the real-time portion
    50. off_part = realtime * offpeak_ratio
    51. final = after_offline - off_part + off_part * offpeak_discount
    52. return {
    53. "input_cost": round(cost_in_no_write, 2),
    54. "cache_write": round(write_cost, 2),
    55. "output_cost": round(cost_out, 2),
    56. "base_total": round(base, 2),
    57. "after_package": round(after_pkg, 2),
    58. "after_offline": round(after_offline, 2),
    59. "final": round(final, 2),
    60. }
    61. if __name__ == "__main__":
    62. p = Price(
    63. input_price=20,
    64. cache_hit_price=2,
    65. cache_write_price=20,
    66. output_price=100
    67. )
    68. # A: pure pay-as-you-go, no cache, all real-time
    69. print(estimate(6_000_000, 1200, 300, cache_ratio=0.0, price=p, write_ratio=0.0))
    70. # B: cache enabled, 60% hit rate, 5% of cache-miss input needs to be written to cache
    71. print(estimate(6_000_000, 1200, 300, cache_ratio=0.6, price=p, write_ratio=0.05))
    72. # C: B + 30% of requests go offline, at 60% of the price
    73. print(estimate(
    74. 6_000_000, 1200, 300,
    75. cache_ratio=0.6, price=p, write_ratio=0.05,
    76. offline_ratio=0.3, offline_discount=0.6
    77. ))
    78. # D: C + 1/3 of the real-time portion moved to off-peak, at 80% of the price
    79. print(estimate(
    80. 6_000_000, 1200, 300,
    81. cache_ratio=0.6, price=p, write_ratio=0.05,
    82. offline_ratio=0.3, offline_discount=0.6,
    83. offpeak_ratio=1/3, offpeak_discount=0.8
    84. ))

    4. Four Bills from the Same Usage: Where the Difference Comes From

    Assume a typical usage profile:

    • Monthly requests: 6 million;
    • Average input: 1,200 tokens;
    • Average output: 300 tokens;
    • Total monthly input: 7.2 billion tokens;
    • Total monthly output: 1.8 billion tokens;
    • Example unit prices: cache-miss input 20, cache-hit 2, cache write 20, output 100 — all in CNY per million tokens.

    The following figures are illustrative results that demonstrate the calculation method and do not correspond to any specific platform.

    Scenario Key assumptions Monthly cost (illustrative) vs. baseline
    A: Pure pay-as-you-go, no cache, all real-time 0% cache hit, no writes, no discounts 324,000 CNY baseline
    B: Cache enabled 60% hit rate; 5% of cache-miss input written to cache 249,120 CNY -23.1%
    C: Cache + 30% offline at 60% Offline portion billed at 60% 219,225.60 CNY -32.3%
    D: C + 1/3 of real-time calls moved to off-peak Off-peak portion billed at 80%, applies only to real-time 207,600.00 CNY -35.9%

    This table yields three key conclusions.

    First, the cache benefit is “hit rate × price gap,” but you still have to subtract the write cost. With an input price of 20 and a hit price of 2, the hit portion itself is 90% cheaper; the overall reduction is only 23.1% because only 60% of the input hits the cache, the miss portion is still charged at full price, and there is also the write cost.

    Second, the benefit of the offline discount depends on “the offline-eligible proportion × the discount size.” If only 30% of the tasks don’t require real-time responses, you can’t enjoy the full offline discount.

    Third, the off-peak discount looks less dramatic than the cache and offline savings, but it usually has the lowest implementation cost. Moving scheduled tasks, batch tasks, and backfill tasks to off-peak hours is an optimization that “changes the configuration, not the architecture.”

    If you further stack a subscription plan — say, the plan covers 60% of input and output tokens, at a plan unit price below pay-as-you-go, with the overage falling back to the average unit price — the bill can drop further. The exact reduction depends on the plan’s coverage, its unit price, the offline ratio, and the off-peak ratio.

    5. The Most Easily Overlooked Billing Details and FAQ

    1. Why isn’t the cache taking effect?
      A common cause is that the system prompt mixes in timestamps, request IDs, randomly ordered examples, or dynamic user information, which breaks prefix consistency. Put stable content first and dynamic content last.

    2. Why aren’t cache writes worth it?
      Low-frequency, long-tail, short-reuse requests that keep writing to the cache may cost more in writes than they save in hits. Enable caching only for fixed prefixes that are reused at high frequency, and track “write cost / hit savings.”

    3. Output tokens are usually more expensive than input. In scenario A, output tokens make up only 20% of total tokens but contribute about 56% of the base cost. Limiting max_tokens, using summaries instead of full text, and compressing structured fields usually pay off more than optimizing input alone.

    4. Retries are billed again. A retry after a timeout, rate limit, or parse failure is a real request every time. Set a retry cap, enforce idempotency, and use backoff to avoid a doubled bill during incidents.

    5. Model versions change the unit cost. Older versions may be retired or stop opening to new users, and newer versions may come with time-limited free allowances. When building an annual budget, estimate with the post-migration new price rather than reusing the old model’s price.

    6. How do you decide whether a task can go offline? If the business can accept minute-level, hour-level, or batch responses — for example log analysis, data backfill, batch rewriting, offline extraction — then it is a candidate for evaluating the offline channel.

    7. How do you change the configuration for off-peak discounts? Schedule cron jobs, batch tasks, and non-urgent report tasks into the low-traffic windows the platform marks, and monitor failed retries so that nighttime task failures don’t end up increasing the bill.

    6. The Five-Step Cost-Reduction Checklist

    Step 1: Measure. Add instrumentation at the call layer and record at least model, channel, realtime, offpeak, cache_hit, and retry_id. Without data, optimization is guesswork.

    Step 2: Shrink the denominator. Stabilize the system-prompt prefix, compress output length, and cap retries. These three usually don’t depend on any platform feature, yet can bring a clear reduction.

    Step 3: Change the channel. Move asynchronous-eligible tasks to the offline/batch channel, and move stable real-time traffic to a subscription or committed-volume plan, with overage falling back per the rules.

    Step 4: Shift the timing. Move scheduled tasks, data backfills, and batch rewrites to off-peak hours. The implementation cost is low and the benefit is stable.

    Step 5: Add routing and governance. Tier tasks by difficulty: route simple classification, extraction, and formatting to a lighter model, and reserve complex reasoning for the flagship model. At the same time, set budget alerts, quota caps, monthly reconciliation, and quality evaluations to avoid cost cuts that cause quality regressions.

    7. Conclusion

    The right way to compare prices across platforms is not to compare unit-price tables alone, but to compare the match between “rules + usage structure.”

    The recommended order is:

    1. Unify the pricing unit, converting all prices to price per million tokens;
    2. Run the same usage through the four factors: input conventions, cache rules, offline/subscription, and time-of-day distribution;
    3. Optimize in the order “measure → shrink the denominator → change the channel → shift the timing → route and govern.”

    If your business already runs on a mature, stable cloud model service, prioritize doing the measurement and optimization on your own side: unify token instrumentation, stabilize the prompt prefix, separate real-time from offline tasks, and set budget alerts. These actions are independent of any specific platform, yet they determine whether the bill can actually go down.