LLM API Pricing Changes: How to Calculate the Real Cost of Token Usage
As LLM API prices shift, comparing per-million-token rates alone leads to bad estimates. This article breaks down how input, output, and cached input tokens are priced, introduces a reusable cost formula with input-to-output ratio and cache hit rate, and works through three sample workloads to show where the money actually goes. You will get a practical optimization checklist covering input compression, stable prefixes, output limits, tier routing, observability, and budget guardrails, plus guidance on switching from unit-price comparison to cost per completed task.
1. Behind the Price Change Announcement: Why “Cost per Million Tokens” Is a Misleading Question
A general-purpose LLM service recently announced a price adjustment that takes effect after a specified date. Announcements like this always trigger another round of “which model is cheaper” debates. But if you make decisions based only on the unit price in the announcement, you will most likely get the math wrong.
The reason is that LLM API billing is not as simple as “one unit price multiplied by call volume.” Mainstream services split tokens into three separately priced categories:
- Input tokens: all the text you send to the model, including system prompts, conversation history, retrieved documents, tool results, and so on.
- Output tokens: the content the model generates. Because generation requires token-by-token autoregressive decoding, the compute cost is significantly higher than the input stage, so the output unit price is usually several times the input price.
- Cached input tokens: when a request prefix closely matches recent requests, the server can reuse the already-computed intermediate state, and these tokens get a steep discount, commonly around one tenth of the original price.
For the same model, input and output unit prices can differ by five to six times; across capability tiers, the gap can stretch to tens of times. So “how much does 1 million tokens cost” requires three follow-up questions: input or output? did it hit the cache? which capability tier?
2. Abstracting the Cost Model: Turning a Price Sheet into a Formula
Setting aside specific vendors and model names, market pricing can be abstracted into three capability tiers, which makes it easier to build a general mental model:
| Tier | Positioning | Input price (relative) | Output price (relative) | Cached input (relative) |
|---|---|---|---|---|
| Flagship | Complex reasoning, specialized tasks | High | High | 1/10 of input |
| Balanced | Trade-off between capability and cost | Medium | Medium | 1/10 of input |
| Lightweight | Cost-sensitive, high concurrency | Low | Low | 1/10 of input |
Take a currently published tier of a major overseas service as an example (USD per million tokens, order-of-magnitude illustration only): flagship tier input 5, output 30; balanced tier input 2, output 12; lightweight tier input 0.2, output 1.2. Output is exactly 6 times input. Another service shows the same structure of “output ≈ 5 times input, cache ≈ 1/10 of input.” This indicates that the output premium and the cache discount are industry-wide patterns rather than a quirk of one provider.
A single request’s cost can therefore be written as:
Cost = (Tin - Tcache) * Pin+ Tcache * Pin * 0.1+ Tout * Pout
where Tin is total input tokens, Tcache is the tokens that hit the cache, and Pin/Pout are the input and output unit prices.
Two more metrics that are more practical for engineering work:
- Input-to-output ratio R = Tin / Tout: measures whether a call is “read-heavy” or “write-heavy.”
- Cache hit rate H = Tcache / Tin: measures how well prefix reuse is being handled.
Substituting these in, the approximate average cost per request becomes Tin * Pin * (1 - 0.9H) + Tout * Pout. This formula explains a counterintuitive phenomenon: a long-context application with a high cache hit rate can cost far less than an estimate based on list prices; while a generation-style application with short input and long output can burn more money even on the cheapest tier than a “pricier tier with short output.”
3. Scenario-Based Estimates: Real Bills for Three Typical Workloads
Assume 1 million calls occur within a given time window, and estimate each case:
Scenario A: intelligent Q&A / customer support (R≈8, H≈0.6, balanced tier)
About 8 million input tokens and 1 million output tokens. After caching, input cost ≈ 800 × 2 × (1 - 0.54) = 736 USD, output cost ≈ 100 × 12 = 1200 USD, for a total of about 1936 USD. Output accounts for more than 60% of the bill.
Scenario B: code / document batch generation (R≈0.3, H≈0.1, lightweight tier)
About 230,000 input tokens and 770,000 output tokens. Cost ≈ 23 × 0.2 × 0.91 + 77 × 1.2 ≈ 96.6 USD. The unit price is cheap, but the output volume is large, so output is still the main expense.
Scenario C: long-document review (R≈20, H≈0.8, flagship tier)
About 19.05 million input tokens and 950,000 output tokens. After caching, input ≈ 1905 × 5 × 0.28 ≈ 2667 USD, output ≈ 95 × 30 = 2850 USD, for a total of about 5517 USD. Here, if the cache hit rate drops from 0.8 to 0.3, the cost rises to more than about 9000 USD — the value of a cache strategy exceeds the gain from switching tiers.
The conclusion is clear: the first priority in cost optimization is not picking the cheapest model, but reducing output length, raising the cache hit rate, and routing tiers by task difficulty.
4. An Actionable Optimization Checklist
- Compress input structurally: trim system prompts, summarize conversation history instead of concatenating all of it, and rerank retrieval results so only highly relevant fragments are kept.
- Design stable prefixes: put the unchanging system instructions, tool definitions, and knowledge fragments at the very front of the request and keep them byte-level stable; avoid letting volatile content such as timestamps or random IDs pollute the prefix. This is the prerequisite for cache hits.
- Constrain output: explicitly limit word or item counts, and use structured output modes to cut redundant pleasantries and repeated phrasing.
- Tier routing: use the lightweight tier for intent recognition, classification, and extraction, and escalate to the flagship tier only for complex reasoning; this can significantly lower the average unit price.
- Observability first: instrument the gateway to record input, output, and cached tokens plus cost for every call, aggregated by business line, endpoint, and tenant, so you can locate the real cost black holes. This can be built on general cloud capabilities such as logging services and monitoring alerts to assemble a dashboard.
- Budget guardrails: set per-day and per-tenant token quotas and circuit-breaker thresholds to prevent runaway bills caused by abnormal retries or infinite loops.
def estimate(tin, tout, pin, pout, h=0.0, cache_factor=0.1):return (tin * (1 - h) * pin) + (tin * h * pin * cache_factor) + tout * pout# Example: 19.05M input, 950K output, flagship tier, hit rate 0.8print(estimate(19.05e6, 0.95e6, 5, 30, 0.8)) # ~5517 (USD)
5. Selection Advice: Move from “Unit Price Comparison” to “Cost per Completed Task”
Price adjustments will keep happening, and any price sheet will go stale. The methodology that actually holds up is a cost per effective completed task metric: the total spend consumed to close one business loop (for example, resolving one ticket or producing one usable document). Only by factoring in accuracy, retry rate, and the share of human fallback can you judge whether a pricier tier is really “more expensive.”
Engineering teams should treat pricing as a configuration item rather than a hard-coded constant, injected centrally at the gateway, and paired with periodic regression estimates so the cost model updates automatically as the market changes. Platforms such as Baidu AI Cloud typically offer general capabilities including model services, container platforms, and logging and monitoring, which make it easier for teams to put the routing, quota, and observability mechanisms above into practice quickly and keep costs under control and the architecture stable through cycles of price fluctuation.
