LLM Inference Cost: A Practical Benchmark and Model Selection Guide
Comparing per-million-token prices is misleading because the real bill is driven by call structure: rounds, repeated context, cache hit rate, retries, and time-of-day pricing. This guide presents a five-variable cost formula, a minimal but credible A/B testing method using a fixed task set, consistent evaluation and environment, a full week of coverage, and single-variable changes, plus a checklist of hidden engineering costs and common pitfalls. It also shows how to use stable prompt prefixes and schema validation for frontend and structured generation, and why decisions should be based on cost per unit of effective output and P95 rather than list prices.
1. The Starting Problem: Why “Price per Million Tokens” Is Almost Never Directly Comparable
When many teams evaluate models, the first thing they look at is the price sheet: how much per million input tokens, how much per million output tokens. Yet real bills often differ dramatically from expectations. The reason is simple—unit price is just one coefficient in the cost formula. What actually determines total spend is the call structure: how many rounds a request is split into, how many times context is repeated, how high the cache hit rate is, and how much failed retries amplify everything.
Take two common billing strategies as examples. One uses a flat all-day price with separate rates for input and output, making costs highly predictable. The other introduces time-of-day pricing, where peak and off-peak rates differ, so the same workload executed at different times can produce bills that differ by several times. If you simply subtract one “sticker price” from another, the conclusion is almost certainly distorted.
More subtle is how model behavior feeds back into cost. Some models pursue higher accuracy through multi-sampling, multi-round reasoning, and self-consistency voting—generating multiple reasoning paths for the same question and then selecting the best. This genuinely improves correctness, but token consumption grows by a multiple. Compare that with an approach that defaults to a single call and relies on prefix caching to push the cost of repeated context very low, and if you do not count actual rounds, you will severely underestimate the true cost of the former.
2. Write the Cost Formula Clearly: Five Variables Determine the Final Bill
A sufficiently rigorous cost model should include at least the following five items:
- Average number of call rounds per task
R - Average input tokens
Iand output tokensOper round - Input cache hit rate
H(the hit portion is usually billed at a lower price) - Retry factor
T(including reruns caused by timeouts, rate limiting, and content blocking) - Time-of-day price factor
P(t)
The cost of a single task can then be approximated as:
Cost = R * T * P(t) * ( I * (1 - H) * price_in + I * H * price_in_cache + O * price_out )
This formula makes three things clear: first, rounds and retries are multipliers, so their impact far outweighs differences in the decimal places of unit price; second, cache hit rate has an order-of-magnitude effect on the cost of long contexts, fixed system prompts, and batches of similar tasks; third, time-of-day pricing turns “when to run” into an optimizable cost item.
3. Don’t Do a Paper Comparison—Run a Credible A/B Test
Conclusions cannot come from speculation; they can only come from controlled experiments in the same environment. The recommended minimal viable plan is as follows.
- Fix the task set: sample from historical real requests, covering four categories—short Q&A, long-document summarization, structured extraction, and code generation—with a recommended sample size of no fewer than two hundred items per category.
- Fix the evaluation criteria: score accuracy with the same set of rules or the same judge model; at the same time, record rounds, input and output tokens, cache hits, latency, and failure rate.
- Fix the runtime environment: keep concurrency limits, timeouts, and retry policies consistent, so that differences in engineering configuration are not attributed to the model.
- Cover a full cycle: run for at least one week so that time-of-day pricing and business peaks and troughs are both included in the sample.
- Change only one variable: replace only the model or only the prompt at a time, otherwise attribution is impossible.
An illustrative experiment record structure:
{"task_id": "sum_00137","model": "model_a","rounds": 3,"input_tokens": 18240,"output_tokens": 2160,"cache_hit_ratio": 0.61,"hour_bucket": "off_peak","retries": 1,"score": 0.94,"cost": 0.0000}
After the run, don’t look only at averages—look at percentiles. The mean is skewed by a small number of extremely long tasks; P50 and P95 are much closer to the real basis for capacity planning and budgeting.
4. The Hidden Cost Checklist: Beyond the Bill, Count the Engineering Costs
- Migration cost: the work needed to adapt prompts, function-calling protocols, and structured output formats.
- Stability cost: additional development caused by rate-limit thresholds, concurrency quotas, and long-context truncation strategies.
- Operations cost: whether observability such as logging, monitoring and alerting, and distributed tracing is in place, and whether a specific request can be quickly located when something goes wrong.
- Data compliance cost: whether data residency, masking, and audit trails meet industry requirements.
- Lock-in risk: abstract a model gateway layer to consolidate retries, fallback, routing, and billing instrumentation, avoiding business logic scattered everywhere.
5. Scenario Practice: Give Frontend and Structured Generation to the Right Model
For tasks such as information-display sites and admin interfaces, the model’s value concentrates on two points: first, generating usable page structure and style code from natural-language descriptions; second, turning unstructured text into well-formed structured data. These tasks have high context repetition and template-like output, making them the scenarios where caching delivers the most obvious gains.
A pragmatic engineering recommendation is to extract prompt templates, component snippets, and field definitions into a stable prefix so they can be reused; put the volatile user input at the end; and enforce schema validation on generated results, retrying in a targeted way rather than rerunning the whole segment when validation fails.
[Stable prefix: role setting + design spec + component list + field schema][Volatile part: current user description][Output constraint: return only JSON that conforms to the schema, no explanation]
Combined with a three-stage rollout rhythm of “small-sample trial first, then scheduled batches, then full rollout,” you can gradually scale up while keeping cost under control. If the enterprise side wants to further reduce unit cost, it can evaluate model fine-tuning in its own environment, distilling a small model to handle high-frequency simple requests, and using container platforms for elastic scaling and off-peak scheduling, placing heavy work in low-traffic periods.
6. Common Pitfalls
- Looking only at unit price and not rounds: bills for multi-round self-consistency approaches are often underestimated.
- Ignoring caching: a fixed system prompt without prefix reuse means continuously paying for repeated content.
- Using averages for budgeting: long-tail tasks will blow through the budget, so estimate based on P95.
- Migrating everything at once: without canary release and rollback, both risk and cost are amplified.
- Counting tokens but not labor: adaptation and operations hours are often the more expensive part.
7. Conclusion
The right approach to model selection is to upgrade “unit price comparison” to “cost per unit of effective output comparison.” First build a cost formula that includes rounds, caching, retries, and time-of-day pricing; then run a one-week, same-environment, single-variable A/B test to obtain percentile data; finally, make the decision in light of observability, compliance requirements, and migration effort. In this kind of engineering practice, Baidu AI Cloud typically advises customers to consolidate calls and billing instrumentation through a model gateway, and to form a closed loop with monitoring, alerting, and logging services, so that cost optimization rests on measurable facts rather than intuition from a price sheet.
