How to Calculate LLM Inference Costs: Beyond Per-Token Pricing
This article breaks down how LLM inference costs are actually determined, why per-token pricing only shows part of the picture, and how to measure and control them. It covers the four layers of real request cost, the technical reasons input and output tokens are priced asymmetrically, the trade-offs behind low-latency model variants, and six practical levers for cost governance, along with a checklist for model selection. The key takeaway: cost reasonableness depends on context length, input/output ratio, cache hit rate, task routing, and retry overhead, not on the sticker price alone.
1. Starting With a Common Complaint
In a discussion about an internal preview of a new-generation large model, the most concentrated feedback was a single sentence: “Still too expensive,” backed by a quoted price of 0.5 yuan per million input tokens and 1 yuan per million output tokens. The statement is representative because it compresses complex inference economics into a single unit-price comparison. To evaluate it professionally, the subjective judgment of “expensive” first needs to be broken down into measurable engineering questions.
One caveat: for any model in internal preview, its pricing, rate limits, context length, and capability boundaries are all temporary policies that may change at any time. This article therefore does not discuss the price or parameters of any specific product. Instead, it abstracts the problem into a general one: what determines LLM inference cost, how to estimate it, and how to govern it.
2. What Makes Up Inference Cost: Unit Price Is Only the Tip of the Iceberg
Per-token billing is only the surface of the bill. The real cost of a single request includes at least four layers:
- Compute cost: The overhead of the attention mechanism grows non-linearly with context length, so a long-context request costs far more than a short one, even at the same per-token price.
- GPU memory and concurrency cost: Memory capacity determines how many requests can be resident simultaneously, and batching efficiency directly determines the amortized cost per token.
- Transfer and recomputation cost: Repeatedly passed system prompts, retrieved snippets, and conversation history are billed again and again within the same session.
- Engineering and operations cost: Rate-limit retries, failure rollbacks, observability, evaluation, and regression testing are all hidden expenses.
The right way to judge whether something is “expensive” is therefore to calculate the cost per unit of effective output, not to compare unit prices.
Cost per unit of effective output = (input tokens × input price + output tokens × output price + retry and redundancy overhead)÷ number of tasks effectively completed
3. Why Input and Output Must Be Priced Asymmetrically
The 0.5-to-1 ratio between input and output is not arbitrary; it reflects a difference in compute structure:
- The input stage can be highly parallelized: encoding an entire prompt can be done in a single forward pass, with high hardware utilization.
- The output stage is autoregressive, generating one token at a time, where each step depends on the previous result. It is hard to parallelize and requires continuously reading the key-value cache, creating heavy memory-access pressure.
- The longer the output, the longer it occupies memory and concurrency slots, and the higher the opportunity cost.
This explains a common misconception: stuffing a long document into the context all at once may seem convenient, but it can actually cost more than “retrieve first, then answer.” The input side may be cheap, but repeated transmission and the attention overhead of long contexts accumulate.
4. The Essence of Low-Latency Variants: An Explicit Trade-Off
Flash-style variants are generally understood in the industry as making reductions in parameter count, distillation strategy, quantization precision, and scheduling in exchange for lower time-to-first-token latency and higher throughput. They suit high-concurrency, short-output, fault-tolerant scenarios such as intent recognition, structured extraction, tag classification, and candidate generation for code completion. For long-chain reasoning, complex code refactoring, and rigorous document writing, they typically underperform flagship versions.
The correct engineering approach is not to choose one or the other, but to route in layers:
def route(task):if task.risk == "high" or task.chain_depth > 3:return "flagship" # complex tasks go to high precisionif task.output_tokens < 512 and task.latency_slo < 800:return "flash" # simple, high-frequency tasks go to low latencyreturn "standard"
Combined with a pattern where a small model first makes a feasibility judgment and a large model only renders the final verdict, this can lower the cost per unit across most traffic.
5. Six Levers for Cost Governance
- Prefix caching: Keep system prompts, tool descriptions, and long documents fixed at the front so repeated portions hit the cache. This is the highest-return and most frequently overlooked measure.
- Prompt slimming: Remove redundant examples and repeated constraints; fewer tokens often bring a linear cost reduction.
- Batching and asynchronization: Run offline tasks off-peak, trading throughput for unit price.
- Output constraints: Use structured schemas to limit output length and avoid extra billing from unconstrained generation.
- Semantic caching: Cache results for high-frequency similar questions, with similarity thresholds and expiration policies.
- Full-chain observability: Tag by business dimension and track tokens, latency, and failure rates to build cost attribution.
6. Selection and Evaluation Checklist
- Quality baseline: Run regression evaluation on your own business dataset rather than relying on public leaderboards.
- Cost model: Use “cost per thousand successful tasks” as the metric, including retries and human fallback.
- Latency budget: Define percentile targets for both time-to-first-token and end-to-end latency.
- Elasticity and rate limiting: Confirm queuing and degradation strategies under burst traffic.
- Data and compliance: Clarify requirements for data retention, masking, and auditing.
- Portability: Abstract the model invocation layer to avoid tight coupling between business logic and a single interface.
7. Conclusion
The professional answer to “still too expensive” is that the unit price alone is not a conclusion. Only by modeling context length, input/output ratio, cache hit rate, task layering, and failure recomputation together can you judge whether the cost is reasonable. Low-latency and flagship versions are not substitutes but two points on the cost curve; what really determines the bill is architecture, not the listed price. If you are already using related capabilities from Baidu AI Cloud, it is likewise advisable to adopt “cost per unit of effective output” as a unified metric for continuous measurement and optimization.
