Every model has a price per million tokens, and it is the number most of us compare. But nobody merges a token. You merge a fix, a feature, a passing test suite. The number that decides whether an AI coding setup is cheap is what it costs to get one piece of work done, including every attempt that didn't make it.
This piece sets out a simple way to measure that number with any coding agent, explains why it often disagrees with the per-token price, and shows where routing each step of a task (rather than the whole session) changes the result.
Why per-token price misleads for agents
A chat request is one call. A coding task is a loop: the agent plans, searches the repo, reads files, edits, runs a command, reads the output, fixes what broke and checks again. Several things happen inside that loop that the per-token price doesn't show:
- Context is re-sent on every turn. Each request carries the system prompt, tool definitions, files already read and the tool results so far. Input tokens, not output, tend to dominate a long session, which is why prompt caching matters so much. A longer walkthrough is in How coding agents use tokens.
- Failed attempts are real spend. A cheaper model that needs three tries can cost more than a stronger one that gets it right once. The failed tries never show up as "the cost of the fix" unless you count them.
- Loops burn budget quietly. An agent that repeats the same search or re-applies the same edit keeps paying for context on every round, with nothing to show for it.
- Switching models has a price. Prompt caches belong to one model. Move a long session to a model with a lower list price and its first request re-reads everything uncached. (We worked through that arithmetic in The Cheapest Model Isn't the Cheapest Request.)
- Premium rates on trivial steps. Renaming a variable or reading a file list doesn't need the strongest model, but a session pinned to one model pays that rate for every step.
None of these are visible if you compare models on a price table. All of them are visible if you measure per task.
Define the unit: a task with a done check
Before you can measure cost per task, you need to say what "done" means. A good definition is mechanical:
- Task: one change you would review and merge on its own (a bug fix, a small feature, a dependency bump).
- Done check: a command or event that says it worked: the test suite passes, the build is green, the PR is merged.
- Attempt: one session aimed at that task. If you abandon a session and start again, that's a second attempt, and its spend still belongs to the task.
Then the metric is:
cost per finished task = total spend on all attempts (finished or not) ÷ number of tasks that passed their done check Track three numbers next to it: attempts per finished task, requests per attempt, and minutes per finished task. Cost alone can hide a setup that's cheap but slow, or cheap because it gives up.
A ledger you can keep today
You don't need special tooling to start. One session per task, one row per attempt, and a few lines of awk:
task,attempt,cost,passed fix-login-redirect,1,0.42,no fix-login-redirect,2,0.38,yes add-csv-export,1,1.10,yes bump-deps,1,0.06,yes flaky-test-retry,1,0.75,no awk -F, 'NR>1 { spend += $3; attempts++; if ($4=="yes") done[$1]=1; seen[$1]=1 } END { n=0; for (t in done) n++; m=0; for (t in seen) m++ printf "tasks started: %d\ntasks finished: %d\nattempts: %d\ntotal spend: %.2f\ncost per finished task: %.2f\n", m, n, attempts, spend, (n ? spend/n : 0) }' tasks.csv tasks started: 4 tasks finished: 3 attempts: 5 total spend: 2.71 cost per finished task: 0.90 The rows are made-up sample data, there to show the arithmetic. Note what the ledger does: the failed first attempt at fix-login-redirect and the unfinished flaky-test-retry both raise the cost of the work that did get done. That's the point. Spend that didn't produce a merged change is part of what your finished work cost.
Two habits make the ledger honest:
- Start a fresh session per task. It keeps spend attributable, and it stops one task's history from being re-sent into the next.
- Record abandoned attempts. They're the line items people forget, and usually the ones a better setup removes.
The arithmetic of "cheap" models, per task
Here is the comparison that per-token pricing gets wrong. Fictional numbers, for the arithmetic only:
- Model X costs 1 unit per attempt on a given kind of task and passes the done check on one attempt in three. Expected cost per finished task: about 3 units.
- Model Y costs 2.5 units per attempt and usually passes first time. Cost per finished task: about 2.5 units.
Model X is cheaper per token and per attempt, and still more expensive per finished task. Flip the task type — a rename, a lookup, a small edit both models handle first time — and Model X wins easily.
That is the real lesson: there is rarely one right model for a session. There is a right model for each step. Planning a migration and listing a directory are different jobs. Pinning a whole session to either the strongest or the cheapest model leaves money or quality on the table.
Routing the step, not the session
This is where a routing layer helps, and the part we work on: we make AirLLM, and Air Router by AirLLM is its routing layer for coding agents. The framing on our platform page is the same one this article uses: "Tokens are an input. The finished task is the outcome." (airllm.ai/platform)
Air Router sits between the coding tool you already use and the models, and maps each of the cost leaks above to a specific behaviour (airllm.ai/air-router):
- Trivial steps on premium rates → step-aware routing. Routine operations go to Fast models (lookups, small edits, summaries), everyday implementation to Balanced, design and deep reasoning to Advanced.
- Failed attempts → quality-aware escalation. "Once an active task requires a stronger model tier, Air Router avoids moving that task to a weaker tier." On the homepage: "Send the same request again and AirLLM can automatically try a stronger tier."
- Cache rebuilds → "Air Router considers existing prompt caches before switching models, helping avoid expensive cache rebuilds."
- Re-sent context → it reduces "repeated file content, completed tool history, and unnecessary prompt overhead before model execution."
- Loops → "Detect repeated searches, edits, and tool calls. Air Router is designed to interrupt unproductive loops before they consume more tokens." It "can stop persistent loops with clear feedback."
What it doesn't promise matters just as much. In the homepage's own words: "AirLLM doesn’t promise that every token is cheaper. The goal is to reduce the cost of completing the work by using expensive intelligence selectively, preserving useful caches, reducing unnecessary context and stopping wasted agent turns." (airllm.ai) And on pricing: "AirLLM routes with 0% fee: you pay the model’s list price or less, never more." (airllm.ai/pricing)
The effect also depends on how long the agent works, which fits the per-task view. From AirLLM's measured coding sessions, Aug 27 – Nov 30, 2026: 1 request · 5% on average; 2–3 requests · 11% on average; 4–10 requests · 17% on average; 11–30 requests · 28% on average; 31+ requests · 53% on average. Those figures apply when a coding agent (Claude Code, Codex, Cursor, AirCode…) names the model on AirLLM's Token Plan. Chat and one-off requests may save little or nothing. Your own ledger is the better test.
Filling the ledger from AirLLM
If you run your agent through Air Router, most of the ledger columns already exist:
- Per-request cost. "Usage History in your dashboard lists every request from the last 24 hours with its tokens and its cost" (airllm.ai/pricing). Because it covers the last 24 hours, copy the day's totals into your ledger if you want a longer history.
- A hard cap per attempt. With AirCode CLI,
aircode loop "<goal>" --until "<cmd>"repeats until a check passes, with--max-iter,--max-costand--max-minuteslimits. The Developer Guide listsaircode loop list/loop report [id|--last]/loop --resume <id>to list loops, report on one, or continue one (airllm.ai/developer-doc). The--untilcommand is your done check, so the loop and the ledger use the same definition of finished. - Scripted tasks.
aircode run "<task>"runs one task and exits, with--jsonor--ndjsonoutput, which suits batch jobs where each run is one ledger row. - Multi-agent work. In AirCode Studio's AI Teams, the run report shows "Outcome, time, tokens and cost, tokens and working time per agent", and the team view shows "Cost per run, per team today and in total" (airllm.ai/developer-doc).
Pointing an existing tool at Air Router is a base URL and a key: https://api.airllm.ai/v1 for OpenAI-compatible tools, https://api.airllm.ai/ for Claude Code, with airllm-auto as the model. The Developer Guide has the exact steps for each tool.
A checklist, router or not
- Define "done" as a command, and run it at the end of every attempt.
- One session per task; count abandoned attempts against the task.
- Compare setups on cost per finished task, attempts per task and minutes per task, never on price per token alone.
- Don't switch models mid-session on a whim; a cold cache can cost more than the price difference saves.
- Cap every unattended run by iterations, time and spend.
- Re-run the ledger after any change (a new model, a new prompt, a new tool) on the same kinds of tasks.
Per-token price tells you what a model charges. Cost per finished task tells you what your work costs. Only the second one shows up in a sprint review.
If you want to measure this on your own work, start at airllm.ai. On Pricing, the Free plan is "For trying AirLLM: free for your first 6 months." As the homepage puts it: "Start on the Free plan with no card. Upgrade when AirLLM proves useful."
Further reading: How coding agents use tokens · Reduce LLM API costs
