How the cost of an AI agent is calculated
A chatbot usually answers with one call to the model. An agent solves a task in several steps: it reads the request, decides which tool to use, reads the result, decides again, and so on until it finishes. Each step is a call to the model, and each call re-sends everything that happened before. The calculator adds up the cost step by step:
Input tokens of step k = S + U + (k − 1) × (O + T)
Input tokens per run = N × (S + U) + (O + T) × N × (N − 1) ÷ 2
Output tokens per run = N × O
Model cost per run = Σ (step input tokens ÷ 1,000,000 × input price
+ O ÷ 1,000,000 × output price)
Cost per task = model cost per run × (1 + retry %) × exchange rate
+ cost per external tool call × calls per task
Monthly cost = cost per task × tasks per month
Yearly cost = monthly cost × 12
Where N is the number of steps, S the base context sent on every step (system instructions and tool definitions), U the user’s request, O the output tokens of each step and T the tokens each tool returns. A simple one-step query uses S + U input tokens and O output tokens; the calculator compares the agent with it to show how many times more tokens the agent uses.
Prices come from the list that is updated automatically every day, in US dollars per million tokens. If the input of a step goes over a model’s long-context threshold, that step (input and output) is charged at the higher price; earlier steps keep the normal price. If you pick another currency, the calculator converts the model cost with an editable exchange rate, and the external tool cost and the hourly cost of the person are entered directly in that currency.
Worked example
A software company runs a research agent that answers customer questions about its product. It handles 2,000 tasks a month, and each task takes 10 steps. Every step sends 2,000 tokens of instructions and tool definitions, the customer’s question is 500 tokens, each step writes 300 tokens and each tool returns 700 tokens. 10% of tasks fail and run again from scratch, and each task makes 3 calls to a search API at $0.01 per call. Without the agent, a person needs 15 minutes per task at $25 an hour.
With a model priced at $2.00 per million input tokens and $10.00 per million output tokens (example prices; the calculator uses the current ones):
- Input tokens per run: 10 × (2,000 + 500) + (300 + 700) × 10 × 9 ÷ 2 = 25,000 + 45,000 = 70,000
- Output tokens per run: 10 × 300 = 3,000
- Model cost per run: 70,000 × $2 ÷ 1,000,000 + 3,000 × $10 ÷ 1,000,000 = $0.14 + $0.03 = $0.17
- With 10% retries: $0.17 × 1.1 = $0.19 of model per task, which is 77,000 input and 3,300 output tokens on average
- External tools: 3 × $0.01 = $0.03 per task
- Cost per task: $0.22
- Monthly cost: $434.00, or $5,208 a year
- A simple one-step query uses 2,800 tokens, so the agent uses 29× as many tokens
- The same task done by a person: 15 ÷ 60 × $25 = $6.25. The agent saves $6.03 per task, or $12,066 a month
Amounts are rounded the same way as in the calculator; each step uses the unrounded values.
Input tokens are 71% of the cost per task, output tokens 15% and the search API 14%. Even though each step writes only 300 tokens, the accumulated context makes input the largest item by far.
How the cost grows with the number of steps
With the same tokens per step, retries and tools, this is how the cost changes when the agent needs more or fewer steps:
| Steps | Input tokens per task | Cost per task | Monthly cost |
|---|---|---|---|
| 1 | 2,750 | $0.04 | $77.60 |
| 5 | 24,750 | $0.10 | $192.00 |
| 10 | 77,000 | $0.22 | $434.00 |
| 20 | 264,000 | $0.62 | $1,248 |
Going from 10 to 20 steps doubles the steps but multiplies the input tokens by more than three. That is the effect of the accumulated context: every new step carries all the previous ones.
Why agents cost much more than a chatbot
Three things make an agent more expensive than a single model call:
- The context accumulates. Each step re-sends the instructions, the request and every earlier output and tool result. The last step of a 10-step task reads the whole history, which is why input tokens grow with the square of the steps.
- The number of steps multiplies everything. Each step is a full call to the model, with its base context. An agent that takes 20 steps where 10 would do pays more than double.
- Retries repeat the whole run. When a task fails halfway and starts again, you pay for both attempts. A retry rate that looks small adds up across thousands of tasks.
Tool results are often the hidden part of the bill. A search that returns ten full web pages, or a database query that returns every column, can add thousands of tokens that the agent then carries on every later step.
How to reduce the cost of an agent
- Use fewer steps. Give the agent tools that do more in one call (one search that returns what it needs instead of three narrow ones), and stop the task as soon as it has an answer.
- Summarize the context between steps. Instead of carrying every earlier result in full, replace old steps with a short summary. The input of later steps stops growing so fast.
- Make tool results shorter. Return only the fields and paragraphs the agent needs. Cutting T from 700 to 300 tokens in the example lowers the input of every later step.
- Use the right model for each step. Simple steps, such as choosing a tool or extracting a field, can run on a small, cheap model, while a more capable model handles planning and the final answer. Compare the cost per task of every model in the chart above.
- Reduce retries. Validate the inputs before starting, set step limits and resume from the last good step instead of starting from scratch.
- Keep the base context lean. System instructions and tool definitions are sent on every step. Remove tools the agent never uses and rules that no longer apply.
Our guide on how to reduce LLM API costs covers more techniques, such as prompt caching and batch processing. To compare the monthly cost of a single model call across providers, use our LLM API cost calculator, and if your assistant answers customers in one call per conversation, our AI chatbot ROI calculator estimates the savings against your support team.
What this estimate does not include
The calculator assumes every step adds the same tokens and every task takes the same number of steps. Real agents vary from one task to the next, so use the average of a sample of real tasks and compare a typical and a pessimistic scenario. It does not include prompt caching or batch discounts, reasoning tokens that some models bill as output, the cost of the infrastructure that runs the agent, or the time spent reviewing its work. Use the result to compare options and set a budget, not as a guaranteed figure.
Frequently asked questions
Why does an agent cost so much more than a single call to the model?
Because every step re-sends the whole conversation so far. Step 10 includes the instructions, the request and the outputs and tool results of the nine steps before it. The input tokens grow with the square of the number of steps, so doubling the steps roughly quadruples the part of the cost that comes from the accumulated context.
What counts as a step?
Each call to the model. A typical agent step is a model call that decides what to do, asks for a tool (a search, a database query, a calculation), and then receives the tool result as input on the next step. If your agent framework logs model calls, count them for a few real tasks and use the average.
How are retries counted?
As tasks that fail and run again from the first step, so a retry costs the same as a full run. With 10% retries, the model cost per task is multiplied by 1.1. Retries of a single step cost less; if that is your case, enter a lower percentage.
Where do the AI model prices come from?
From the same price list as our LLM API cost calculator. It is checked automatically every day against public sources that track the official rates, and the page shows the date of the last update and links to each provider's pricing page. If a step goes over a model's long-context threshold, that step is charged at the higher price.
Does the calculator include prompt caching discounts?
No. Several providers charge less for input tokens that repeat from one call to the next, which is common in agents because each step starts with the same instructions and history. The discounts and conditions vary by provider and model, so the calculator uses the standard price and the result is a conservative estimate.
Is the data I enter stored?
No. All calculations run in your browser. Values only leave your device if you use the share button, which puts them in the link you copy.