# AI Token Cost per Successful Task, Not Price per Million

Compare AI models by cost per successful task: total spend including retries and failures divided by passes. Includes a Python calculator and a synthetic log.

Author: Steven Phan
Published: 2026-11-23
Article: https://stevenphan.ca/blog/ai-token-cost-per-successful-task/

## Quick answer

Price per million tokens tells you what a model charges for tokens. It doesn't tell you what a finished task costs. The number that does is **cost per successful task**: your total spend on a set of tasks, counting every retry and every failed run, divided by the number of tasks that passed your check.

A shortcut makes it easy to remember: cost per successful task equals cost per attempt times attempts per success. A model with a cheap token price can still lose if it needs many attempts, writes long answers or fails often. In the demo below, a model that costs half as much per token cost about 36 percent more per finished task. The log is synthetic and the model labels are invented, so the numbers show the method and not how any real product performs.

<nav class="toc" aria-label="Table of contents"><p><strong>On this page</strong></p><ol><li><a href="#why-price-per-million-tokens-misleads">Why price per million tokens misleads</a></li><li><a href="#the-formula">The formula</a></li><li><a href="#download-the-demo-project">Download the demo project</a></li><li><a href="#the-run-log-and-the-price-table">The run log and the price table</a></li><li><a href="#real-output-from-the-synthetic-log">Real output from the synthetic log</a></li><li><a href="#how-retries-change-the-answer">How retries change the answer</a></li><li><a href="#long-outputs-cost-more-than-they-look">Long outputs cost more than they look</a></li><li><a href="#where-caching-fits">Where caching fits</a></li><li><a href="#what-not-to-measure">What not to measure</a></li><li><a href="#limits-of-this-demo">Limits of this demo</a></li><li><a href="#faq">FAQ</a></li><li><a href="#where-to-go-next">Where to go next</a></li></ol></nav>

