LLM Inference Cost: A Practical Benchmarking and Model Selection Guide
Comparing per-million-token prices is almost always misleading when choosing an LLM for production. This guide explains why list pricing fails to predict real spend, how to build a total cost of ownership model that includes round and retry factors, and how to run a reusable load test and A/B evaluation on a fixed production sample. It also covers prefix and cache design, retry budgeting, and architecture practices such as gateway-level observability, queue-based peak shifting, and cost threshold alerts, so model selection decisions become reproducible, auditable, and continuously recalibrated.
1. The Starting Problem: Why Per-Token Price Comparisons Are Almost Always Wrong
When a new model is released, the first number people compare is usually the quoted input and output price per million tokens. Engineering-wise, this comparison does not hold up, for three reasons.
First, quotes typically distinguish cache hits from cache misses, and the cache hit rate is determined by your workload characteristics, not by the model. An intelligent Q&A scenario built around a long system prompt and a fixed knowledge prefix has a highly repetitive prefix, so its hit rate is naturally high; a scenario that concatenates different context on every request may see a hit rate close to zero. Using the bill from the former to infer the cost of the latter can be off by an order of magnitude.
Second, billing is usually segmented by time. Peak and off-peak hours, monthly commitments versus pay-as-you-go, and different throughput tiers all map to different prices. Collapsing segmented pricing into a single number for comparison throws away the most important degree of freedom: the room you have to schedule work.
Third, and most easily overlooked, the price of a single call is not the price of completing a task. If a model needs more rounds, more retries, or a longer chain of thought to converge on the right answer, then a “cheap single call” gets multiplied by the call count into a more expensive total bill.
So the right question is not “which model is cheaper per million tokens,” but “what is the total cost of completing the same batch of tasks on my load curve?”
2. Building a Total Cost of Ownership Model
Break cost into measurable factors rather than a single quote:
Cost per task =(In_cached * P_in_cached + In_uncached * P_in_uncached+ Out * P_out) * R_round * (1 + R_retry)Total cost = Σ(cost per task) * daily request volume + fixed cost (reserved capacity / ops / bandwidth)
Here R_round is the average number of call rounds needed to complete a task, and R_retry is the failure retry rate. Most teams optimize only the price terms inside the parentheses and never measure R_round or R_retry, yet those two are often the real source of cost differences.
A practical rule of thumb: when a task requires multi-step reasoning or tool calls, the round factor is often greater than 1 and varies noticeably between models. Treating it as a constant 1 when budgeting will almost certainly underestimate spend.
3. A Reusable Load Testing and A/B Testing Plan
Conclusions must come from data, not from launch-day marketing. Recommended process:
- Sample real traffic. Pull a week of requests from production logs, preserving characteristics such as length distribution, prefix repetition, and tool-call ratio, then desensitize them into a fixed test set. Once the test set is fixed, do not change it, or the before-and-after numbers stop being comparable.
- Fix the evaluation baseline. Same temperature, same maximum output length, same timeout and retry policy, same concurrency level, changing only the model as the single variable.
- Record three categories of metrics at once: quality (task success rate, structured-output validity rate), cost (token consumption and billing), and latency (percentiles of time-to-first-token and end-to-end latency).
- Run a full cycle. Cover at least one business peak and one trough, so the real impact of segmented pricing and rate limiting becomes visible.
A minimal illustrative experiment skeleton:
# Pseudocode: demonstrates experiment design only, not tied to any specific vendor APIasync def run_ab(model_client, samples, cfg):stats = defaultdict(lambda: {"calls": 0, "in": 0, "out": 0,"ok": 0, "latency": []})for s in samples:t0 = time.perf_counter()r = await model_client.chat(model=cfg.model, messages=s.messages,temperature=cfg.temperature, max_tokens=cfg.max_out,timeout=cfg.timeout)stats[cfg.model]["latency"].append(time.perf_counter() - t0)stats[cfg.model]["calls"] += 1stats[cfg.model]["in"] += r.usage.prompt_tokensstats[cfg.model]["out"] += r.usage.completion_tokensstats[cfg.model]["ok"] += int(validate(r.text, s.golden))return stats
When reading the results, put success rate ahead of cost: a cheaper option with a success rate 5 percentage points lower usually needs human fallback, and that hidden cost far exceeds the saved call fees.
4. Caching and Prefix Design: The Underrated Cost Lever
In most long-context applications, optimizing prefix structure pays off more than switching models. Key points: put the stable system prompt, tool definitions, and domain knowledge at the very front and keep them byte-for-byte unchanged; put request-varying content at the end; avoid breaking prefix consistency with volatile fields such as timestamps and random IDs; for very long documents, summarize in segments and then concatenate to reduce repeated transmission.
A simple engineering guardrail metric is the prefix hit rate. If the hit rate stays persistently below expectations, investigate the template concatenation logic first rather than switching models first.
5. Rounds and Retries: Converting Accuracy into Cost
A common way to raise accuracy is to let the model try more, verify more, and self-correct across multiple rounds. This works for quality but acts as a multiplier on cost. Set differentiated policies per task: high-certainty tasks are fine with a single call; reasoning-heavy tasks need a maximum round cap and an early-exit condition; for structured output, use schema validation and retry on failure, counting those retries in R_retry.
if success_rate < target and round < max_round:round += 1 # cost scales linearly with rounds, so enforce a hard capelse:return result
Always put a budget circuit breaker on rounds and retries so that abnormal inputs cannot drive up the bill.
6. Architecture and Observability Recommendations
Govern model calls as an external dependency: route and fall back through a unified gateway, and collect tokens, latency, success rate, and cost at the gateway layer; use a message queue to shave peaks and run deferrable tasks during off-peak windows to take advantage of segmented pricing; run load tests and batch evaluations on a container platform; and use logging services plus monitoring alerts to set cost thresholds. If your organization already uses these general capabilities on Baidu AI Cloud, model calls and the evaluation pipeline can be brought into the same observability system, which makes side-by-side comparison and capacity planning easier.
7. Conclusion
The real value of a new model release is not a unit price number, but that it forces the team to re-examine its own cost structure. Upgrade the evaluation baseline from “how much per million tokens” to “end-to-end cost and success rate of completing the task,” run a fixed test set across a full business cycle, optimize cache hit rate and call rounds first, and only then discuss model selection. That is how you arrive at a decision that is reproducible, auditable, and continuously recalibrated as the business evolves.
