How to Choose an LLM: Replace Benchmarks with Cost per Successful Task
Benchmarks and token prices alone can lead to misleading model choices. This guide shows how to calculate expected cost per successful task, account for retries and heterogeneous workloads, evaluate models with reliable samples, and build a budget-aware routing strategy that escalates failed tasks to stronger models. It also includes a Python routing framework, measurement requirements, and a practical pre-launch checklist.
Why Benchmarks and List Prices Are Not Enough
Benchmarks measure pass rates on fixed test sets, which may not resemble your production workload. List prices can also lead to poor decisions. In agentic workloads, output tokens often make up most of the bill, and output-token prices are typically several times higher than input-token prices. A model that succeeds on only 60% of tasks on the first attempt may incur substantial retry costs. A lower per-token price does not necessarily mean a lower total cost.
Prices can change as well. Many vendors offer promotional pricing when a new model launches, then adjust prices after the promotion ends. For budgeting, model costs using the standard prices shown on the official pricing page, and record the date on which you checked them.
How to Calculate Cost per Successful Task
First, define the cost of one attempt. This includes the input-token charge and the output-token charge. If the request also incurs charges for cache reads or writes, tool calls, or other billable items, include those as well. Use a consistent unit of US dollars per million tokens and divide token counts by one million during calculation.
Cost per attempt, c = input tokens × input price+ output tokens × output priceCost per successful task = c / p
Here, p is the probability that one attempt succeeds.
This formula relies on two assumptions:
- Every attempt has the same success probability, and attempts are independent.
- The costs of failed attempts are fully included in total spending.
Why the Retry Limit Does Not Change the Expected Cost
Assume that each task can be attempted at most K times. The expected number of attempts per task is:
(1 − (1 − p)^K) / p
The probability that the task eventually succeeds is:
1 − (1 − p)^K
Dividing expected attempts by the probability of eventual success gives the expected cost per successful task:
c / p
This result does not depend on K. The retry limit truncates both the number of attempts and the number of tasks that eventually succeed, so the two effects cancel out.
However, this conclusion requires three conditions.
1. The Success Rate Is the Same Across Tasks
If the workload contains several task types with significantly different success rates, do not substitute the overall average success rate into c / p. Calculate each task type separately and then weight the results by traffic.
Let:
w_ibe the traffic share of task typeic_ibe the cost per attempt for task typeip_ibe its success probabilityKbe the retry limit
Then:
Cost per successful task =Σ(w_i · c_i · E_i) / Σ(w_i · q_i)
where:
E_i = (1 − (1 − p_i)^K) / p_iq_i = 1 − (1 − p_i)^K
When all task types have the same success rate, this simplifies to c / p.
Consider two task types with equal traffic shares. For task type A, c = $0.02 and p = 0.9. For task type B, c = $0.10 and p = 0.2. With unlimited retries, the correct result is:
(0.02 / 0.9 + 0.10 / 0.2) / 2 ≈ $0.261
If you first average the costs and success rates, you get:
0.06 / 0.55 ≈ $0.109
That result underestimates the true cost by almost 60%.
2. The Cost per Attempt Is Stable
If retry prompts include error messages or previous outputs, the input grows with each attempt. The value of c then changes from one attempt to the next. In that case, replace the fixed cost with the measured average cost per attempt.
3. All Failure Costs Are Included
Timeouts, errors, and validation failures must all be counted as spending. Counting only the costs of successful tasks produces an artificially low figure.
Worked Example
The following figures are hypothetical and are included only to demonstrate the calculation. Input and output token counts represent average usage per attempt and exclude cache and tool-call charges.
| Item | Model X | Model Y |
|---|---|---|
| Input price (USD per million tokens) | 2 | 10 |
| Output price (USD per million tokens) | 10 | 50 |
| Average input / output tokens per attempt | 3,000 / 1,500 | 3,000 / 1,500 |
Cost per attempt, c |
$0.021 | $0.105 |
Success rate, p |
60% | 85% |
Cost per successful task, c / p |
About $0.035 | About $0.124 |
Under these assumptions, Model Y costs about 3.5 times as much as Model X for each successful task. Even if Y achieved a 100% success rate, its cost per successful task would still be $0.105, approximately three times X’s cost. A higher success rate can narrow the gap, but it cannot eliminate a large price difference by itself.
The opposite can also happen. On a particular task type, a more expensive model may be cheaper overall if the less expensive model fails too often. Suppose Y has a 60% success rate on this task type and a cost per successful task of $0.175. If X’s success rate falls below 12%, its cost per successful task exceeds $0.175. Y is then the more economical choice. This is the problem that model routing is designed to solve.
A Practical Evaluation Process
Sample production traffic. Stratify samples by task type and draw them from real traffic. The smaller the sample, the less stable the success-rate estimate. For example, with 50 samples and a success rate of approximately 60%, the 95% confidence interval has a half-width of about 14 percentage points under a normal approximation using the Wald method. The interval is therefore approximately 46% to 74%. This approximation can be inaccurate for small samples, so use a Wilson interval or an exact binomial interval instead. Before making a decision, increase the sample size, or treat small-sample results only as an initial screen rather than a final conclusion.
Use a fixed grading standard. Automate evaluation and count a task as successful only when all test cases pass. Record the grading-script version so that every evaluation uses the same criteria.
Test multiple reasoning levels. For every candidate model, test at least two reasoning settings. Record success rate, token usage per attempt, latency, and cost. If a higher reasoning level does not improve success rate or causes a large cost increase, return to the lower setting.
Calculate and rank. Rank candidates by cost per successful task, not by list price or benchmark score.
Every test record should include at least:
- Model identifier and version
- Test date
- Source and date of the pricing snapshot
- Sample ID
- Grading-script version
- Input and output token counts
- Whether the task succeeded
- Latency
How to Build Model Routing
A routing strategy starts with a less expensive model. After the output is automatically validated, the request is escalated to a stronger tier if validation fails. Set a maximum number of attempts for each tier and a per-task spending limit to prevent difficult tasks from consuming unlimited budget.
The initial tier can be selected using features such as task type and input length. These rules should be calibrated against offline evaluation data.
The following code provides a usable framework. You must implement call_model. On timeout or error, it should raise CallFailed and include any cost already incurred.
import loggingimport timeTIERS = ["cheap-model", "flagship-medium", "flagship-high"] # Ordered from lowest to highest priceMAX_ATTEMPTS_PER_TIER = 2BUDGET_PER_TASK_USD = 0.50 # Per-task spending limit; escalate to human review when exceededRULE_VERSION = "route-v1" # Routing-rule version for log analysislog = logging.getLogger("router")class CallFailed(Exception):"""Model call timed out or failed. The exception must include the incurred cost."""def __init__(self, cost: float):super().__init__(f"model call failed, cost={cost:.4f}")self.cost = costclass NeedsHuman(Exception):"""No validated result was obtained; send the task for human handling."""def __init__(self, reason: str, spent: float):super().__init__(f"{reason}, spent={spent:.4f}")self.reason = reasonself.spent = spentdef estimate_start_tier(task) -> int:"""Return the starting tier. 0 is the least expensive tier.The rules must be calibrated with offline evaluation data."""if task.kind in {"doc_extract", "format_convert"}:return 0if task.input_tokens > 50_000 or task.kind == "multi_file_refactor":return 2return 1def run_with_routing(task, call_model, validate):"""Return (result, total_cost_for_task).call_model(model, task) -> (result, cost); raises CallFailed on timeout or error.validate(result, task) -> bool; returns whether automatic validation passed."""spent = 0.0 # Accumulated across all tiers; failed attempts are includedtier = estimate_start_tier(task)while tier < len(TIERS):model = TIERS[tier]for attempt in range(1, MAX_ATTEMPTS_PER_TIER + 1):if spent >= BUDGET_PER_TASK_USD:raise NeedsHuman("budget_exceeded", spent)start = time.monotonic()try:result, cost = call_model(model, task)ok = validate(result, task)status = "pass" if ok else "validation_failed"except CallFailed as exc:cost, ok, status = exc.cost, False, "call_failed"latency_ms = (time.monotonic() - start) * 1000spent += costlog.info("task=%s rule=%s tier=%d model=%s attempt=%d status=%s cost=%.4f latency_ms=%.0f",task.id, RULE_VERSION, tier, model, attempt, status, cost, latency_ms,)if ok:return result, spenttier += 1 # Escalate after exhausting the attempts for the current tierraise NeedsHuman("all_tiers_exhausted", spent)
There are several details to note:
- The budget is checked before each call, so actual spending can exceed the limit by the cost of one call.
- If the limit must be strict, reserve the worst-case call cost before making the request.
- The caller should catch
NeedsHuman, send the task for human handling, and writespentto the billing record.
Calibrating Routing Rules Offline
Use historical labeled data to calculate the first-pass success rate and cost per successful task for each tier. Use these results to determine the rules for selecting the starting tier.
After changing the rules, rerun the evaluation on a retained test set. Compare cost per successful task and the rate of escalation to human handling. If the escalation rate increases beyond your chosen threshold, roll back to the previous rule version.
Write the rule version to every log entry so that routing behavior can be traced later.
Recommended observability fields include:
- Task ID
- Rule version
- Tier
- Model
- Attempt number
- Validation status
- Cost per attempt
- Latency
- Whether the task was ultimately sent for human handling
With these fields, you can investigate why a task type is frequently escalated or why a particular tier consumes budget without producing passing results.
Model Selection Checklist
Before launching or replacing a model, verify each item:
- The pricing snapshot includes its source and lookup date and uses standard rather than promotional pricing.
- The model version is recorded and matches the version used during testing.
- The grading-script version is recorded, and every candidate uses the same version.
- The sample size is sufficient, confidence intervals for success rates have been calculated, and interval width is considered in the decision.
- Every candidate model has been tested at at least two reasoning levels, with cost and success rate recorded.
- Costs from failed retries are included in cost per successful task.
- A per-task budget limit is configured, with a defined process for human escalation.
- Data privacy and compliance requirements have been reviewed, including whether the data may be sent to the vendor and whether cross-border transfer is involved.
- A rollback plan is ready, and the previous model configuration can be restored online.
Common Misjudgments
- Looking only at benchmark scores. A benchmark may not cover your production scenarios. Evaluate models on your own representative samples.
- Looking only at list prices. Output tokens often account for most of the bill, and retries can multiply the actual cost.
- Ignoring output tokens. Output-token prices are often much higher than input-token prices. Estimating input costs alone can substantially understate spending.
- Modeling with promotional prices. Prices may rise after a promotion ends. Use standard pricing for budgets.
- Drawing conclusions from a small sample. Small samples produce wide confidence intervals, and an apparent difference between two models may be random variation.
