Evaluating LLM Inference Cost: What to Look at Beyond Token Pricing
Token price alone does not determine inference cost. This article explains how to evaluate LLM inference using cost per unit of valid output, combining throughput, latency percentiles, and effective output rate. It covers prefill and decode performance, load testing methods, billing and caching factors, task tiering and routing, hidden costs from retries and rate limits, and observability practices for sustainable cost control. The goal is to turn the question "is it expensive" into a measurable comparison under fixed business constraints.
1. Define the Problem First: Unit Price Is Not Cost
Discussions like “the new-generation model costs several times more per token than the previous flagship—is it expensive?” rarely converge because they treat the per-token price as the cost itself. Unit price is only one multiplier in the bill. The real cost is:
Cost per unit of valid output = Total cost / Valid output that passes validationTotal cost ≈ (Input tokens × Input price + Output tokens × Output price) × Retry factor + Fixed and operational overhead
As long as the denominator (valid output) grows faster than the numerator (cost), a higher unit price can actually be cheaper. Any evaluation must therefore measure three things at the same time: throughput, latency distribution, and effective output rate.
2. Throughput and Latency: Turning “Fast” into Measurable Metrics
Generative inference time consists of two phases: prefill and decode. The prefill phase processes the input in parallel, and its compute grows with input length. The decode phase generates tokens autoregressively one by one and is mainly constrained by memory bandwidth. If a new-generation model significantly improves output speed, it can serve more concurrent requests per unit of time, allowing the same hardware and quota to support more workloads.
Metrics that must be measured rather than guessed include:
- Output throughput (tokens generated per second) and time to first token;
- Latency percentiles (P50/P95/P99) at the target concurrency, not averages;
- Performance differences between two extreme workloads: long input with short output, and short input with long output.
A sample load-testing skeleton (pseudocode, only expressing the measurement approach):
def bench(client, prompt, max_tokens, concurrency):results = []with ThreadPool(concurrency) as pool:for _ in range(N):pool.submit(one_request, client, prompt, max_tokens, results)return summarize(results) # throughput, P95 latency, failure ratedef one_request(client, prompt, max_tokens, results):t0 = now()stream = client.stream(prompt, max_tokens=max_tokens)first = Nonefor chunk in stream:if first is None:first = now() # time to first tokenresults.append((first - t0, now() - t0, count_tokens(chunk)))
A common misconception is “compare only the high-throughput versions in the same tier.” A more rigorous approach is to fix the business constraints (latency ceiling, concurrency ceiling) and then compare how many valid requests per second each option can support under those constraints.
3. Billing and Caching: Bill Structure Determines Optimization Focus
Services differ widely in the pricing ratio between input and output tokens, cache-hit discounts, batch channels, and reserved capacity. The optimization order should be:
- Compress the input: trim system prompts, cut retrieved snippets, and deduplicate conversation history;
- Improve cache hits: place stable prefixes (guidelines, tool descriptions, examples) at the very front of the prompt so prefix caching can be reused;
- Control output length: use structured constraints and explicit stop conditions instead of “be as detailed as possible”;
- Batch and make asynchronous: send offline tasks through lower-priority channels, isolated from the online path.
Optimized cost ≈ Input tokens × (1 - hit rate) × Input price + Output tokens × Output price
4. Task Tiering and Routing: Not Every Request Needs the Flagship
Tiering requests by difficulty is the most effective architectural lever for cost control: route simple classification, extraction, and formatting to small models or rules; route complex reasoning and long-form writing to high-capability models; when necessary, let the upstream perform intent recognition and confidence scoring, and escalate only low-confidence cases.
def route(task):if task.kind in ("classify", "extract", "format"):return small_modelif task.risk == "high" or task.complexity >= 3:return flagship_modelreturn mid_model
Combined with a “small first, then large” cascade strategy and result validation (rule-based checks, a second model review), this can reduce average cost without sacrificing quality.
5. Capacity, Rate Limiting, and Stability: Overlooked Hidden Costs
A higher-priced option with more generous quota and more stable rate limiting can reduce retry rates and queue timeouts. Hidden costs include: duplicate billing from failed retries, business degradation caused by rate limiting, and user experience loss from cold starts and long-tail latency. The total cost model should include the retry factor, failure rate, and number of degradation events, rather than only the listed price.
6. Observability and Governance: Making Cost Sustainable
It is recommended to build three dashboards: a usage dashboard (tokens and cost broken down by business line or scenario), a quality dashboard (effective output rate, manual rework rate, validation pass rate), and a performance dashboard (throughput and latency percentiles). Also set budget alerts, per-scenario quotas, prompt version management, and a regression evaluation set to avoid cost drift from prompt bloat and arbitrary model switching.
7. Conclusion: Reframe “Is It Expensive” into a Verifiable Question
A several-fold difference in unit price is not a conclusion by itself. If the new-generation option improves effective throughput several times under the same concurrency and latency constraints, and caching, batching, and routing can be stacked together, the cost per unit of valid output can be lower. The practical recommendation is: first define business-level latency and quality thresholds, then use a unified load-testing script to collect throughput and percentile data, and finally use “cost per unit of valid output” as the single comparison metric. If you need to host these inference services with logging, monitoring, and elastic scaling, you can use the general cloud infrastructure offered by Baidu AI Cloud to complete capacity planning and cost attribution based on your own workload characteristics.
