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:
- Uncached input cost per request = uncached input tokens × input price
- Cache hit cost per request = cached tokens × cached price
- Output cost per request = output tokens × output price
- Daily cost = sum of per-request costs × requests per day
- Discounted cost = daily cost × number of days × (1 − batch discount rate)
- After free credits: max(0, discounted cost − free credits)
- 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:
python estimate_cost.py
"""LLM API monthly cost estimation scriptDependencies: Python 3.8+, standard library onlyNote: All prices are example values. Replace them with the currentprice list of your target platform before calculating."""from dataclasses import dataclass@dataclassclass Pricing:input_per_m: float # Input price for uncached tokens, CNY per million tokenscached_per_m: float # Input price for cache-hit tokens, CNY per million tokensoutput_per_m: float # Output price, CNY per million tokensbatch_discount: float = 0.0 # Batch discount rate, 0 to 1, e.g. 0.2 means 20% off@dataclassclass Workload:requests_per_day: int # Requests per dayinput_tokens: int # Total input tokens per request (including prefix)cached_prefix_tokens: int # Prefix tokens per request eligible for cachingcache_hit_rate: float # Fraction of the prefix that hits the cache, 0 to 1output_tokens: int # Output tokens per requestdays: int = 30 # Billing period in daysdef usage_cost(w: Workload, p: Pricing) -> float:"""Raw pay-as-you-go cost (before discounts and credits)."""cached = w.cached_prefix_tokens * w.cache_hit_rateuncached = w.input_tokens - cachedper_request = (uncached * p.input_per_m+ cached * p.cached_per_m+ w.output_tokens * p.output_per_m) / 1_000_000return per_request * w.requests_per_day * w.daysdef monthly_bill(w: Workload,p: Pricing,free_credit: float = 0.0,subscription_fee: float = 0.0,included_credit: float = 0.0,) -> float:"""Calculate the monthly bill.1. Apply the batch discount first;2. Then deduct free credits;3. If there is a subscription, the bill is the subscription feeplus any usage beyond the included allowance."""gross = usage_cost(w, p) * (1 - p.batch_discount)after_free = max(0.0, gross - free_credit)if subscription_fee > 0:overage = max(0.0, after_free - included_credit)return subscription_fee + overagereturn after_freeif __name__ == "__main__":pricing = Pricing(input_per_m=10, cached_per_m=2, output_per_m=40)# Structure A: the prefix changes every time, almost no cache hitsplan_a = Workload(requests_per_day=10000,input_tokens=3200,cached_prefix_tokens=3000,cache_hit_rate=0.0,output_tokens=500,)# Structure B: fixed prefix, 90% cache hit rateplan_b = Workload(requests_per_day=10000,input_tokens=3200,cached_prefix_tokens=3000,cache_hit_rate=0.9,output_tokens=500,)print(f"Structure A monthly cost: {monthly_bill(plan_a, pricing):.2f} CNY")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.
