AI agent cost per task
How do you track what one AI agent task actually costs?
Cost per task is the price of every model call, retry and paid tool call an agent makes to finish one task, added up at the rates on your provider bill. Cost per outcome divides your total agent spend by the tasks that actually succeeded, so failed runs and retries are paid for by the work that got done.
Last updated . Part of the AI agent cost control guides.
Why cost per task is the number that matters
A monthly bill tells you how much you spent. It doesn't tell you whether that was a lot for the work you got. Cost per task does: it is the number you can compare across agents, across models and across months, and the one you can put next to what the task is worth to the business.
Cost per outcome goes one step further. An agent that costs little per run but fails half the time is not cheap. Dividing by successful outcomes puts the failures back into the price.
What goes into the cost of one agent task?
One task is rarely one model call. Here is a support ticket handled by an agent, replayed call by call:
- 01Plan the taskReads the ticket and picks tools$0.012
- 02Look up the orderTool call$0.007
- 03Check the refund policyTool call$0.007
- 04Draft the refundTool call$0.007
- 05Payment API times outNo answer, the step has to run againtimeout
- 06Retry the refundSame work, paid twice$0.007
- 07Write the replyFinal answer to the customer$0.006
Count all of these:
- Every model call the task makes, including planning steps, tool-choice steps, summaries and any sub-agents it hands work to.
- Each token type at its own rate. Input, output, cache writes and cache reads are priced differently. On Anthropic, cache reads cost a fraction of the base input price and five-minute cache writes cost 1.25 times it (prompt caching pricing, checked 30 Nov 2026).
- Retries and loops. A call that timed out and was sent again is paid twice. A loop that calls the same tool ten times is paid ten times.
- Paid tools. Web search, embeddings, vector database queries and third-party APIs the agent calls during the task.
Why your provider bill can't show cost per task
Providers see API calls, not your tasks. OpenAI's Costs endpoint groups spend by project, user, line item, API key or API source, in one-day buckets. Anthropic's cost report groups by dimensions such as model, workspace, API key and the user or service account behind each request. Both are useful for checking totals, and neither knows that calls 14 to 22 were the same customer ticket. (Both checked 30 Nov 2026; links in the sources below.)
Cost figures your own SDK prints are estimates. Anthropic's Agent SDK, for example, says its cost fields are worked out on your machine from a bundled price table and shouldn't be used for billing. Use them for per-task numbers, and reconcile the total with the provider's report.
How to track cost per task, step by step
- Give every task an ID. Create it when the task starts and pass it to every call the task makes. If your agents call each other across services, carry it in a W3C trace context header so sub-agent calls land under the same task.
- Record usage on every call. Store the token counts the provider returns in each response, split by type, with the model, the task ID and whether the call was a retry. OpenTelemetry has standard attribute names for token usage on AI calls, but no attribute for cost, so you price calls yourself.
- Price each call from a dated price list. Keep a copy of each provider's rates with the date you read them. Prices change, and a cost you can't trace back to a rate is a cost nobody will trust.
- Add up by task. Sum every call with the same task ID. Keep the retries in.
- Mark the outcome. Record whether the task did what it was for: ticket resolved, report accepted, code merged. Pick a definition you can check automatically or by sampling.
- Reconcile monthly. Your summed task costs should land close to the provider's cost report. A big gap means calls without a task ID or an out-of-date price.
A worked example
A support agent resolves tickets. These numbers are made up to show the arithmetic.
One ticket, one attempt
Illustrative- Planning call
- $0.012
- Three tool-using calls
- $0.021
- One retry after a tool timeout
- $0.007
- Final answer call
- $0.006
- Cost per task
- $0.046
A month of tickets
Illustrative- Tasks run
- 10,000
- Total spend (10,000 × $0.046)
- $460
- Tickets resolved without a human
- 8,000
- Cost per resolved ticket ($460 ÷ 8,000)
- $0.0575
The agent looks like it costs under five cents a ticket. Each resolved ticket really costs about a quarter more, because 2,000 runs were paid for and didn't resolve anything.
Cost per outcome calculator
Change the cost per run, the number of runs and the success rate to your own numbers.
Cost per outcome = monthly spend ÷ runs that succeed. Put in your own numbers to see how much each finished task really costs.
What to do with the numbers
- Rank workflows by cost per outcome, not by total spend. A busy, cheap workflow can matter less than a quiet one that fails often.
- Look at the share spent on retries and failed runs. That money bought nothing, and it is usually the easiest to win back.
- Try a cheaper model on one step at a time, and compare both cost per task and success rate before you switch.
- Set a budget per agent once you know what a normal task costs, so a runaway loop stops at the cap instead of showing up on next month's bill.
Not sure where your team stands? The free agent setup check-up asks ten questions, including whether you can see cost per finished task, and runs entirely in your browser.
Where Alpha fits
Alpha records the tokens, model, latency and cost of every traced run against the agent that made it, and can pause an agent when it reaches its budget. Calls go through your own provider accounts with no markup. If you want to see cost per task on one of your agents, book a 30-minute teardown.
Related
More on AI agent cost
FAQ
Common questions
How do you calculate the cost of one AI agent task?
Give the task an ID, attach it to every model call and paid tool call the agent makes for that task, including retries and sub-agents, and add up the cost of those calls. Price each call from the token counts the provider returns, using separate rates for input, output, cache writes and cache reads.
What is cost per outcome for AI agents?
Total agent spend for a period divided by the number of tasks that reached the result you wanted in that period. It is always higher than the average cost per task, because the failed and retried runs are still on the bill.
Why doesn't my OpenAI or Anthropic bill show cost per task?
The provider only sees API calls. Their cost reports can group spend by things like project, API key, model or workspace, but they don't know which calls belonged to which of your tasks. That link has to come from your own tracing.
Do failed agent runs count in cost per outcome?
Yes. A failed run costs the same tokens as a successful one, so leaving it out makes the agent look cheaper than it is. Count every run in the spend, and only successful runs in the number you divide by.
How should cached tokens be counted in agent cost?
Separately from normal input tokens, because providers price them differently. On Anthropic, for example, a cache read costs a fraction of the base input price and a cache write costs more than it, so a single blended input rate gets the cost of a task wrong.
Sources
- OpenAI API reference: organization Costs endpoint (group_by and bucket_width), checked 30 Nov 2026
- Anthropic: Usage and Cost Analytics API, checked 30 Nov 2026
- Anthropic: prompt caching pricing, checked 30 Nov 2026
- Claude Agent SDK: tracking cost and usage, checked 30 Nov 2026
- OpenTelemetry: Gen AI attribute registry, checked 30 Nov 2026
- W3C Trace Context
Want cost per task on your own agent?
In 30 minutes we'll go through one of your agents on real runs and show what each task costs, including the retries.