LLM Inference Cost: A Practical Benchmarking and Model Selection Guide
Comparing model prices per million tokens is misleading because real inference cost is a product of multiple variables, including input/output pricing, request lengths, cache hit rate, the number of rounds per task, time-of-day billing, and retries. This guide presents a reusable cost model and a measurement framework for evaluating LLM inference costs: how to instrument per-model and per-task metrics, optimize prefix cache hit rates, control round amplification through task tiering and early stopping, shift deferrable workloads out of peak windows, and run A/B tests using cost per valid output rather than cost per token. It also covers engineering details such as output length control, prompt versioning, failure budgets, observability, and elastic deployment, along with a practical rollout checklist.
1. Why Per-Token Price Comparisons Usually Lead to the Wrong Conclusion
Within the same week, two cloud providers released small inference models aimed at high-concurrency scenarios, and the community was immediately flooded with “cost per million tokens” comparison charts. The flaw in these comparisons is that they reduce inference cost to a one-dimensional scalar, while a real bill is the product of several variables.
The actual cost of any production inference request is determined jointly by at least the following factors:
- The pricing structure for input and output tokens (which often differ by several times);
- The average input length and output length per request;
- The cache (prefix reuse) hit rate, which directly determines how many input tokens are billed at a discounted rate;
- The number of rounds required to reach the target accuracy, i.e., how many requests a single business question is split into;
- Billing granularity and time-of-day pricing, such as the difference between peak and off-peak periods;
- Hidden calls caused by failed retries, timeout replays, and rate-limit backoff.
Ignore any factor beyond the first three, and the credibility of the comparison decays quickly. Therefore, this article does not declare “which one is cheaper.” Instead, it provides a measurement framework that lets the conclusion emerge on its own.
2. Building a Reusable Cost Model
Let the total cost of a single business task be C. It can be approximated as:
C = N_round × [ (L_in × (1 - h) × P_in) + (L_in × h × P_cache)+ L_out × P_out ] × (1 + r_retry)
Here, N_round is the number of rounds needed to complete the task, L_in / L_out are the average input/output lengths, h is the cache hit rate, P_in / P_cache / P_out are the corresponding unit prices, and r_retry is the retry rate.
This equation shows three things. First, output price sensitivity is usually higher than input sensitivity, because output length cannot be compressed and is billed at full price. Second, the benefit of cache hit rate is bounded by the input share: the lower the input share, the harder it is for caching to become a decisive factor. Third, rounds are a multiplier, so any “cheaper per round” advantage can be canceled out by an increase in rounds.
From an engineering standpoint, it is advisable to instrument and report all of these metrics, forming a cost dashboard aggregated by model, by business line, and by time period, rather than reverse-engineering from the month-end bill.
3. Cache Hit Rate: The Most Overestimated Discount
A high cache hit rate usually depends on a stable prefix: a fixed system prompt, fixed tool descriptions, and fixed few-shot examples. Once you insert a timestamp, random ID, or username at the top of the prompt, the prefix mismatches and the hit rate drops off a cliff.
The actionable optimization order is:
- Split the prompt into a “stable prefix + variable suffix,” placing all dynamic content at the end;
- Keep long documents and knowledge snippets in a stable position, avoiding reordering on every call;
- Control session lifetime to avoid frequent cold starts;
- Treat hit rate as a first-class metric in monitoring, displayed on a dashboard alongside accuracy.
Note that different services differ in cache granularity, invalidation rules, and discount ratios. You must run your own tests based on each provider’s official documentation and cannot rely on rules of thumb.
4. Round Amplification: The Hidden Bill Behind Higher Accuracy
To make a model more reliable on complex tasks, a common approach is to let it try multiple times, self-check, or vote across multiple paths. This yields marginal accuracy gains but pushes N_round from 1 to 3 or even 5. If a single round is 30% cheaper but the number of rounds triples, the total cost actually rises.
A more rational approach is task tiering:
- High-certainty tasks (summarization, classification, format conversion): single round, low temperature, multi-path sampling disabled;
- Medium-complexity tasks (structured extraction, code completion): single round plus one rule-based validation;
- High-uncertainty tasks (complex reasoning, long-form rewriting): allow multiple rounds, but set a round cap and confidence-based early stopping.
Illustrative early-stopping logic:
def run_with_early_stop(prompt, max_rounds=3, threshold=0.9):best, best_score = None, 0.0for _ in range(max_rounds):out = call_model(prompt) # Unified inference call wrapperscore = evaluate(out) # Rule validation or lightweight judgeif score > best_score:best, best_score = out, scoreif best_score >= threshold:breakreturn best, best_score
5. Time-of-Day Scheduling: Moving Deferrable Tasks Out of Peak Hours
If a service uses time-of-day billing, the optimization space shifts from “switching models” to “shifting time.” Batch tasks (content summarization ingestion, index building, offline labeling) are naturally deferrable and suitable for off-peak windows, while online interactive paths must stay in peak hours.
A simplified scheduling rule:
if task is deferrable and currently in peak hours:enqueue and wait for the off-peak windowelse:execute immediately
Combined with queue-based peak shaving, concurrency limits, and a timeout-retry budget, this can significantly reduce average cost without sacrificing the online experience.
6. Replacing Intuition with A/B Testing
Conclusions must come from data. It is recommended to run a controlled comparison in the same environment for more than a week:
- Fixed evaluation set: covering long input, short input, output-heavy, and multi-round samples;
- Fixed metrics: task success rate, human spot-check quality score, cache hit rate, average rounds, and cost per task;
- Fixed traffic split: segmented by business line to avoid sample bias;
- A unified call wrapper, so switching models changes only configuration, not business code.
Configuration example (illustrative)model_route:online: {provider: A, timeout_ms: 800, max_rounds: 1}offline: {provider: B, timeout_ms: 5000, max_rounds: 3}
After a week, use “cost per unit of valid output” rather than “cost per token” as the sole deciding metric, i.e., total cost divided by the number of outputs that pass validation.
7. Often-Overlooked Engineering Details
- Output length governance: use explicit word-count and structure constraints to compress L_out; the payoff is often greater than switching models;
- Prompt versioning: prompt changes must be recorded, otherwise cost fluctuations cannot be attributed;
- Failure budget: set an upper limit on retries to avoid avalanche-style repeated billing;
- Observability: logging and monitoring alerts must cover token usage, latency percentiles, and error rates;
- Elasticity and isolation: deploy online and offline paths in separate pools, scale container platforms on demand, use object storage for cold data, and use message queues for peak shaving.
8. Rollout Checklist
- Instrument first, optimize later: without per-item metering, there is no credible comparison;
- Calculate rounds before unit price: the multiplier takes priority over the discount;
- Fix output before input: output is billed at full price, so the compression room is largest;
- Tier first, unify later: different tasks follow different routing and round strategies;
- Test first, decide later: re-evaluate on a rolling weekly basis, since both models and prices change.
9. Conclusion
The model unit price is only one factor in the bill. What truly determines cost is the combination of “rounds × length × hit rate × time period.” Treating cost as an engineering metric that requires continuous measurement, rather than a one-time procurement comparison, is the only way to achieve a stable and explainable balance among quality, latency, and budget. If an enterprise wants to host model routing, elastic compute, and full-chain observability in its own environment, it can build the metering and scheduling system described above on top of the relevant general cloud product capabilities from Baidu AI Cloud.
