LLM Selection Beyond Per-Token Price: Measuring Cost per Task
Most teams compare LLM pricing by looking at per-million-token rates, but that comparison often breaks down in practice. This article explains why unit price is a poor proxy for real cost, breaks down how input, cached input, and output tokens are billed, and shows how to calculate cost per successful task with sample Python code. It also covers efficiency-focused model trends, how to read score-versus-cost benchmark curves, hidden costs in long-horizon agent workflows, tiered model selection with routing, and the cost monitoring and governance practices needed to keep both cost and quality visible.
1. Why Unit Price Does Not Reflect Real Cost
LLM services are usually priced per million tokens, with separate rates for input, cached input, and output. Many teams compare those rates directly and conclude that “model A is cheaper than model B.” That comparison often does not hold up in engineering practice, for two reasons.
First, the same task consumes a different number of tokens on different models. A model with stronger reasoning may produce a correct answer in a short output, while another may iterate repeatedly and emit long intermediate reasoning, ending up with a higher total bill.
Second, unit price reflects only the billing rules, not result quality. If a cheaper model needs several retries to pass acceptance, the real cost of each acceptable result still goes up. Cost should therefore be measured against the total spend required to produce one acceptable result, not against the unit price.
2. Understanding the Three Token Categories
Mainstream billing typically has three parts.
Input tokens are everything sent to the model in a request: system instructions, conversation history, retrieved documents, and tool results. Longer input means higher cost.
Cached input tokens are repeated prefix content that has already been cached on the server side. When an application reuses the same system instructions or knowledge base fragments, cache hits can substantially reduce input cost. Cached input is usually priced far below regular input, so when designing prompt structure, put stable content first and variable content last to improve the cache hit rate.
Output tokens are what the model generates. In most pricing schemes the output rate is clearly higher than the input rate, because generation is computed token by token. Controlling output length is therefore one of the most direct ways to cut cost.
The table below summarizes where the cost pressure comes from for each category:
| Type | Main cost driver | Optimization direction |
|---|---|---|
| Input tokens | Context length, number of retrieved fragments | Trim context, remove irrelevant history |
| Cached input tokens | Whether the prefix is stable | Fix system instructions, reorder content |
| Output tokens | Redundancy in generated content | Constrain output format, cut unnecessary process narration |
3. Calculating Cost per Task
To compare models, the three token costs have to be rolled up to a single task. The approach: run a batch of representative tasks, record the three token counts for each task, multiply by the corresponding rates, and take the average cost per task. Then divide by the task success rate to get the cost per successful result.
The following illustrative code shows the calculation logic (the numbers are assumed and used only to demonstrate the method):
from dataclasses import dataclass@dataclassclass Pricing:input_per_m: float # price per million input tokens (USD)cached_per_m: float # price per million cached input tokens (USD)output_per_m: float # price per million output tokens (USD)@dataclassclass TaskRun:input_tokens: intcached_tokens: intoutput_tokens: intsucceeded: booldef cost_per_successful_task(pricing: Pricing, runs: list[TaskRun]) -> float:total_cost = 0.0successes = 0for run in runs:total_cost += (run.input_tokens * pricing.input_per_m+ run.cached_tokens * pricing.cached_per_m+ run.output_tokens * pricing.output_per_m) / 1_000_000successes += run.succeededif successes == 0:return float("inf")return total_cost / successes
The key part of this code is the denominator. Even if a model is cheap per call, a low success rate can still make the average cost per successful result higher. The calculation should also include human review, retries, and tool invocation costs, since those are part of completing the task as well.
4. The Value of Efficiency: Harder Tasks with Fewer Output Tokens
A number of model vendors have recently emphasized “efficiency,” meaning fewer output tokens on difficult tasks while maintaining or improving result quality. This direction has practical value for engineering teams.
Fewer output tokens means two things. It directly lowers output cost, and it shortens response time, improving the interaction experience. In agent workflows that require multiple calls, output saved at each step is amplified along the chain.
Efficiency metrics still need careful interpretation, though. Shorter output does not equal higher quality. Teams should monitor accuracy, readability, and downstream rework cost at the same time, and avoid sacrificing reliability just to compress tokens. The reasonable approach is to set a quality threshold and compare cost among options that meet it.
5. Reading Benchmark Scores and Cost Curves Correctly
More and more model evaluations present results as score-versus-cost curves. A few things to watch when reading them.
Sample scope. Whether the evaluation excluded some tasks, and why, directly affects score comparability. If a model was excluded on part of the tasks because it fell back to an alternate path, its score does not fully correspond to the same standard.
Axis selection. The horizontal range is sometimes adjusted to accommodate one high-cost point. That compresses the visual gap between other points, so read the actual numbers rather than relying on the visual impression.
Cost definition. Is cost computed per task or per call? Does it include failed retries? Does it include tool invocation costs? Different definitions can lead to completely opposite conclusions.
Task representativeness. Results on long-horizon, multi-step tasks may not match your business scenario. Evaluations should stay close to real workloads, ideally with small-scale validation on internal data.
6. Hidden Costs in Long-Horizon Tasks
Multi-step agent tasks have several cost sources that are easy to overlook.
The first is context accumulation. Each step may resend the entire prior history as input, so input tokens grow with the number of steps. The second is tool output. Search results, database queries, and file reads can return long content that stays in context and keeps being billed. The third is error recovery. Once the model fails at a step, the whole chain may need to roll back and rerun.
Common countermeasures include: periodically compressing message history and keeping only the state relevant to the current step; truncating and summarizing tool returns; setting a timeout and maximum retry count for each step; and recording failure reasons to improve prompts and workflow design.
7. Tiered Selection and Model Routing
Using a single model for everything is usually not optimal. A more robust approach is to tier by task difficulty.
- High-difficulty tasks: use the most capable flagship model for complex reasoning, critical decisions, and high-value output.
- Everyday tasks: use a cost-effective workhorse model covering most text processing, code assistance, and information organization needs.
- Simple tasks: use a lightweight model for classification, extraction, format conversion, and other work with high determinism.
The routing layer can allocate requests dynamically based on task characteristics, historical success rate, and current budget. Keep a fallback mechanism in the implementation: when the lightweight model’s confidence is insufficient, escalate automatically to a stronger model, and record the escalation ratio as a basis for evaluating the routing strategy.
8. Building Cost Monitoring and Governance
Cost governance needs data behind it. At minimum, build the following capabilities.
- Track the three token categories by project, feature, and user.
- Record the result status and retry count of each task, and compute cost per successful result.
- Set budget thresholds and anomaly alerts, for example notifying the owner when daily cost spikes beyond a certain percentage of the historical average.
- Periodically review prompt structure and check trends in cache hit rate and output length.
- After each model switch or pricing strategy change, run a regression comparison on the same batch of representative tasks.
These metrics can be implemented with common logging services, monitoring and alerting, and dashboards. The key is to make cost and quality metrics visible at the same time, rather than focusing on a single dimension.
9. Summary
Evaluating LLM cost means shifting from per-token price to the total spend per successful result. That requires distinguishing the billing differences among input, cached input, and output, measuring real task usage and success rate, and reading benchmark sample scope and cost definitions carefully. In engineering practice, combining tiered selection, context management, and continuous monitoring keeps model cost within a predictable range without compromising quality.
