Why LLM Model Selection Should Go Beyond Unit Price: Evaluate Cost and Quality per Task
Unit pricing alone does not reveal the true cost of using a large language model. This article explains how to evaluate models based on token consumption, context and cache design, retries, task success rates, latency, and cost per successful task. It also presents a practical evaluation framework and shows how Pareto frontiers can identify models that offer the best trade-off between performance and cost.
1. Why Unit Price Does Not Represent the True Cost
Large language model services are typically billed by token. Pricing tables usually list separate rates for input tokens, cached input tokens, and output tokens. Many teams compare these figures directly when selecting a model, but the conclusion often differs from the actual bill.
The reason is that the same task may consume different numbers of tokens, require different numbers of calls, and trigger different numbers of retries on different models. A model with a lower unit price may require repeated trial and error, making its total cost for the same task higher.
Model evaluation should therefore shift from unit price to cost per task. A simplified calculation is:
Cost per task = input cost+ cached input cost+ output cost+ tool invocation cost+ failed retry overhead
Input cost equals the number of input tokens multiplied by the input price. The other components can be calculated in the same way.
The following variables are especially easy to overlook:
- Context length. In multi-turn conversations or multi-step tasks, historical content accumulates, causing input token usage to grow with each step.
- Output length. Some models tend to provide more detailed explanations, which can significantly increase output token usage.
- Failed retries. When a task fails and is executed again, all previous consumption still contributes to the total cost.
- Cache hit rate. Placing stable system instructions and tool definitions at the beginning of a request can improve prefix cache hits and reduce input costs.
The following fictional example illustrates the calculation. These figures are for demonstration only and do not represent the pricing of any real product.
Assume Model A charges $2 per million input tokens and $8 per million output tokens. It uses 200,000 input tokens and 20,000 output tokens to complete a task:
Input cost: 200,000 / 1,000,000 × $2 = $0.40Output cost: 20,000 / 1,000,000 × $8 = $0.16Total cost: $0.56
Model B charges $8 per million input tokens and $32 per million output tokens—four times the unit price of Model A. However, it completes the same task with only 40,000 input tokens and 4,000 output tokens:
Input cost: 40,000 / 1,000,000 × $8 = $0.32Output cost: 4,000 / 1,000,000 × $32 = $0.128Total cost: approximately $0.448
Model B is therefore cheaper for this task despite its higher unit price.
The example shows that unit price is only one input to the cost calculation. To determine which model is more economical, teams must consider the actual token consumption required to complete the task.
2. Context and Cache Design
Cached input is usually priced lower than regular input, but this benefit generally depends on the request prefix being exactly the same. Prompt structure therefore has a direct impact on cost.
Three practical guidelines are useful:
- Put stable content first, including system instructions, role definitions, and tool descriptions.
- Put dynamic content later, including user input, retrieved results, and the current state.
- Avoid inserting timestamps, random IDs, or other fields that change on every request into the prefix.
For example:
def build_request(system_prompt, tool_schemas, history, user_input):# Place stable content first to improve prefix cache hitsprefix = [system_prompt, tool_schemas]# Place dynamic content laterreturn prefix + history + [user_input]
For very long multi-turn histories, earlier conversations can also be periodically compressed into summaries. Summarization reduces input token usage, but it may remove important details. The evaluation process should therefore verify whether task success rates decline after compression.
3. Why Long-Running Tasks Require Separate Evaluation
Single-turn question-answering benchmarks cannot fully represent the capabilities required for multi-step work. Long-running tasks commonly involve reading requirements, planning steps, calling tools, checking intermediate results, handling errors, and maintaining state across a large context.
An evaluation set must cover these stages. Otherwise, its scores may not reflect real-world performance.
The following metrics are particularly useful:
- Task completion rate: Determine success using verifiable completion conditions rather than subjective judgment.
- Average number of steps and tool calls: Reflect task complexity and execution efficiency.
- Number of human interventions: Indicate how much follow-up correction is required.
- Failure-type distribution: Distinguish between comprehension errors, tool invocation errors, timeouts, and output-format errors.
- Cost and latency per task: Track them separately, and calculate the cost of each successful task.
- Result variance: Run the same task multiple times to measure stability and fluctuations.
A common data-processing issue occurs when some tasks are switched to another model because of service failures. The results from those tasks should not be counted toward the original model’s performance. If such samples are excluded, the report must state how many were removed and why. It should also provide results that include the complete sample set.
Reporting only the results after exclusions can overstate the evaluated model’s performance and distort the comparison.
4. Building an Evaluation Framework
An evaluation framework generally consists of five steps:
- Define the task set.
- Standardize the execution environment.
- Record usage data.
- Calculate cost metrics.
- Produce comparative results.
Step 1: Define the Task Set
The task set should cover the primary scenarios found in real business operations and should label each task by difficulty and type. It should also be version-controlled, with every change recorded.
Step 2: Standardize the Execution Environment
Temperature settings, tool lists, timeouts, maximum step counts, and prompt templates should remain consistent. Otherwise, comparisons between models will not be meaningful.
Step 3: Record Usage Data
For every run, store the number of input tokens, cached input tokens, and output tokens, along with the number of tool calls and execution time.
Step 4: Calculate Cost Metrics
The following code provides a simplified implementation:
from dataclasses import dataclass@dataclassclass RunRecord:model: strtask_id: strsuccess: boolinput_tokens: intcached_input_tokens: intoutput_tokens: intprice_in: float # Price per million input tokensprice_cached: float # Price per million cached input tokensprice_out: float # Price per million output tokensattempts: int # Actual number of attemptsdef task_cost(r: RunRecord) -> float:uncached = r.input_tokens - r.cached_input_tokensper_attempt = (uncached * r.price_in+ r.cached_input_tokens * r.price_cached+ r.output_tokens * r.price_out) / 1_000_000# Assume similar consumption for each attempt for a rough estimatereturn per_attempt * r.attemptsdef summarize(records):by_model = {}for r in records:by_model.setdefault(r.model, []).append(r)result = {}for model, rs in by_model.items():n = len(rs)successes = sum(r.success for r in rs)total_cost = sum(task_cost(r) for r in rs)result[model] = {"success_rate": round(successes / n, 3),"cost_per_task": round(total_cost / n, 4),# Includes failure-related waste in the cost of each successful task"cost_per_success": round(total_cost / max(1, successes), 4),}return result
The cost per successful task is one of the most important metrics. It includes the waste caused by failures and is therefore closer to actual spending than a simple comparison of average unit prices.
Step 5: Produce Comparative Results
The results should include performance scores, costs, latency, and failure types. This gives decision-makers a clearer view of the trade-offs between models.
5. Plotting Performance and Cost Curves
Performance-versus-cost curves are a common way to compare multiple models. The horizontal axis represents cost per task, while the vertical axis represents task performance. A point closer to the upper-left corner generally indicates a better cost-performance trade-off.
The Pareto frontier is an important concept in this analysis. If Model X has a score no lower than Model Y while costing less, Model Y is dominated by Model X for the selected metrics and should not be considered the optimal choice.
All non-dominated points form the Pareto frontier. These are the candidates that are genuinely worth considering.
def pareto_front(points):# points: [(name, score, cost), ...]front = []for name, score, cost in points:dominated = any(score2 >= scoreand cost2 <= costand (score2 > score or cost2 < cost)for _, score2, cost2 in points)if not dominated:front.append((name, score, cost))return front
Using this approach, teams can avoid selecting a model solely because of its low listed price. A more reliable decision combines task success, token consumption, retry behavior, latency, and cost per successful task.
