On this page
- What an agent run actually costs
- The five lines in a loaded run
- Why input tokens grow faster than the step count
- Where the money hides
- Run it on your own numbers
- Cost controls that do not make the agent worse
- Instrument the cost before you tune it
- Building an estimate you can defend
- Terms worth being precise about
- Before you commit to a number
What an agent run actually costs
An agent run costs five things, and model tokens are usually the smallest: tokens, paid tool calls, standing infrastructure, human minutes, and cleaning up wrong output. Cost per run is also the wrong unit. Budget on cost per accepted outcome, because a run that gets rejected or redone charges you twice and delivers nothing. Before you promise anyone a number, run twenty real cases through the loop, record the token counts the provider reports, and quote the 95th percentile rather than the average.
Most agent estimates are one multiplication: tokens times a price found on a pricing page. That number is real and it is a fraction of the bill. The rest hides in retries, in tool providers that charge per call, in the eval suite that runs inference every night, and in the person who reads the escalation queue. This guide gives you the arithmetic and the lines people forget.
- 5cost lines in a single run, and only one of them is model tokens
- Every stepre-sends the whole transcript, so input tokens grow faster than the step count
- p95the percentile to budget on, because failed runs exhaust the step cap
- Per outcomethe unit that matters, not per run, because rejected runs still cost full price
The five lines in a loaded run
Price the run, not the model call. A loaded run is one unit of work carried end to end, including everything that had to happen around the model for the output to be usable. If your estimate has one line in it, it is not an estimate of anything a finance team recognises.
The Loaded Run
Five lines that together give the real cost of one unit of work. Estimate each separately, then divide by your acceptance rate.
Input and output across every step, including retries. This is the line everyone estimates and typically the smallest. Take the counts from the provider's usage fields rather than a tokenizer estimate, because system scaffolding and tool schemas are counted too.
Search, enrichment, geocoding, OCR, document conversion, voice minutes, per-request connectors. Somebody else prices these per call, and the agent decides how many calls to make, which is the part that makes them hard to forecast.
Vector store, queue, sandbox for code execution, object storage, egress, and the observability bill, which grows with trace volume rather than with revenue. Mostly fixed monthly, so divide by expected runs and watch that number fall as volume rises.
Approvals, escalation handling, the person who reads the dead letter queue on Monday. Convert to money at a loaded hourly rate. A gate that adds two minutes to every run is usually the largest line on this list.
The rework when an output is wrong, plus whatever the wrong output cost downstream. You cannot price this precisely, so price it as accuracy: divide the other four lines by your acceptance rate and the number carries the failure cost implicitly.
Why input tokens grow faster than the step count
In a tool-calling loop, every step re-sends the entire conversation so far. The static prefix, the system prompt and the tool schemas go up on every call, and so does each earlier assistant message and each tool result. If the prefix is S tokens and each step adds A tokens of new material, total input billed across n steps is about nS + An(n-1)/2. The second term is quadratic, which is why a loop that takes twice as many steps costs more than twice as much.
Two consequences follow. Anything that lengthens the transcript is charged again at every remaining step, so a single fat tool result is not a one-off cost. And the cheapest reliability work is often the cheapest cost work, because a step you did not need to take removes its own tokens plus its share of every later re-send.
Where the money hides
Six lines get missed in most agent estimates. None of them are exotic. They are simply invisible in a demo, because a demo runs the happy path once and never runs a nightly eval suite.
| Cost line | How to measure it | What makes it explode | The control |
|---|---|---|---|
| Fat tool results | Tokens per tool result, times remaining steps | Returning a raw API payload into the transcript | Summarise to the fields the agent needs, keep raw output behind a handle |
| Retries on invalid output | Count parse failures per hundred runs | A schema the model keeps violating | Constrained decoding, and a repair call that sends the error, not the whole transcript |
| Eval inference in CI | Golden cases times models times runs per day | A growing golden set on a nightly cron | Tier it: smoke on commit, full nightly, everything weekly |
| Trace storage | Bytes kept per run, times retention | Storing full prompts at every step forever | Sample successful runs, keep all failures, expire raw payloads early |
| Human review | Minutes per item times gated items | A gate on a high-volume action | Approve policies rather than instances |
| Runs that fail | Cost of runs that hit the step cap | Cases outside the design envelope | A cheap classifier that refuses out-of-scope work at step zero |
Run it on your own numbers
The two prices below are stand-in figures, chosen only so the arithmetic runs. Replace them with your provider's current published rates before you trust the output, and keep those rates in config with the date you checked them.
Input tokens use the loop formula, so raising the step count raises cost faster than linearly. Prices are per million tokens.
Push the step count from eight to sixteen and watch what happens. That single field usually moves the monthly figure more than switching model tiers does, which is why step discipline beats price shopping. Then add the other four lines from the loaded run by hand; this calculator covers tokens only, and tokens are the part that flatters you.
Cost controls that do not make the agent worse
Cut tokens where the model does not need them, never where it does. Every control below is measured against your eval set before and after, because a change that saves twenty percent and loses five points of accuracy costs money once you divide by the acceptance rate.
Truncate tool results before they enter the transcript
This is the largest lever in most systems. A raw API response of eight thousand tokens, returned at step two of a ten-step loop, is charged nine more times. Return the fields the agent reasons over, keep the full payload out of band behind an identifier, and give the agent a tool to fetch specific parts if it ever needs them.
Cache the static prefix, and never reorder it
Providers price cached input below fresh input, and caching keys on an exact prefix match. One dynamic value near the top of the prompt, a timestamp or a user name or tool definitions serialised in a different order, breaks the match for the whole run. Put the static system prompt and tool schemas first, dynamic context last, and check your provider's current cache pricing and minimum cacheable length, because both change.
Route steps to different models
Classification, routing and field extraction rarely need your best model. Planning and final synthesis usually do. Split the loop so cheap steps run cheap, then re-run the eval set to confirm the small model holds on those steps specifically, not on the task as a whole.
Cap the loop and fail visibly
A step ceiling turns an unbounded worst case into a bounded one, which is what makes a forecast possible at all. The run that hits the ceiling is the most expensive run you have, so alert on the rate rather than logging it quietly.
Instrument the cost before you tune it
Write a cost record per run from the first day, not after somebody asks why the bill moved. It costs an afternoon at the start and is close to impossible to reconstruct later, because provider invoices arrive aggregated and cannot be split by ticket.
{
"run_id": "run_01J9KQ7Z8M",
"unit_of_work": { "type": "support_ticket", "id": "t_55219" },
"agent": "support-triage",
"steps": [
{ "n": 1, "model": "small", "in": 1840, "cached_in": 1500, "out": 96 },
{ "n": 2, "model": "small", "in": 2610, "cached_in": 1500, "out": 142 },
{ "n": 3, "model": "large", "in": 4380, "cached_in": 1500, "out": 380 }
],
"tool_calls": { "search": 4, "enrich": 1, "crm_write": 1 },
"prices": {
"source": "config/pricing.yaml",
"checked_on": "2026-08-19",
"note": "read at run time, never hardcoded in the agent"
},
"outcome": {
"status": "accepted",
"retries_on_invalid_output": 1,
"hit_step_cap": false,
"human_review_minutes": 0.0
}
}
The field that matters most is unit_of_work. Without it you can compute cost per run, which is the number that flatters you, but never cost per resolved ticket, which is the number somebody will ask for. Recording retries_on_invalid_output and hit_step_cap alongside it lets you separate expensive work from expensive failure, and those two have completely different fixes. Reading prices from config with a checked_on date keeps the ledger honest when a provider changes a rate.
Building an estimate you can defend
- Name the unit of work
One resolved ticket, one processed invoice, one qualified lead. Every number afterwards is per unit, and teams that skip this end up comparing cost per run against a colleague's cost per outcome.
- Pull twenty real cases from the last month
Real ones, including the awkward ones people complain about. Synthetic cases are shorter, cleaner and cheaper than reality, which is exactly how estimates end up half of what production charges.
- Spike the loop and record per-step usage
A rough agent is enough. What you need is the shape: how many steps, how large the tool results, how often the output fails to parse. Take token counts from the provider's usage fields.
- Take the median and the 95th percentile
Quote both. Budget on the 95th, because the tail is where the step cap and the retries live, and the tail is what a monthly invoice actually reflects.
- Add the other four lines with named assumptions
Tool calls per run times published rates, infrastructure divided by expected volume, review minutes times a loaded hourly rate. Write each assumption next to its number so anyone can argue with it.
- Re-measure two weeks after launch
Real traffic is more varied than your twenty cases. The first fortnight tells you whether the acceptance rate holds and whether the step distribution has a longer tail than the spike suggested.
- Estimating on the happy path. Failed runs usually reach the step cap, so they cost more than successful ones, and accuracy improvements cut the bill twice.
- Forgetting the eval bill. A nightly suite over a growing golden set is inference, and it can outspend production traffic in a low-volume system.
- Treating prices as fixed. Put every rate in config with the date it was checked, and re-run the estimate when a provider changes one.
- Ignoring context growth. A knowledge base that doubles usually doubles retrieved context in every step, so retrieval size belongs in the forecast.
- Comparing models on price per token rather than on cost per accepted outcome over the same case set.
A run that goes wrong rarely stops early. It loops, retries, re-reads and exhausts the step cap, so failure and cost are the same curve. That is why the mean misleads and the 95th percentile does not, and why work on how agents fail shows up on the invoice as well as in the quality numbers.
Terms worth being precise about
- Cost per accepted outcome
- The total cost of one unit of work divided by the fraction of runs whose output is accepted without rework. It is the only cost figure that stays honest when accuracy changes, because rejected runs are charged in full and deliver nothing.
- Loaded run
- The full cost of carrying one unit of work end to end: model tokens, paid tool calls, a share of standing infrastructure, human minutes, and remediation. A token-only estimate is a lower bound on a loaded run, not an estimate of one.
- Prefix caching
- A provider feature that charges less for the leading portion of a prompt when it matches a previous request exactly. It only works on an exact prefix, so any dynamic content placed before the static system prompt and tool schemas removes the discount.
- Step cap
- A hard ceiling on the number of model calls in one agent run, enforced in code rather than by instruction. It converts an unbounded worst case into a bounded one, which is what makes a per-run budget forecastable.
- Transcript growth
- The effect of a tool-calling loop re-sending the whole conversation on every step, so input tokens accumulate roughly with the square of the step count. It is why a single large tool result is charged once for every step that follows it.
Before you commit to a number
Work through this before the figure leaves your team, because a cost estimate becomes a commitment the moment somebody writes it in a plan. Most of it takes a day, and the alternative is explaining a bill nobody predicted. If the arithmetic says the numbers do not work, that is a finding: some jobs are better as a fixed pipeline, which agent or workflow covers.
Two related pieces: agent permissions and scope covers the budget ceilings that stop a stuck loop from spending the month in an afternoon, and token cost arithmetic works through the token maths on its own. Our AI agent development work starts with this estimate rather than ending with it.
Questions readers ask next
How much does an AI agent cost per run?
Why does an agent cost more than one model call doing the same job?
Is a cheaper model always cheaper overall?
What is the biggest hidden cost in an agent system?
Should I budget on average cost or worst case?
ChatGPTalker. "How to Cost an AI Agent Before You Build It." chatgptalker.com, 2026-08-26. https://chatgptalker.com/guides/costing-an-agent/