What does a coding agent cost per workflow, and how do we measure it?
By Kevin DawkinsPublished 5 min read
In short: Per-seat and per-token figures tell you almost nothing about what coding agents cost. The unit that matters is cost per merged change, counting failed runs and the human time spent on review. In a typical setup, human review is by far the largest part of that cost.
What goes into the cost
| Component | Often missed? |
|---|---|
| Model tokens: input, output, and cache reads and writes | No, but often not attributed to anyone |
| Sandbox and compute time | Yes |
| Paid tool calls: search, connectors, APIs | Yes |
| Failed and abandoned runs | Yes. Nothing merged, but you paid for them |
| Agent code review | Rarely matters. It usually costs well under a dollar per review |
| Human reviewer minutes | Almost always, and it is usually the biggest line |
How to instrument it
- Route all agent traffic through a single gateway. Teams that make this mandatory get one bill, one budget system and one place to tag requests. Direct vendor subscriptions scatter spend where nobody can see it.
- Tag every request at the point where traffic is routed. Use
workflow,team,task(the ticket or pull request) andapp. Add the tags at the gateway or the agent harness, not afterward from logs. - Attribute usage that has no API key. Usage through OAuth or personal tokens can show up as zero dollars per person unless it is credited to the token's owner.
- Stack your budgets by team, project, key and user. Most gateways have no department level, so use tags for that.
How to join cost to outcome
Join cost, by task tag, to what happened to the change:
- Merged
- Abandoned: the pull request was closed, or the run failed without opening one
- Reverted: within a set window, for example 14 days
Cost per merged change runs well above cost per pull request opened. The gap is your abandoned work.
The three numbers to report
- Cost per merged change. Also report cost per durable change, which excludes reverts.
- Success rate: merged changes divided by total runs.
- Time to merge: the median from the start of a run to the merge.
What causes blowups
- Long contexts. Agent sessions grow toward the model's context limit unless they are compacted. Compact early, at around 200,000 tokens.
- Cache misses. Cache entries that expire in the middle of a session force expensive rewrites. Ordering prompts so the stable content comes first raises the cached share of input tokens and nearly eliminates first calls with nothing cached.
- The wrong model for the task. Measure quality on your own evals, then change the default model. This is often the largest single saving.
- Routing that ignores the cache. Switching models in the middle of a session throws the cache away, which can cancel the saving. The one good moment to route is the first prompt of a session.
- Loops and misconfiguration. A misconfigured agent in a loop can burn a five-figure sum overnight. Making spend visible on a dashboard is often enough to cut it sharply.
- Review bots that run on everything. Check where review-bot spend goes. It often runs on changes where it never leaves a comment.
Controls
- Set a budget per workflow, with an alert that a person watches. An agent that hits its budget and fails quietly while the alert is muted can be down for more than a day before anyone notices.
- Make hitting a budget limit loud. Failing closed is right. Failing closed and silently is an outage.
- Route by task type, at the start of a session only.
- Cap iterations and turns per run, and set a token ceiling per run.
- Alert at 50%, 75% and 100% of budget, and on unusual spend over a short window.
Worked example
A bug-fix agent over one month. The coding agent runs on Claude Opus 5.5 at medium effort. Every pull request it opens gets an automated first review from GPT-6.2 Sol at its default reasoning effort, then a human review.
| Model | Input | Cache read | Cache write | Output |
|---|---|---|---|---|
| Claude Opus 5.5 (coding agent) | $4.00 | $0.20 | $5.00 | $20.00 |
| GPT-6.2 Sol (reviewer) | $2.00 | $0.10 | $2.50 | $10.00 |
| Token type | Tokens | Rate per million | Cost |
|---|---|---|---|
| Coding run (Opus 5.5) | |||
| Cache reads | 1,800,000 | $0.20 | $0.36 |
| Cache writes | 150,000 | $5.00 | $0.75 |
| Uncached input | 50,000 | $4.00 | $0.20 |
| Output, including reasoning | 60,000 | $20.00 | $1.20 |
| Per run | $2.51 | ||
| Review (GPT-6.2 Sol) | |||
| Input: diff, files touched, and the ticket | 100,000 | $2.00 | $0.20 |
| Output, including reasoning | 6,000 | $10.00 | $0.06 |
| Per review | $0.26 |
About 90% of the input on a coding run is a cache read. That share does most of the work here. With no caching, the same 2 million input tokens would cost $8.00 per run instead of $1.31.
| Line | Input | Cost |
|---|---|---|
| Runs | 200 | |
| Model tokens (Opus 5.5) | 200 × $2.51 | $502.00 |
| Sandbox compute | 200 × $0.40 | $80.00 |
| Tool calls | 200 × $0.10 | $20.00 |
| Pull requests opened | 140 (60 runs produced none) | |
| Agent review (GPT-6.2 Sol) | 140 × $0.26 | $36.40 |
| Human review | 140 × 15 minutes = 35 hours × $120 per hour | $4,200.00 |
| Total | $4,838.40 | |
| Merged | 110 (30 pull requests abandoned) | |
| Reverted within 14 days | 4 | |
| Cost per merged change | $4,838.40 ÷ 110 | $43.99 |
| Cost per durable change | $4,838.40 ÷ 106 | $45.65 |
| Machine-only cost per merged change | $638.40 ÷ 110 | $5.80 |
| Success rate | 110 ÷ 200 | 55% |
Human review is 87% of the cost. Halving token spend saves about $2.28 per merged change. Halving review time saves about $19, roughly eight times as much. That is why review rules and cost are the same conversation. The rules are in What review rules should we set for agent-written code?
Takeaway: a cost model to copy
| Line | Input | Formula |
|---|---|---|
| Runs | R | Count of runs tagged with this workflow |
| Model tokens | $tok per run | R * $tok |
| Sandbox compute | min per run, $min per minute | R * min * $min |
| Tool calls | calls per run, $call each | R * calls * $call |
| Pull requests opened | P | From the join to pull requests |
| Agent review | $rev per review | P * $rev |
| Human review | rmin minutes per pull request, $hr per hour | P * rmin * $hr / 60 |
| Total | Sum of the cost lines | |
| Merged | M | From the join to pull requests |
| Reverted | V | Reverts within 14 days |
| Cost per merged change | Total / M | |
| Cost per durable change | Total / (M - V) | |
| Success rate | M / R | |
| Time to merge | Median of merged_at - run_started_at |
About Deftpace
Deftpace helps engineering and operations teams put agents to work without lowering the bar. Kevin Dawkins builds production agent infrastructure, including the routing and cost tracking described here. Email hello@deftpace.com.