LLM API Cost Breakdown: Why Do Bills Differ at the Same Per-Token Price?

    At the same per-token price, two platforms can still produce very different monthly bills. This article breaks down the main cost drivers for pay-as-you-go LLM APIs: input/output token structure, cache hit rate, batch discounts, free credits, and subscription plans. It provides a total cost formula, a worked comparison of two prompt structures showing up to 41% savings from prompt caching, a dependency-free Python estimation script, and a pre-launch pricing verification checklist.

    1. Key Takeaway

    Two platforms can charge the same pay-as-you-go rate for the same model and still produce very different monthly bills. The difference mainly comes from three sources: the input/output token structure of each call, the proportion of cache hits, and the rules around discounts and free credits. The unit price is just one coefficient in the formula. When evaluating platforms, run the same real workload through each platform’s pricing model, calculate the monthly cost for each, and only then compare.

    This article is written for pay-as-you-go LLM API users. All prices shown are examples used to demonstrate the calculation method. For actual selection decisions, always refer to each platform’s current price list.

    2. Common Billing Dimensions

    2.1 Separate pricing for input and output tokens

    Most LLM APIs split each request into input tokens and output tokens, priced separately. A token is the unit a model uses to process text. Depending on the tokenizer, one token may correspond to a character, part of a word, or several characters. The conversion ratio differs across languages, so you should not estimate cost from character counts. Use the usage fields returned by the API to measure actual consumption.

    The output price is usually higher than the input price, and the multiplier varies by platform and model. With the same total token count, the higher the output share, the more expensive each call. Scenarios that generate long-form text, code, or reports often underestimate output costs. Some platforms also bill reasoning (“thinking”) tokens generated during inference as output. Verify this when reconciling bills.

    2.2 Cache hits

    When multiple requests share the same prefix—such as a fixed system prompt, a long specification document, or the same knowledge base content—some platforms charge a lower rate for input tokens that hit the cache.

    Prompt caching usually comes with boundary conditions. Confirm each of the following before relying on it:

    • The prefix must match exactly. Even one extra space can invalidate the cache.
    • Most platforms require a minimum prefix length; short prompts never enter the cache.
    • Cached entries expire. After a timeout the prefix must be rewritten, and the write itself may incur a charge.
    • The cache is typically shared only within the same model, account, or organization.
    • How hit tokens are reported in response fields varies by platform and needs to be verified.

    2.3 Batch discounts

    Batch APIs usually let you submit requests asynchronously in exchange for lower unit prices. They suit latency-insensitive tasks such as offline summarization, data cleaning, and bulk labeling. Whether batch discounts stack with cache discounts depends on the platform’s rules. Some platforms require a minimum submission volume or set a maximum completion time, which should be factored into your scheduling.

    2.4 Free credits

    New accounts or specific models often come with free credits. Credits usually have a validity period and expiration date, and some apply only to certain models. When estimating, deduct free credits separately, and check whether the unit price changes once the credits are exhausted.

    2.5 Subscription plans

    Subscription plans typically include a usage allowance, with overage billed per use. Whether a subscription is worthwhile depends on how much of your actual usage the included allowance covers. If daily usage stays well below the allowance, the fixed fee is wasted. If usage frequently exceeds it, the overage rate determines the total cost.

    3. Total Cost Formula

    Calculate monthly cost with the following steps:

    1. Uncached input cost per request = uncached input tokens × input price
    2. Cache hit cost per request = cached tokens × cached price
    3. Output cost per request = output tokens × output price
    4. Daily cost = sum of per-request costs × requests per day
    5. Discounted cost = daily cost × number of days × (1 − batch discount rate)
    6. After free credits: max(0, discounted cost − free credits)
    7. With a subscription: subscription fee + max(0, cost after free credits − included allowance)

    The parameters and their units:

    Parameter Meaning Unit Example value
    requests_per_day Requests per day calls 10000
    input_tokens Total input tokens per request (including prefix) tokens 3200
    cached_prefix_tokens Prefix tokens per request eligible for caching tokens 3000
    cache_hit_rate Fraction of the prefix that hits the cache 0 to 1 0.9
    output_tokens Output tokens per request tokens 500
    input_per_m Input price for uncached tokens CNY per million tokens 10
    cached_per_m Input price for cache-hit tokens CNY per million tokens 2
    output_per_m Output price CNY per million tokens 40
    batch_discount Batch discount rate 0 to 1 0
    free_credit Free credit amount CNY 0
    subscription_fee Subscription fee CNY per month 0
    included_credit Usage allowance included in the subscription CNY per month 0

    4. Cost Comparison of Two Prompt Structures

    The same task can be organized into prompts in two ways. Both produce identical answers from the same model, yet the bills can differ noticeably.

    • Structure A: the user question goes first, with the fixed system prompt and documents at the end. Every request has a different prefix, so there are almost no cache hits.
    • Structure B: the fixed system prompt and documents go first, with the user question at the end. The prefix stays consistent, so the cache hit rate is high.

    Assume each request has 3,200 input tokens, of which 3,000 form a fixed prefix, with 500 output tokens and 10,000 requests per day. Using the example prices from the previous section:

    Item Structure A Structure B
    Cache hit rate 0% 90%
    Uncached input tokens per request 3200 500
    Cache-hit tokens per request 0 2700
    Daily cost (CNY) 520 304
    Monthly cost (CNY, 30 days) 15600 9120

    Under these assumptions, Structure B costs about 41% less per month than Structure A. This ratio only holds for the prefix length, hit rate, and prices above; different values produce different results. Structure B’s advantage requires a prefix that is long enough and reused often enough. If the prefix is only a few dozen tokens, or differs on every request, the gap between the two structures is minimal.

    5. Estimation Script

    The script below uses only the Python standard library, with no third-party dependencies. It requires Python 3.8 or later.

    Save the code as estimate_cost.py, then run:

    1. python estimate_cost.py
    1. """
    2. LLM API monthly cost estimation script
    3. Dependencies: Python 3.8+, standard library only
    4. Note: All prices are example values. Replace them with the current
    5. price list of your target platform before calculating.
    6. """
    7. from dataclasses import dataclass
    8. @dataclass
    9. class Pricing:
    10. input_per_m: float # Input price for uncached tokens, CNY per million tokens
    11. cached_per_m: float # Input price for cache-hit tokens, CNY per million tokens
    12. output_per_m: float # Output price, CNY per million tokens
    13. batch_discount: float = 0.0 # Batch discount rate, 0 to 1, e.g. 0.2 means 20% off
    14. @dataclass
    15. class Workload:
    16. requests_per_day: int # Requests per day
    17. input_tokens: int # Total input tokens per request (including prefix)
    18. cached_prefix_tokens: int # Prefix tokens per request eligible for caching
    19. cache_hit_rate: float # Fraction of the prefix that hits the cache, 0 to 1
    20. output_tokens: int # Output tokens per request
    21. days: int = 30 # Billing period in days
    22. def usage_cost(w: Workload, p: Pricing) -> float:
    23. """Raw pay-as-you-go cost (before discounts and credits)."""
    24. cached = w.cached_prefix_tokens * w.cache_hit_rate
    25. uncached = w.input_tokens - cached
    26. per_request = (
    27. uncached * p.input_per_m
    28. + cached * p.cached_per_m
    29. + w.output_tokens * p.output_per_m
    30. ) / 1_000_000
    31. return per_request * w.requests_per_day * w.days
    32. def monthly_bill(
    33. w: Workload,
    34. p: Pricing,
    35. free_credit: float = 0.0,
    36. subscription_fee: float = 0.0,
    37. included_credit: float = 0.0,
    38. ) -> float:
    39. """
    40. Calculate the monthly bill.
    41. 1. Apply the batch discount first;
    42. 2. Then deduct free credits;
    43. 3. If there is a subscription, the bill is the subscription fee
    44. plus any usage beyond the included allowance.
    45. """
    46. gross = usage_cost(w, p) * (1 - p.batch_discount)
    47. after_free = max(0.0, gross - free_credit)
    48. if subscription_fee > 0:
    49. overage = max(0.0, after_free - included_credit)
    50. return subscription_fee + overage
    51. return after_free
    52. if __name__ == "__main__":
    53. pricing = Pricing(input_per_m=10, cached_per_m=2, output_per_m=40)
    54. # Structure A: the prefix changes every time, almost no cache hits
    55. plan_a = Workload(
    56. requests_per_day=10000,
    57. input_tokens=3200,
    58. cached_prefix_tokens=3000,
    59. cache_hit_rate=0.0,
    60. output_tokens=500,
    61. )
    62. # Structure B: fixed prefix, 90% cache hit rate
    63. plan_b = Workload(
    64. requests_per_day=10000,
    65. input_tokens=3200,
    66. cached_prefix_tokens=3000,
    67. cache_hit_rate=0.9,
    68. output_tokens=500,
    69. )
    70. print(f"Structure A monthly cost: {monthly_bill(plan_a, pricing):.2f} CNY")
    71. print(f"Structure B monthly cost: {monthly_bill(plan_b, pricing):.2f} CNY")

    The output is: Structure A monthly cost 15,600.00 CNY; Structure B monthly cost 9,120.00 CNY, matching the table in Section 4.

    To compare subscription plans, pass subscription_fee and included_credit to monthly_bill. For example, for a 300 CNY monthly fee with a 200 CNY usage allowance, call monthly_bill(plan_b, pricing, subscription_fee=300, included_credit=200). The prices in the script are examples only and must be replaced with actual price list values before calculating.

    6. Pre-Launch Pricing Verification Checklist

    Before signing a contract or going live, verify each item below and record the verification date and source.

    Item What to confirm
    Price list version The effective date of current prices, and whether any upcoming changes have been announced
    Input and output pricing Whether input and output are billed separately, the output-to-input price ratio, and whether reasoning tokens are billed as output
    Caching rules Minimum prefix length, exact-match requirements, cache lifetime, write fees, and how hit tokens are reported
    Batch pricing Discount rate, minimum submission volume, maximum completion time, and whether it stacks with cache discounts
    Free credits Applicable models, validity period, expiration rules, and whether the price changes after exhaustion
    Subscription terms Included allowance, overage rate, and whether unused allowance rolls over
    Usage reporting Whether the API returns accurate token counts, and whether billing metrics match the documented calculation method

    Keeping a dated record of these checks makes it easier to trace discrepancies if the actual bill diverges from your estimate, and ensures the comparison stays valid when platforms update their pricing.