SourceVane · Practical AI
Measure coding-agent cost per accepted coding task
Count edit-test model calls against original coding tasks, with test results, review and sandbox charges kept visible.
Direct answer
The decision in brief
Use the original coding request as the task, not each tool call or attempted patch. Count all billed model calls in the edit-test loop and divide by changes that pass the declared tests and review. Keep sandbox and tool fees outside token spend.
What belongs in a coding-agent cost record?
- Freeze the starting repository revision, requested change, allowed files and acceptance tests. Include both typical changes and difficult failures in the comparison set.
- Record every model call, including repository context, test logs, tool output and rejected edits. Average attempts in the calculator means billed model calls per original task; an edit-test loop may contain several calls.
- Count success only when the original request is met, relevant tests pass and the change clears review. Track test-passing but rejected patches separately, because test completion alone does not prove a correct change.
- Compare the same tasks with the same review rules. Report unresolved tasks, repair calls and elapsed time alongside cost; do not turn fewer tokens into a claim about coding quality.
Write the acceptance rule first
A sample acceptance rule can require the requested behavior, passing existing relevant tests and no unrequested file changes. Set the review rule before running the agent; this page reports no benchmark winner.
Worked illustrative example
These numbers are assumptions chosen to demonstrate the calculation. They are not provider quotes, measured success rates or model benchmarks. Both options use $1 per million input tokens, $4 per million output tokens and an assumed 90% final success rate.
The example has 2000 original tasks, 12000 input tokens and 1200 output tokens per model call. Option A uses 1.5 average calls per task; Option B uses 2. Everything else is held equal to isolate the cost of additional calls.
| Measure | Option A | Option B |
|---|---|---|
| Monthly token spend | $50.40 | $67.20 |
| Accepted original tasks | 1800 | 1800 |
| Cost per accepted task | $0.028 | $0.0373 |
Monthly token spend = tasks × calls per task × (input tokens × input rate + output tokens × output rate) ÷ 1,000,000. Divide by accepted original tasks for cost per accepted result.
What the estimate leaves out
Sandbox compute, paid tools, repository storage, developer review and later repairs are separate costs. Cache hits, cache writes and batch discounts require the actual billed configuration; this estimate does not assume that they apply.
Replace the assumptions with measured usage and the current rate for the exact provider route and conditions. Review source-linked API prices · Check retry accounting
What happened next · API prices · Decision guides · Latest AI coverage · Follow updates