Sub topic 13
Judging models by cost per resolved task
This chapter assumes you have read the earlier chapters on token pricing, agent loop cost and model tiers. It also assumes you can read short Python functions and JSON usage records. Here you stop comparing models by their price list and start comparing them by what a finished piece of work costs.
Why price per token misleads
A price list gives you dollars per million input and output tokens. That number says nothing about how many tokens a model needs to finish a task, or how often it finishes at all. Three things sit between the price list and your bill:
- Token volume. A model may take more turns, read more files or produce longer reasoning to reach the same result. Each extra turn resends the whole context.
- Failure rate. A run that ends with a wrong patch still costs money. You pay for it and then pay again to retry or fix it.
- Retries and review. Failed attempts need another run or a human, and both add cost that the per-token price hides.
A model that is cheaper per token can be more expensive per finished task. A model that is pricier per token can be cheaper. The only way to know is to measure.
The metric
Cost per resolved task is the total spend divided by the number of tasks the agent actually resolved:
cost per resolved = total cost of all attempts / number of resolved tasksThe numerator includes every attempt, successful or not. The denominator counts only tasks that passed your definition of "resolved". That asymmetry is what makes the metric honest.
The metric relates to two simpler numbers:
cost per resolved = cost per attempt / success rateThis holds when the total covers all attempts. It also describes the expected cost of retrying until success, assuming attempts are independent. A model with a 40% success rate needs 2.5 attempts per resolved task on average.
| Measure | What it tells you | What it hides |
|---|---|---|
| Price per million tokens | The rate you pay for tokens | How many tokens a task needs |
| Cost per attempt | What one run costs on average | Whether the run worked |
| Cost per resolved task | What a working result costs | Latency, review effort, variance |
A worked example
The function below turns a list of run records into the numbers in the table. Each record holds the cost of one attempt and whether it resolved the task. The costs are placeholders, not real rates.
def evaluate(runs):
"""Summarize a list of run records: {"cost_usd": float, "resolved": bool}."""
total_cost = sum(r["cost_usd"] for r in runs)
resolved = sum(1 for r in runs if r["resolved"])
return {
"attempts": len(runs),
"resolved": resolved,
"success_rate": resolved / len(runs),
"cost_per_attempt": total_cost / len(runs),
"cost_per_resolved": total_cost / resolved if resolved else float("inf"),
}
# Placeholder results from running the same 5 tasks with two models.
cheap = [
{"cost_usd": 0.30, "resolved": True},
{"cost_usd": 0.45, "resolved": False},
{"cost_usd": 0.60, "resolved": False},
{"cost_usd": 0.25, "resolved": False},
{"cost_usd": 0.40, "resolved": True},
]
strong = [
{"cost_usd": 0.80, "resolved": True},
{"cost_usd": 0.95, "resolved": True},
{"cost_usd": 1.10, "resolved": True},
{"cost_usd": 0.70, "resolved": False},
{"cost_usd": 0.95, "resolved": True},
]
for name, runs in [("cheap", cheap), ("strong", strong)]:
s = evaluate(runs)
print(
f"{name}: success {s['success_rate']:.0%}, "
f"per attempt ${s['cost_per_attempt']:.3f}, "
f"per resolved ${s['cost_per_resolved']:.3f}"
)The output is:
cheap: success 40%, per attempt $0.400, per resolved $1.000
strong: success 80%, per attempt $0.900, per resolved $1.125The strong model costs more than twice as much per attempt, yet only 12.5% more per resolved task. If the strong model's success rate were a little higher, or the cheap model's a little lower, the ranking would flip. The per-attempt view alone would have picked the cheap model every time.
Note that in this data the failed runs cost more than some successful ones. That is common. An agent that cannot solve a task often keeps looping, rereading files and retrying until it hits a step limit. Failures tend to be the longest and most expensive runs.
Deciding what "resolved" means
The metric is only as good as the definition of resolved. Pick it before you run anything, and apply it identically to every model.
- Automated check. The task has a test that fails before the change and passes after. This is the cheapest and most repeatable option.
- Regression check. The existing test suite still passes. A patch that fixes the target test but breaks others is not resolved.
- Review criteria. For tasks with no test, such as refactors or documentation, write a short rubric and have a person or a separate grader apply it. Record who graded, because graders disagree.
Avoid counting a run as resolved because the agent said it was done. Agents report success on work that does not pass the tests. Grade the output, not the claim.
Counting the whole cost
The numerator should include everything you spent to get the result.
- All attempts for the task, including retries and abandoned runs.
- Subagent and tool-summarization calls, which may use a different model than the main loop.
- Reasoning tokens, which are billed as output.
- Cache writes as well as cache reads, if your provider charges for writes.
Pull these from the usage data your API returns, as covered in the chapter on reading usage data, rather than estimating from the final context size. The final context understates the bill, because each turn resent everything before it.
You can also add human cost. A failed run usually leaves someone to finish or repair the work. This function folds that in, using a placeholder hourly rate:
def cost_per_resolved_with_review(runs, review_minutes_per_failure, hourly_rate):
"""Add the cost of a person finishing each failed task, then divide by resolved."""
agent_cost = sum(r["cost_usd"] for r in runs)
failures = sum(1 for r in runs if not r["resolved"])
resolved = len(runs) - failures
human_cost = failures * review_minutes_per_failure / 60 * hourly_rate
return (agent_cost + human_cost) / resolved if resolved else float("inf")
# Reuses the cheap and strong lists from the previous example.
print(cost_per_resolved_with_review(cheap, 15, 60.0)) # 23.5
print(cost_per_resolved_with_review(strong, 15, 60.0)) # 4.875Once a person's time is counted, the strong model is far cheaper per finished task here, even though the agent spend alone looked close. Whether to include human time depends on your situation. State which version you report.
Running a fair comparison
The comparison is only useful if the setup is the same for every model.
Keep these fixed across models:
- The task set, drawn from work like what you will actually run.
- The system prompt, tools and step limit.
- The caching setup. A model run with a warm cache and one run cold are not comparable.
- The reasoning setting, or at least record it, since it changes output tokens.
Variance and sample size
Agent runs are not deterministic, and small task sets are noisy. In the earlier 50-task example, a 40% success rate has a standard error of about 7 percentage points: the square root of 0.4 × 0.6 / 50 is roughly 0.069. A difference of two or three tasks between models can come from chance.
Practical ways to handle this:
- Run more tasks, or run each task several times and average.
- Report the success counts next to the cost, such as "20 of 50", not only the ratio.
- Treat gaps smaller than the noise as ties, and break ties on latency or simplicity.
Latency and other costs the metric leaves out
Cost per resolved task is a dollar measure. It does not capture how long a developer waits. A large model with extended reasoning may be cheaper per resolved task and still be too slow for interactive use. Record median and worst-case wall-clock time per task next to the cost, and decide which one binds for each workflow. A background job can accept slow and cheap. A developer watching the terminal usually cannot.
Feeding the result back into routing
The metric works at the level of a whole task, but the routing policy from earlier chapters works at the level of a step. Use the comparison to decide which steps deserve a stronger model. A common finding is that planning steps resolve far more often with a large model, while running tests or summarizing tool output works fine on a small one. Measure cost per resolved task for the routed setup too, and compare it against each single-model setup. A routing policy that does not beat the best single model on this metric is added complexity with no return.
Common errors
- Dividing by attempts instead of resolutions. This gives cost per attempt and rewards models that fail cheaply.
- Leaving failed runs out of the numerator. This makes every model look cheaper than it is.
- Comparing under different settings. Different step limits, prompts or cache states change both cost and success.
- Trusting a self-reported success. Grade with tests or a rubric.
- Reading a tiny sample as a ranking. Check the gap against the noise.
- Treating the result as permanent. Prices, models and your tasks change. Rerun the comparison when any of them does.
Exercise
You ran the same 50 tasks with two models. Model X spent $30 in total and resolved 25 tasks. Model Y spent $50 in total and resolved 40 tasks. Which has the lower cost per resolved task, and why might Model Y still be the better choice even if the two were nearly equal?
Show answer
Model X costs 30 / 25 = $1.20 per resolved task. Model Y costs 50 / 40 = $1.25 per resolved task. Model X is slightly cheaper, but the gap is about 4%, which is within the noise of a 50-task sample. Model Y resolves 80% of tasks against 50%, so it leaves fewer failures for a person to repair, and review time is not in the dollar figure. If human cost or latency matters, Model Y can be the better choice despite the near tie.