LLM API Cost Calculation Guide: Limited-Time Discounts and Cache Price Reductions
This guide shows how to build a reusable cost model for LLM API pricing when limited-time discounts, prompt caching, and credit-based billing are involved. It breaks a typical agent request into cached input, uncached input, and output tokens, unifies currency-based and credit-based pricing into a single per-call formula, and runs a sensitivity analysis on cache hit rate to find the break-even point. Readers get a step-by-step calculation workflow, Python snippets, and a practical optimization checklist.
1. Why a Lower Unit Price Does Not Mean a Lower Bill
LLM inference pricing is rarely a single number. It is usually built from several billing dimensions stacked together: cached input, uncached input, and output often carry separate unit prices. Some platforms also replace direct currency pricing with credits or points, which requires an extra conversion step. When a vendor launches a limited-time discount or announces a long-term cache price cut, users often see “80% off” and jump to a conclusion. In reality, the true cost depends on three variables: the call structure (input-to-output ratio), the cache hit rate, and the exchange rate of the plan’s credits.
The right approach is not to compare unit prices, but to build a reusable cost model that puts discounts, caching, and credits into the same formula and runs a sensitivity analysis. This article uses a personal AI coding agent (an OpenClaw-style scenario) as an example and walks through a complete calculation workflow.
2. Four Assumptions to Fix Before Modeling
Any cost calculation must fix its assumptions first; otherwise the conclusions are not reproducible. Make the following four points explicit:
- Budget cycle credit: for example, CNY 40 per month.
- Per-request structure: 51,000 input tokens and 5,100 output tokens, 56,100 tokens in total, an input-to-output ratio of about 10:1.
- Cache hit rate: initially set to 56%, with a sensitivity sweep from 0% to 90% later.
- Billing basis: distinguish “priced in currency” from “priced in credits”; the latter needs a conversion of how many credits correspond to one token.
The key insight here is that in agent scenarios where input far exceeds output, the cache hit rate has a significantly amplified effect on total cost, because the input side accounts for the vast majority of tokens.
3. Splitting a Single Request into Tokens
Total input = 51000Cached input = 51000 * 56% = 28560Uncached input = 51000 * 44% = 22440Output = 5100Total per call = 56100
The point of this split is that only “uncached input” and “output” are billed at the high price, while “cached input” is billed at the discounted price. If you charge all 56,100 tokens at the uncached price, you overestimate the cost by several times.
4. Unifying Four Billing Models
To make cross-comparison easy, convert every option into “cost per call” and “number of calls within CNY 40”.
- Credit-based base model: CNY 40 ≈ 60 million credits, 1 token = 1 credit. Cost per call is about CNY 0.0374, roughly 1,070 calls, about 60 million tokens in total.
- Currency-based lightweight model: cached input CNY 0.2/million, uncached input CNY 1/million, output CNY 2/million. Cost per call is about CNY 0.0384, roughly 1,043 calls, about 58.51 million tokens in total.
- Credit-based advanced model: 1 token = 2 credits. Cost per call is about CNY 0.0748, roughly 535 calls, about 30 million tokens in total.
- Advanced model during the discount period: cached input CNY 0.25/million, uncached input CNY 3/million, output CNY 6/million. Cost per call is about CNY 0.1051, roughly 381 calls, about 21.36 million tokens in total.
The general conversion formula is:
def cost_per_call(inp, out, hit_rate, p_hit, p_miss, p_out):hit = inp * hit_ratemiss = inp * (1 - hit_rate)return (hit * p_hit + miss * p_miss + out * p_out) / 1_000_000# Example: advanced model during the discount periodprint(cost_per_call(51000, 5100, 0.56, 0.25, 3, 6)) # ≈0.1051 CNY
5. Break-Even Analysis of the Cache Hit Rate
Holding everything else fixed and varying only the hit rate yields two important conclusions:
- At a hit rate of about 80%, the per-call cost of the discounted advanced model is roughly equal to that of the credit-based base model.
- Below that threshold, the advanced model is more expensive; above it, the advanced model becomes the better deal.
The derivation is straightforward: set the per-call costs of the two models equal and solve for hit_rate, which gives the break-even point.
def breakeven(inp, out, a, b):# a and b are (p_hit, p_miss, p_out) tuplespa_h, pa_m, pa_o = apb_h, pb_m, pb_o = b# costA = inp*(pa_m + (pa_h-pa_m)*h) + out*pa_onum = inp*(pb_m - pa_m) + out*(pb_o - pa_o)den = inp*((pa_h - pa_m) - (pb_h - pb_m))return num / den
The engineering takeaway: if your system prompts are stable and the system instructions and context prefix can be reused, the hit rate usually stays high, and the discounted advanced model becomes clearly more cost-effective. Conversely, if the prefix differs significantly on every request and the hit rate stays low over time, you should prioritize the lower-priced base model.
6. Heavy Usage and Choosing Credit Plans
Under heavy usage, compare the “effective price per token” rather than the list price. The conversion logic for credit-based plans is: effective unit price = currency price ÷ (total credits ÷ credit coefficient per token). The larger the credit coefficient, the fewer tokens the same amount of currency buys. So even if an advanced model’s unit price looks low, the actual number of calls may be only half that of the base model. Work backward from the monthly budget to the number of calls, then check whether it meets your business peak.
7. An Actionable Optimization Checklist
- Stable prefix: put the system prompt, tool definitions, and long-term context at the very front of the request to improve prefix reuse.
- Control output length: output usually has the highest unit price, so trimming redundant explanations cuts cost significantly.
- Tiered routing: send simple tasks to the low-price model and complex tasks to the advanced model.
- Monitor the hit rate: bring the cache hit rate into your monitoring and alerting dashboard as a core cost metric.
- Recalculate regularly: after the discount period ends, rerun the same script to recompute the break-even point and avoid relying on outdated conclusions.
8. Conclusion
Whether limited-time discounts and cache price cuts are worth it is not answered by the unit price table, but by your call structure. Using this article’s assumptions: at a 56% hit rate the base model is slightly better; at a hit rate of about 80% the two are on par; under heavy usage the lower-priced plan is more economical. Only by turning the token split, credit conversion, and hit-rate sensitivity analysis into a script can you make the right decision quickly every time prices change.
