What an AI coding model costs per solved task
- Authors
- Name
- Hamza Rahman
- Published on
- -13 mins read
A price per million tokens doesn't tell you what a coding model costs to get a task done. This article turns token prices into cost per attempt, then into cost per solved task, with a small JavaScript module you can copy. Review and rework time stay as a separate term, so you can see when they outweigh the model bill.
Checked on December 4, 2026 against CursorBench 4.1, the DeepSWE v1.1 live data, and the official Anthropic and OpenAI price pages. The code ran on Node.js v25.2.1 and v26.14.0.
Why token price is not enough
These are standard global API prices per million tokens, retrieved December 4, 2026 from Anthropic and OpenAI.
| Model | Input | Cached input | Cache write | Output |
|---|---|---|---|---|
| Claude Fable 5.2 | $8.00 | $0.20 | $10.00 (5 min) | $40.00 |
| Claude Opus 5.5 | $4.00 | $0.20 | $5.00 (5 min) | $20.00 |
| Claude Sonnet 5.5 | $2.00 | $0.10 | $2.50 (5 min) | $10.00 |
| Claude Haiku 5.5 (prompts up to 100,000 tokens) | $0.10 | $0.01 | $0.125 (5 min) | $0.50 |
| GPT-6 Astra | $10.00 | $1.00 | $12.50 (30 min) | $50.00 |
| GPT-6.2 Sol | $2.00 | $0.10 | $2.50 (30 min) | $10.00 |
Sonnet 5.5 and GPT-6.2 Sol have the same four prices here. That doesn't mean they cost the same per task, because each model decides how many requests to make, how much to read and how long to reason.
The table also leaves out long-context tiers. Haiku 5.5 charges five times these rates for prompts over 100,000 tokens. GPT-6.2 Sol doubles input and cache rates and charges 1.5 times the output rate for a request with more than 272K input tokens. Choose the rate per request rather than from the total tokens of the whole attempt.
Calculate one attempt
A coding agent makes many requests in one attempt, and each request has four kinds of billable text tokens: uncached input at the base input rate, cached input read from the prompt cache, cache writes stored for later reads, and output, which includes reasoning on these APIs. Multiply each count by its rate to price one request:
const PER_MILLION = 1_000_000
function requestCost(tokens, prices) {
return (
(tokens.input * prices.input +
tokens.cachedInput * prices.cachedInput +
tokens.cacheWrite * prices.cacheWrite +
tokens.output * prices.output) /
PER_MILLION
)
}
Those counts must not overlap, and the two APIs report them differently, so normalize each response first:
// OpenAI Responses API: input_tokens is the total.
export function fromOpenAI(usage) {
const cachedInput = usage.input_tokens_details?.cached_tokens ?? 0
const cacheWrite = usage.input_tokens_details?.cache_write_tokens ?? 0
const input = usage.input_tokens - cachedInput - cacheWrite
if (input < 0) {
throw new RangeError('cached_tokens + cache_write_tokens exceed input_tokens')
}
return { input, cachedInput, cacheWrite, output: usage.output_tokens }
}
// Anthropic Messages API: input_tokens excludes cache reads and writes.
export function fromAnthropic(usage) {
return {
input: usage.input_tokens,
cachedInput: usage.cache_read_input_tokens ?? 0,
cacheWrite: usage.cache_creation_input_tokens ?? 0,
output: usage.output_tokens,
}
}
fromOpenAI throws if the subtraction goes negative, because that means the payload broke the rule the formula relies on. The field meanings come from the OpenAI and Anthropic caching guides. If you mix cache lifetimes, price each lifetime separately. Both vendors have a longer-lived write that costs more.
Do not add reasoning on top of output. OpenAI bills reasoning tokens as output tokens, and Anthropic does the same for thinking.
Check the formula against published data
DeepSWE publishes the token mix behind its costs. In its live data, retrieved December 4, 2026 and generated September 22, 2026, GPT-6 Astra at xhigh averages:
| Token kind | Mean tokens per attempt | Cost at $10 / $1 / $12.50 / $50 |
|---|---|---|
| Uncached input | 295 | $0.003 |
| Cache reads | 1,326,922 | $1.327 |
| Cache writes | 129,710 | $1.621 |
| Output | 29,557 | $1.478 |
| Total | $4.429 |
That matches the reported mean of $4.429. The row also lists 11,256 reasoning tokens, which are already inside output, so adding them again would overstate the cost by about $0.56.
Cache traffic is two thirds of this bill, and a calculator with only input and output boxes can't describe it.
From attempts to solved tasks
Two different statistics get called cost per solved task: what a finished task set cost, and what you expect to spend retrying one task. They can give the same number while answering different questions.
Amortized cost across a task set
const amortized = totalSpend / solvedTasks
This one is accounting: add every attempt, including failures, and divide by the number of distinct tasks solved. It needs no independence assumption and describes the set you ran, under the retry policy you used.
For one attempt per task and a binary score, it simplifies to average cost divided by pass rate.
Expected cost of retrying one task
const expectedRetry = costPerAttempt / successProbability
Unlike amortized cost, this is a prediction. If attempts are independent with the same probability p each time, the number of attempts until success follows a geometric distribution with mean 1 / p. You also need to retry without a cap and recognize success when you see it.
A hard task usually breaks those assumptions. A model that misunderstood it once can misunderstand it again, and a 60% score across a set can hide tasks it nearly always solves alongside tasks it never solves.
The same DeepSWE row shows the gap. It passed 335 of 452 attempts (74.1%) over 113 tasks, four attempts per task. If every attempt had the same independent 74.1% chance, about 99.6% of tasks would have at least one pass in four. The reported figure is 91 of 113, or 80.5%.
That doesn't prove what caused each repeat failure, since different difficulty per task is enough to produce the gap. It does show that a pooled pass rate isn't the success probability of the task in front of you.
The denominator changes the answer too. At $4.429 per attempt:
- All 452 attempts divided by 335 passing attempts (
452 * 4.429 / 335) gives $5.98 per passing attempt. - The same spend divided by 91 distinct solved tasks (
452 * 4.429 / 91) gives $22.00 per solved task, because the benchmark runs all four attempts even after a pass.
Neither is the cost of stopping at the first pass, which needs the order of results for each task.
Worked example: CursorBench 4.1
These rows are quoted from CursorBench 4.1, retrieved December 4, 2026. The page dates version 4.1 to November 18, 2026. All four are Anthropic models because CursorBench 4.1 has no GPT-6 rows to pair with the OpenAI prices above. The last column is calculated here.
| Configuration | Score | Cost / task | Tokens / task | Steps / task | Cost / score-equivalent solve |
|---|---|---|---|---|---|
| Opus 5.5 High | 54.5% | $3.87 | 56,162 | 64 | $7.10 |
| Sonnet 5.5 Max | 54.4% | $8.63 | 342,273 | 199 | $15.86 |
| Fable 5.2 Low | 53.4% | $4.26 | 40,384 | 34 | $7.98 |
| Haiku 5.5 Extra High | 45.2% | $0.56 | 149,314 | 94 | $1.24 |
Sonnet's input and output prices are half of Opus's. At nearly the same score, the Sonnet Max row costs 2.2 times as much per task. Fable's input and output prices are double Opus's, yet the Low row costs only 10% more.
The last column says "score-equivalent solve" because the leaderboard doesn't say that every task is strictly pass or fail. If graders award partial credit, score divided by 100 is not a solve rate, so read it as cost per full point of score.
Cursor says cost uses published input, cache read, cache write and output prices, and that small score differences may not be statistically meaningful. The page does not break Tokens / task down by kind, so you cannot rebuild these costs from that column.
For the wider comparison, see the AI coding benchmark page.
Add review and rework
Someone has to look at failed attempts as well as good ones. Keep that term visible:
total per solve = model spend per solve
+ review minutes per attempt * attempts / solves * hourly rate / 60
+ rework minutes per solve * hourly rate / 60
Take an illustrative $60 hourly rate and no rework. Treat the scores as pass rates, with one attempt on each task:
| Configuration | Model only | 10 min review per attempt | 20 min review per attempt |
|---|---|---|---|
| Haiku 5.5 Extra High | $1.24 | $23.36 | $45.49 |
| Opus 5.5 High | $7.10 | $25.45 | $43.80 |
Under these assumptions, Opus 5.5 High becomes cheaper than Haiku 5.5 Extra High once review passes about 15.5 minutes per attempt. Replace the review times and hourly rate with your own. If an automated test suite rejects failures before a person sees them, count review only for the attempts that reach a person.
The complete module
Save this as solve-cost.js in a package with "type": "module". It has no dependencies.
const PER_MILLION = 1_000_000
function nonNegative(name, value) {
if (!Number.isFinite(value) || value < 0) {
throw new RangeError(`${name} must be a finite number >= 0`)
}
}
function probability(value) {
if (!Number.isFinite(value) || value <= 0 || value > 1) {
throw new RangeError('successRate must be > 0 and <= 1')
}
}
// OpenAI Responses API: input_tokens is the total.
export function fromOpenAI(usage) {
const cachedInput = usage.input_tokens_details?.cached_tokens ?? 0
const cacheWrite = usage.input_tokens_details?.cache_write_tokens ?? 0
const input = usage.input_tokens - cachedInput - cacheWrite
if (input < 0) {
throw new RangeError('cached_tokens + cache_write_tokens exceed input_tokens')
}
return { input, cachedInput, cacheWrite, output: usage.output_tokens }
}
// Anthropic Messages API: input_tokens excludes cache reads and writes.
export function fromAnthropic(usage) {
return {
input: usage.input_tokens,
cachedInput: usage.cache_read_input_tokens ?? 0,
cacheWrite: usage.cache_creation_input_tokens ?? 0,
output: usage.output_tokens,
}
}
// Token counts must not overlap. `output` includes reasoning tokens.
// Returns the cost of one API request in dollars.
export function requestCost(tokens, prices) {
let total = 0
for (const kind of ['input', 'cachedInput', 'cacheWrite', 'output']) {
const count = tokens[kind] ?? 0
nonNegative(`tokens.${kind}`, count)
if (count === 0) continue
nonNegative(`prices.${kind}`, prices[kind])
total += count * prices[kind]
}
return total / PER_MILLION
}
// Returns the cost of one attempt: every request the agent made.
export function attemptCost(requests, prices) {
return requests.reduce((sum, tokens) => sum + requestCost(tokens, prices), 0)
}
// Observed cost per distinct solved task, over a whole task set.
export function amortizedCostPerSolve(totalSpend, solvedTasks) {
nonNegative('totalSpend', totalSpend)
if (!Number.isInteger(solvedTasks) || solvedTasks < 0) {
throw new RangeError('solvedTasks must be an integer >= 0')
}
return solvedTasks === 0 ? Infinity : totalSpend / solvedTasks
}
// Expected cost of retrying ONE task until it passes.
// Valid only if attempts are independent with the same successRate.
export function expectedRetryCost(costPerAttempt, successRate) {
nonNegative('costPerAttempt', costPerAttempt)
probability(successRate)
return costPerAttempt / successRate
}
// Independent attempts again, but you stop after maxAttempts.
export function cappedRetry(costPerAttempt, successRate, maxAttempts) {
nonNegative('costPerAttempt', costPerAttempt)
probability(successRate)
if (!Number.isInteger(maxAttempts) || maxAttempts < 1) {
throw new RangeError('maxAttempts must be an integer >= 1')
}
const solveProbability = 1 - (1 - successRate) ** maxAttempts
const expectedAttempts = solveProbability / successRate
return { solveProbability, expectedCost: expectedAttempts * costPerAttempt }
}
// Human time per solved task, kept separate from model spend.
export function humanCostPerSolve({
attempts,
solvedTasks,
reviewMinutesPerAttempt,
reworkMinutesPerSolve = 0,
hourlyRate,
}) {
nonNegative('attempts', attempts)
nonNegative('reviewMinutesPerAttempt', reviewMinutesPerAttempt)
nonNegative('reworkMinutesPerSolve', reworkMinutesPerSolve)
nonNegative('hourlyRate', hourlyRate)
if (!Number.isInteger(solvedTasks) || solvedTasks < 0) {
throw new RangeError('solvedTasks must be an integer >= 0')
}
if (solvedTasks === 0) return Infinity
const minutes = (attempts * reviewMinutesPerAttempt) / solvedTasks + reworkMinutesPerSolve
return (minutes / 60) * hourlyRate
}
requestCost rejects a missing price when that token kind was used, because treating it as zero would hide an incomplete price table. For tiered prices, call requestCost per request with the matching rates and add the results.
cappedRetry models a retry limit. At $3.87 and 54.5%, three independent attempts give a 90.6% chance of success and an expected spend of $6.43, with the same warning about independence.
Test it
Save this as solve-cost.test.js:
import test from 'node:test'
import assert from 'node:assert/strict'
import * as c from './solve-cost.js'
const prices = { input: 4, cachedInput: 0.2, cacheWrite: 5, output: 20 }
const close = (a, b) => assert.ok(Math.abs(a - b) < 1e-9, `${a} !== ${b}`)
test('fromOpenAI subtracts cache reads and writes from the total', () => {
const usage = {
input_tokens: 15_000,
input_tokens_details: { cached_tokens: 12_000, cache_write_tokens: 2_000 },
output_tokens: 900,
}
assert.deepEqual(c.fromOpenAI(usage), {
input: 1_000,
cachedInput: 12_000,
cacheWrite: 2_000,
output: 900,
})
})
test('fromOpenAI rejects cache counts larger than the total', () => {
const usage = { input_tokens: 100, input_tokens_details: { cached_tokens: 101 }, output_tokens: 1 }
assert.throws(() => c.fromOpenAI(usage), /exceed input_tokens/)
})
test('fromAnthropic keeps input_tokens as uncached input', () => {
const usage = {
input_tokens: 2_048,
cache_read_input_tokens: 1_800,
cache_creation_input_tokens: 248,
output_tokens: 503,
}
assert.deepEqual(c.fromAnthropic(usage), {
input: 2_048,
cachedInput: 1_800,
cacheWrite: 248,
output: 503,
})
})
test('prices each token kind once', () => {
const tokens = { input: 10_000, cachedInput: 900_000, cacheWrite: 60_000, output: 30_000 }
close(c.requestCost(tokens, prices), 0.04 + 0.18 + 0.3 + 0.6)
})
test('an attempt is the sum of its requests', () => {
close(c.attemptCost([{ output: 1000 }, { output: 2000 }], prices), 0.06)
})
test('a missing price is an error, not free', () => {
assert.throws(() => c.requestCost({ cacheWrite: 1 }, { input: 4 }), RangeError)
})
test('amortized cost uses solved tasks, and zero solves is Infinity', () => {
assert.equal(c.amortizedCostPerSolve(300, 50), 6)
assert.equal(c.amortizedCostPerSolve(300, 0), Infinity)
})
test('retry cost is attempt cost over success rate', () => {
assert.equal(c.expectedRetryCost(2, 0.5), 4)
assert.throws(() => c.expectedRetryCost(2, 0), RangeError)
})
test('a retry cap limits both spend and solve probability', () => {
assert.deepEqual(c.cappedRetry(2, 0.5, 2), { solveProbability: 0.75, expectedCost: 3 })
})
test('review is paid on failed attempts too', () => {
const result = c.humanCostPerSolve({
attempts: 100,
solvedTasks: 50,
reviewMinutesPerAttempt: 6,
reworkMinutesPerSolve: 3,
hourlyRate: 60,
})
assert.equal(result, 15)
})
test('reproduces the DeepSWE mean cost from its mean token counts', () => {
const astra = { input: 10, cachedInput: 1, cacheWrite: 12.5, output: 50 }
const tokens = { input: 295.387, cachedInput: 1_326_921.684, cacheWrite: 129_710.022, output: 29_557.327 }
assert.equal(c.requestCost(tokens, astra).toFixed(4), '4.4291')
})
Run node --test. All 11 tests pass on Node.js v25.2.1 and v26.14.0.
Picking the right function
- Reach for
attemptCostwhen checking an agent's bill from its usage logs. - Use
amortizedCostPerSolveto report what a finished task set cost. - Save
expectedRetryCostfor planning, and only when you have a reason to believe the probability applies to that task and attempts are independent. - Compare configurations on the same tasks, with the same retry limit and verifier.
To measure the rates on your own code, see Build a coding-agent benchmark in Node.js.
References
Related articles
Build your own coding-agent benchmark in Node.js
Build a small coding-agent benchmark in Node.js with disposable git worktrees, hidden verifiers, time limits, repeated runs and Wilson intervals.
AI Coding Benchmark Leaderboards Compared (December 2026)
Every major AI coding benchmark in one place: which leaderboards are still updated, who leads each one, what it costs, and where the rankings disagree.
Build an MCP server in TypeScript with Node.js
Build a stateless MCP server in TypeScript with SDK v2: SQLite tools, elicitation, stdio and HTTP, a test client, client setup and Code Mode.