![Original diagram of two stacked bars for model b and model c from the synthetic log, split into spend on passed tasks and spend on failed tasks. Model b costs US$1 and US$5 per million tokens and spent about US$2.05, of which 29.0 percent went to tasks that never passed. Model c costs US$2 and US$10 per million tokens and spent about US$1.79, of which 2.6 percent went to failed tasks. Dividing by passed tasks gives US$0.01232 per success for model b with 166 passes and US$0.00906 for model c with 198 passes, so the model at half the token price costs about 36 percent more per finished task.](https://stevenphan.ca/_astro/ai-token-cost-per-successful-task-flow.C2t6Lv-R_ZXA4Vd.webp)

## Why price per million tokens misleads

A price page lists two numbers per model: dollars per million input tokens and dollars per million output tokens. They're accurate, and they're the right inputs. The trouble is that they price a unit you don't actually want to buy. You want a task done: an invoice field extracted, a bug fixed, a summary that your checker accepts.

Three things sit between the token price and the finished task.

- **Failure.** A run that fails your check still got billed. Its tokens are spend with nothing to show for it.
- **Retries.** If you retry a failed task, you pay again, usually for the same long prompt plus a new answer.
- **Verbosity.** Two models can read the same prompt and write very different amounts. Output tokens cost several times more than input tokens on the pages we checked, so a wordy model pays twice: more tokens at a higher rate.

Checked 2026-11-13, the Anthropic pricing page lists Claude Sonnet 5.5 at US$2 per million input tokens and US$10 per million output tokens, and Claude Haiku 5.5 at US$0.10 and US$0.50 for prompts up to 100,000 tokens. That's a 20 times gap per token. Whether it's a 20 times gap per finished task depends entirely on how often each one passes. We'll measure that gap with a script.

## The formula

Take a fixed set of tasks and one model. Run each task, retrying up to some limit if your check fails. Then:

```text
spend             = sum over ALL tasks, passed or failed, of
                    fresh_input x input_price + output x output_price
                    + cache_reads x input_price x read_multiplier
                    + cache_writes x input_price x write_multiplier
cost per attempt  = spend / total attempts
success rate      = passed tasks / tasks
cost per success  = spend / passed tasks
                  = cost per attempt x (attempts / passed tasks)
```

The last line is the useful one. Attempts per success is at least 1.0, and it grows when the model fails or you retry. If a model's tokens are 2 times cheaper but it needs 2.2 attempts per success where the other needs 1.15, the cheaper tokens lose.

A tiny worked example, with one row from the demo log below. A model priced at US$1 and US$5 per million tokens used 4,929 input and 2,628 output tokens across 3 attempts and still failed:

```text
4,929 x 1.00 / 1,000,000 = 0.004929
2,628 x 5.00 / 1,000,000 = 0.013140
row cost                 = 0.018069 USD, and the task did not pass
```

That US$0.018 goes into the numerator and adds nothing to the denominator. That's the whole idea.

## Download the demo project

Download the [cost per successful task demo](https://stevenphan.ca/downloads/ai-token-cost-per-successful-task.zip) and unzip it into a new folder. You need Python 3.8 or newer. It uses only the standard library, makes no network calls and needs no API keys.

```text
costper.py              the calculator (the part you keep)
make_synthetic_log.py   writes the invented run log, seeded
prices.csv              price table, USD per million tokens, with source and date
run_all.sh              generates the log, then runs the calculator
README.md
```

Run `bash run_all.sh` on macOS, Linux, Git Bash or WSL. On plain Windows, run the two commands inside it with `py -3` instead of `python3`.

## The run log and the price table

Each line of the log is one task run by one model. Counts are totals across all attempts of that task. `input_tokens` means fresh, uncached input, which keeps the cache arithmetic honest later. This is the real shape of a line from the log we generated (the generator wrote it, so the data is synthetic):

```json
{"task_id": "t000", "model": "model-b", "input_tokens": 4929, "output_tokens": 2628, "cache_read_tokens": 0, "cache_write_tokens": 0, "attempts": 3, "result": "fail"}
```

**The log is synthetic.** `make_synthetic_log.py` invents 200 tasks, runs each through four labels with a seeded random generator and records the outcome. The labels `model-a`, `model-b`, `model-c` and `model-c-cached` are placeholders for a price tier. They aren't real products and no model was called. The pass chances, token counts and retry limit of 3 are assumptions we chose to illustrate the metric, so don't read them as a measurement of any vendor.

The prices are not invented. We read the API table in our [AI tool pricing post](https://stevenphan.ca/blog/ai-tools-pricing-cad-dated/) and re-read Anthropic's pricing page on 2026-11-13. The three price points in `prices.csv` are copied from rows in that table: US$0.10 and US$0.50, US$1.00 and US$5.00, and US$2.00 and US$10.00 per million tokens (input and output). Each row in the CSV names its source and the date checked. Prices change often, so check the vendor page again before you trust any total.

For caching, the Anthropic page said a 5 minute cache write costs 1.25 times the base input price and a cache read costs 0.1 times on most models, with a lower 0.05 times listed for Claude Sonnet 5.5 (checked 2026-11-13). The demo's `prices.csv` uses 0.1 and 1.25 for every row, and those two columns are placeholders, not the vendor's real figures. For example, the `model-c` price point is the Sonnet 5.5 row, whose real read multiplier on that page is 0.05, not 0.1, and the Haiku 5.5 and gpt-6.1 rows have their own cache prices too. Put your vendor's real multipliers in the CSV before you trust any cached total.

## Real output from the synthetic log

We unzipped the archive into a new empty folder and ran `bash run_all.sh`. This is the real console output, sorted by cost per success:

```text
wrote 800 rows for 200 tasks to runs.jsonl
model           tasks  pass  succ% att/task out/att  $/attempt  $/success  naive$/succ  waste%
----------------------------------------------------------------------------------------------
model-a           200   122  61.0%     2.37    1132    0.00072    0.00279      0.00139   50.1%
model-c-cached    200   198  99.0%     1.20     454    0.00548    0.00661      0.00645    2.4%
model-c           200   198  99.0%     1.14     472    0.00787    0.00906      0.00882    2.6%
model-b           200   166  83.0%     1.80     826    0.00568    0.01232      0.00874   29.0%

$/attempt = total spend / attempts. $/success = total spend (failures and retries included) / passed tasks.
naive$/succ = spend on passed tasks only / passed tasks (the survivorship mistake).

price per million tokens (input/output, USD) for comparison:
  model-a        0.10 / 0.50
  model-c-cached 2.00 / 10.00
  model-c        2.00 / 10.00
  model-b        1.00 / 5.00
```

Read it in three passes.

**The expected result.** `model-a` is 20 times cheaper per token than `model-c` and ends up about 3.2 times cheaper per finished task (US$0.00279 against US$0.00906). The cheap model still wins here, but the gap shrank from 20 times to about 3 times because it passed only 61 percent of tasks and used 2.37 attempts per task.

**The surprise.** `model-b` charges half as much per token as `model-c`. Per attempt it's cheaper too (US$0.00568 against US$0.00787). But per finished task it costs US$0.01232 against US$0.00906, about 36 percent more. Over the 200 tasks that works out to roughly US$2.05 of spend for 166 finished tasks, against roughly US$1.79 for 198. The half price model costs more and delivers 32 fewer finished tasks.

**The check on the shortcut.** Attempts per success is attempts divided by passes. From the table: `model-b` made 360 attempts for 166 passes, which is 2.17, and 0.00568 times 2.17 is about 0.01232. `model-c` made 228 attempts for 198 passes, which is 1.15, and 0.00787 times 1.15 is about 0.00906. The formula and the script agree.

## How retries change the answer

Retries do two things at once. They raise the chance a task finishes, and they raise the bill. The `att/task` column shows it: `model-a` averaged 2.37 attempts and `model-b` 1.80, while `model-c` averaged 1.14.

The `waste%` column is the share of total spend that went to tasks which never passed. For `model-a` it's 50.1 percent: half its money bought nothing. For `model-c` it's 2.6 percent. A high waste share is a prompt to look at the tasks that failed. If the same kind of task keeps failing, retrying the same model is a poor use of money, and a different model, a better prompt or a human is cheaper.

Set a retry cap and log every attempt. In this demo the cap is 3, and tasks that hit the cap and still failed count as failures with their full cost. Without a cap, cost per success can look fine on average while a few tasks burn many attempts. If you want a guardrail for runaway loops, a hard cap on attempts is the simplest one.

Also decide what "pass" means before you run. The metric is only as good as the check behind it. A weak grader inflates success and flatters every model, a point we come back to in the post on [building a 30 case eval set and running it three times](https://stevenphan.ca/blog/build-30-case-eval-set-run-three-times/). That post also explains why one run of a case isn't enough, because a model that passes once may not pass the next time.

## Long outputs cost more than they look

The `out/att` column is average output tokens per attempt: 1,132 for `model-a`, 826 for `model-b`, 472 for `model-c`. Those are our assumptions, but the pattern is common: a model that's less sure of itself may ramble, repeat itself or add steps.

Output tokens are the expensive half. On the Anthropic and OpenAI rows in the pricing post, output costs 5 times as much per token as input. Cut an answer from 1,100 tokens to 450 and you save more than the same cut in the prompt would.

Two practical consequences:

- Log input and output tokens separately. A single "tokens used" number hides the part that costs more.
- If a task only needs a short structured answer, ask for one. Tight output formats, such as the schema approach in [structured output from an LLM with JSON Schema](https://stevenphan.ca/blog/structured-output-from-llm-json-schema/), cut verbosity and make the pass check easier to write.

One caution: don't compare models on output length alone. A short wrong answer is still a failure. Length matters because it multiplies into cost, and pass rate decides whether that cost counts.

## Where caching fits

Caching changes the numerator. If most of your prompt is a prefix that repeats, such as a long system prompt or a reference document, the repeated part is billed at a fraction of the base input price after the first write.

The demo's `model-c-cached` label is `model-c` with a 1,200 token shared prefix read from the cache at 0.1 times the input price. The generator writes the prefix on the first attempt of every 25th task and reads it otherwise, an assumption we picked. Result, using the placeholder multipliers: the same 99.0 percent pass rate and US$0.00661 per success against US$0.00906, about 27 percent lower. With a real read multiplier the saving would differ. The attempts per task differ a little (1.20 against 1.14) because each label gets its own random draws, not because caching changes how the model behaves.

Two warnings. First, cache savings depend on your traffic. If a cached prefix is written and rarely read before it expires, the 1.25 times write cost can make caching more expensive. Second, caching doesn't touch the pass rate. It cheapens the tokens, and a model that fails half the time is still failing half the time at a lower price. Fix reliability first, then tune tokens.

## What not to measure

A few measurements look useful and mislead.

- **Price per million tokens alone.** It's an input, not an outcome, as the `model-b` row shows.
- **Cost per attempt.** It hides retries. `model-b` looked cheaper per attempt than `model-c` and lost per success.
- **Spend on passed tasks only.** The `naive$/succ` column divides only the passing tasks' spend by passes. It makes `model-a` look like US$0.00139 per success when the true figure is US$0.00279. Failures are part of the price of the successes. This is a survivorship mistake and it's easy to make by filtering a log to successful rows.
- **Success rate alone.** A model with 99 percent success at a cost you can't afford isn't the answer either. Read pass rate and cost together.
- **Average cost across mixed task types.** If your tasks range from easy to hard, a cheap model might win on easy ones and lose on hard ones. Break results down by task type before you pick one model for everything. The post on [making a benchmark from your own logs](https://stevenphan.ca/blog/build-your-own-benchmark-from-your-logs/) covers grouping tasks that way.
- **Latency mixed into cost.** Time matters, but it's a separate axis. Record it, and don't fold it into dollars unless you've decided what a second is worth.

Review time is the cost this script can't see. If a human checks each output, or fixes the failures, that labour is part of the price of a finished task. You could add it as a per task cost in the numerator once you've estimated it from real work.

## Limits of this demo

Everything about model behaviour here is made up. The pass chances, retry behaviour, token counts and the cached prefix size come from our generator, and a real model will behave differently. The script's arithmetic and the price points are real; the outcomes aren't.

Other limits: the cache multipliers in `prices.csv` are placeholders (see the caching section), so the cached row's saving is illustrative only; the script prices only text tokens in USD (it can print an approximate CAD figure with `--cad-rate`, a rate you supply); it ignores batch discounts, long prompt tiers, tax and any minimums; and it treats each model label as having one price. The Anthropic page we read lists a 50 percent batch discount and a higher Haiku 5.5 tier for prompts over 100,000 tokens (checked 2026-11-13). If you use those, add rows or multipliers to match.

To use your own data, replace the generator with an export of your logs and make sure each model string has a row in `prices.csv`. Use a real pass check, run enough tasks that the success rates are stable, and re-check prices on the day you decide.

## FAQ

### What is cost per successful task?

It's your total spend on a set of tasks, including retries and failed runs, divided by the number of tasks that passed your check. It prices the outcome you want, a finished task, and not the tokens you used along the way.

### Is the cheapest model per token ever the cheapest per task?

It can be, and in the demo `model-a` was. The cheaper token price still has to survive the extra retries and failures. In the demo the 20 times gap per token shrank to about 3 times per finished task, and a model at half the token price ended up about 36 percent more expensive per finished task.

### How do retries affect cost per successful task?

Every retry is billed, and failed attempts add to the numerator without adding to the denominator. Cost per success equals cost per attempt times attempts per success, so a model needing more attempts per pass pays that multiple.

### Does prompt caching change which model wins?

It lowers the token cost for repeated prompt prefixes, so it can change the ranking. In the demo it cut cost per success by about 27 percent for one label, using placeholder cache multipliers. It doesn't change the pass rate, and a poor cache hit rate can make it cost more because cache writes are billed at a premium.

### Why not just count the cost of the passing tasks?

Because the failures were paid for as well. Dividing only passing spend by passes understates cost, as the `naive$/succ` column shows: US$0.00139 against the true US$0.00279 for `model-a`.

### Are the demo's numbers real results for these models?

No. The model labels are invented and the run log is synthetic, with pass rates and token counts that we chose. Only the arithmetic and the price points are real, and the prices were checked 2026-11-13. Real model results will differ.

## Where to go next

Start with the prices. The [AI tool pricing post](https://stevenphan.ca/blog/ai-tools-pricing-cad-dated/) has the dated table and the CAD method. Then get real outcomes to feed the script: [build a 30 case eval set and run it three times](https://stevenphan.ca/blog/build-30-case-eval-set-run-three-times/), or [turn your own request logs into a benchmark](https://stevenphan.ca/blog/build-your-own-benchmark-from-your-logs/). To pick a model with a test you can repeat, read [how to choose an AI model with a simple task test](https://stevenphan.ca/blog/choose-ai-model-task-test/). When you make the check automatic, [prompt regression gates in CI](https://stevenphan.ca/blog/prompt-regression-gates-ci/) shows how to stop a change that raises cost or lowers the pass rate.
