Evaluating LLM Inference Cost: What Matters Beyond Per-Token Pricing
This article explains why per-token price is only one factor in LLM inference cost and introduces cost per effective output as a more practical metric. It breaks down four hidden cost dimensions—throughput and concurrency, latency structure, first-pass success rate, and engineering overhead—and outlines a reusable evaluation workflow with sample Python snippets for percentile latency, output validation, and cost calculation. The goal is to help teams compare model tiers using workload data rather than price lists alone.
1. Framing the Question Correctly: From Price Comparison to Cost per Effective Output
Before deciding whether a new flagship model is expensive because its pricing is roughly 2.5 times that of the previous flagship generation, one premise needs to be clear: the per-token price is only one factor in the cost formula, not the cost itself.
In engineering practice, a more realistic metric is the cost per effective output, which can be roughly expressed as:
cost per effective output = (input token price × input volume + output token price × output volume)÷ (successful output volume × business value per output)
This formula makes three points. First, the output price is usually significantly higher than the input price, so scenarios with a high share of output tokens are more sensitive to price changes. Second, the “successful output volume” in the denominator means that retries, timeouts, and format violations can multiply the actual cost. Third, when the business value differs, the same price can lead to completely different cost-effectiveness conclusions.
For this reason, the intuition that “it actually costs less in practice” is mathematically sound: if a new-generation model delivers lower time to first token, higher output throughput, and a better first-pass success rate on the same tasks, the denominator may grow faster than the numerator.
2. Four Cost Dimensions Hidden by Per-Token Pricing
2.1 Throughput and Concurrency: How Much Compute You Actually Get
The same statement—“how much per million tokens”—can correspond to very different real costs at different throughput levels. If one configuration’s output speed is only one-third of another’s, then under a fixed concurrency limit, the number of requests completed per unit of time is also roughly one-third. To reach the same business peak, you need to multiply concurrency quotas and queue waiting time.
When evaluating throughput, focus on three measures: output tokens per second (TPS), time to first token (TTFT), and the throughput degradation curve under high concurrency. A low latency at a single point is meaningless; look at P95 and P99 percentiles.
2.2 Latency Structure: TTFT and TPS Carry Different Weights
Conversational and streaming scenarios are extremely sensitive to time to first token, while batch processing, code generation, and long-form rewriting depend more on overall completion time. A common mistake is making decisions based on average latency; percentiles are what actually matter:
# Example: percentile summary for model selection comparisonsimport statisticsdef summarize(latencies_ms):ordered = sorted(latencies_ms)p = lambda q: ordered[min(len(ordered) - 1, int(len(ordered) * q))]return {"count": len(ordered),"p50": p(0.50),"p95": p(0.95),"p99": p(0.99),"mean": round(statistics.mean(ordered), 1),}
2.3 First-Pass Success Rate: The Most Overlooked Multiplier
If a model’s structured output requires manual rework or a second call to fix, the real cost must be multiplied by 1 / success rate. Raising the success rate from 70% to 90% is equivalent to reducing cost by about 22%, which is often enough to offset a several-fold difference in per-token price.
Measuring the success rate requires executable criteria, such as parseable JSON, complete fields, passing unit tests, or compilable code:
def is_valid_json(text: str) -> bool:import jsontry:json.loads(text)return Trueexcept json.JSONDecodeError:return False
2.4 Engineering Overhead: Retries, Caching, and Observability
A higher-priced option may come with more mature streaming interfaces and more stable rate-limiting policies, which simplifies compensation logic on the engineering side. Conversely, choosing an unstable tier to lower the per-token price often requires extra investment in retry queues, idempotency design, and fallback paths. These hidden labor costs do not appear on the bill, but they are real.
3. A Reusable Model Selection and Evaluation Workflow
- Build an evaluation set of 100–300 real business samples covering three distributions: long input with short output, and strongly structured output.
- Run load tests at fixed concurrency levels (for example, 1/5/20/50) and record TTFT, TPS, and error rate for each.
- Calculate the cost per effective output for each configuration instead of comparing per-token prices.
- Add a caching layer to reuse results for high-frequency repeated prefixes and further amortize cost.
- Set up online monitoring and alerting to continuously track percentile latency and failure rate, preventing cost drift after launch.
Example calculation script:
def effective_cost(input_price, output_price, in_tok, out_tok,success_rate, cache_hit=0.0):billable_in = in_tok * (1 - cache_hit)cost = (input_price * billable_in + output_price * out_tok) / 1_000_000return cost / max(success_rate, 1e-6)
4. Conclusion
“2.5 times more expensive” is a number stripped of context. If a new flagship tier improves output throughput, percentile latency, and first-pass success rate at the same time, its cost per effective output may well be lower than that of the previous generation—especially in output-heavy, concurrency-sensitive, stability-critical workloads. Conversely, if the workload mainly involves short inputs and short outputs, runs as offline batch processing, and is insensitive to latency, choosing a more economical tier is the rational decision.
In related practice at Baidu AI Cloud, the recommendation is to bring model selection into a unified inference gateway with monitoring and alerting, and to make decisions with data rather than price tables: first quantify the workload distribution, then load-test percentile performance, and finally calculate the cost per effective output. This turns the debate over whether a model is “expensive” into a verifiable engineering conclusion.
