Evaluating LLM Costs: Per-Task Cost Accounting Beyond Token Pricing
Token unit prices alone can mislead model selection decisions. This article explains how to calculate per-task cost using token consumption and success rates, why output tokens are the biggest cost amplifier, how parameter scale relates to inference efficiency, how to interpret benchmark scores, and provides Python code for computing cost per task and cost per successful task, along with practical recommendations for production deployment.
1. Why Token Unit Prices Alone Can Mislead Cost Estimates
LLM services typically bill input tokens and output tokens separately, quoting a price per million tokens. This pricing model makes comparison easy, but it creates an illusion: a lower unit price means a lower total cost.
In real-world workloads, cost depends on how many tokens a task actually consumes. If one model charges $10 per million tokens but needs three times the output volume of another model to complete the same task, its per-task cost may end up higher. Unit price is only one coefficient in the cost formula; the other two are the number of tokens consumed per task and the quality of task completion.
Therefore, when selecting a model, the comparison should shift from “how much per million tokens” to “how much to complete one valid task.”
2. The Basic Formula for Per-Task Cost
Per-task cost can be expressed as:
Per-task cost = average input tokens × input price + average output tokens × output price
Prices are quoted per million tokens, so divide by 1,000,000 during calculation. Note that average output tokens should include the reasoning tokens a model generates during inference. If the billing rules count these tokens as output but your statistics only capture the visible response text, costs will be systematically underestimated.
In most business scenarios, input token counts are relatively stable—for example, the system prompt plus the user question has a roughly fixed length. Output token counts fluctuate much more, influenced by task difficulty, prompt constraints, the model’s verbosity habits, and reasoning strategy. This is the variable that deserves the most attention in cost accounting.
3. Output Token Volume: An Easily Overlooked Cost Amplifier
Output tokens are generally priced significantly higher than input tokens. In common pricing structures, the output price may be several times the input price. This means that generating one thousand extra output tokens usually has a greater impact on total cost than sending one thousand extra input tokens.
High output volume typically stems from three causes:
- Longer reasoning processes: Reasoning-capable models generate internal thinking content before answering. The more thorough the reasoning, the more output is produced, increasing both latency and cost per call.
- Verbose expression: Responses containing repetitive explanations, excessive preamble, or unnecessary formatting markup all inflate token counts.
- Unconstrained output length: If the prompt does not explicitly limit length, the model may produce content beyond what the task requires.
To address these causes, you can take the following measures:
- Specify output format and length limits in the prompt, such as requesting only structured fields;
- Disable or reduce reasoning intensity for simple tasks, reserving complex reasoning for scenarios that genuinely need it;
- Set a reasonable maximum output token parameter to prevent abnormal output from causing runaway costs;
- Use caching for repetitive system prompts to reduce redundant input-side overhead.
4. The Relationship Between Parameter Scale and Inference Efficiency
Parameter count is often used as a rough proxy for cost and capability. Two concepts need to be distinguished here: total parameters determine the model’s storage footprint, while activated parameters determine how many parameters actually participate in a single forward computation.
Models using a mixture-of-experts architecture activate only a subset of expert networks per inference. As a result, a model with a very large total parameter count may have far fewer activated parameters. Fewer activated parameters generally means lower theoretical compute cost per call, which helps improve inference throughput.
However, activated parameter count cannot be directly converted into price. A provider’s pricing also depends on hardware configuration, batching strategy, scheduling efficiency, cache hit rates, and commercial strategy. Cost judgments should therefore be based on actual billing data and measured results, not inferred from parameter scale alone.
More importantly, inference efficiency should be measured by “the number of tokens needed to complete a task.” A model with fewer activated parameters may not end up cheaper if it needs to generate more tokens to reach a correct answer. Conversely, a larger model that completes tasks via shorter reasoning paths may deliver more competitive per-task costs.
5. How to Interpret Composite Benchmark Scores
Composite evaluation indices are typically derived by weighting or averaging multiple sub-benchmarks, covering dimensions such as coding, mathematics, knowledge QA, and instruction following. They are useful for initial filtering, but have several limitations:
- Two models with the same composite score may have completely different strengths and weaknesses across sub-items;
- The distribution of evaluation sets may differ significantly from your own business data;
- Evaluations are usually run under fixed reasoning settings, while real-world deployment configurations change both performance and cost;
- Scores may not reflect output length or latency.
A more practical approach is to plot cost against quality. Put per-task cost on the horizontal axis and task success rate on the vertical axis. Comparing cost at the same quality threshold, or comparing quality at the same budget, usually yields more reliable conclusions than looking at composite scores alone.
6. Computing Per-Task Cost and Effective Cost in Code
The following example shows how to combine pricing, token statistics, and success rates into comparable metrics. The values are hypothetical and used only to demonstrate the calculation; they do not represent the performance of any real model.
from dataclasses import dataclass@dataclassclass ModelPricing:name: strinput_price: float # Price per million input tokens, in USDoutput_price: float # Price per million output tokens, in USD@dataclassclass TaskStats:avg_input_tokens: int # Average input tokens per taskavg_output_tokens: int # Average output tokens per task, including reasoning tokenssuccess_rate: float # Task success rate, between 0 and 1def cost_per_task(pricing: ModelPricing, stats: TaskStats) -> float:"""Average cost per task."""input_cost = stats.avg_input_tokens * pricing.input_priceoutput_cost = stats.avg_output_tokens * pricing.output_pricereturn (input_cost + output_cost) / 1_000_000def cost_per_success(pricing: ModelPricing, stats: TaskStats) -> float:"""Effective cost per successful task. Failed tasks still incur cost."""if stats.success_rate <= 0:raise ValueError("Success rate must be greater than 0")return cost_per_task(pricing, stats) / stats.success_rateif __name__ == "__main__":model_a_price = ModelPricing("Model A", input_price=1.0, output_price=4.0)model_a_stats = TaskStats(avg_input_tokens=3000, avg_output_tokens=40000, success_rate=0.80)model_b_price = ModelPricing("Model B", input_price=2.0, output_price=10.0)model_b_stats = TaskStats(avg_input_tokens=3000, avg_output_tokens=20000, success_rate=0.85)for pricing, stats in [(model_a_price, model_a_stats), (model_b_price, model_b_stats)]:task_cost = cost_per_task(pricing, stats)success_cost = cost_per_success(pricing, stats)print(f"{pricing.name}: cost per task ${task_cost:.4f}, "f"cost per successful task ${success_cost:.4f}")# Output:# Model A: cost per task $0.1630, cost per successful task $0.2038# Model B: cost per task $0.2060, cost per successful task $0.2424
This code illustrates three key points. First, unit prices only become meaningful when multiplied by token statistics. Second, output tokens typically carry far more weight than input tokens, so the accuracy of output statistics directly determines the accounting result. Third, the success rate amplifies the cost of failed tasks—if you only count the cost of successful tasks, the conclusion will be overly optimistic.
7. Practical Recommendations
Build your own evaluation set. Extract representative tasks from real business scenarios, covering simple, medium, and difficult levels, and define clear success criteria for each task. Public benchmark scores can serve as a reference, but final decisions should be based on your own data.
Continuously record token usage. Log input tokens, output tokens, and reasoning tokens for every request in the call chain, and aggregate them by task type, model version, and time dimension. Without this data, you cannot determine why costs change.
Route requests by difficulty. Use lower-cost configurations for simple tasks and invoke high-capability, high-reasoning-intensity configurations only for complex tasks. The routing strategy needs to be validated through evaluation to avoid degrading overall quality.
Set budgets and alerts. Define thresholds for per-task cost, daily average cost, and per-user cost, triggering alerts or throttling when exceeded. Abnormal growth in output length is often an early sign of runaway spending.
Track version and pricing changes. Model version updates, pricing adjustments, or changes in reasoning strategy can all alter the cost structure. Re-run your evaluation set and update the cost comparison table after each change.
Monitor latency alongside cost. The more output tokens generated, the longer the end-to-end latency. For interactive scenarios, balance cost, quality, and response time, and record time-to-first-token and full response time separately.
The core of LLM cost accounting is comparing unit price, token consumption, and task success rate within a single metric system. Only then can model selection conclusions reflect real business expenditure.
