Skip to content
MyStackCost
Leer en español

Why AI agents cost more than you expect

An AI agent can burn dozens of times more tokens than a chatbot. Why accumulated context drives the bill up, with worked examples and ways to bring it down.

Published: 7 min read

Most teams budget for an AI agent the way they budget for a chatbot: estimate the tokens in a request, multiply by the price per million, multiply by the number of requests. The first invoice usually proves that estimate wrong, and not by a little. A chatbot answers with one call to the model. An agent works through a task in a loop (plan, call a tool, read the result, call the model again) until it is done. That loop is what makes agents useful, and it is also why an agent’s cost grows faster than its number of steps.

This guide walks through where the extra cost comes from, with worked numbers, and what you can do about it without giving up what makes the agent worth having. To run the numbers for your own agent, use our AI agent cost calculator.

One call versus a loop

When someone asks a chatbot a question, the model receives the system prompt and the question and writes an answer. You pay for that input once and that output once.

An agent runs the same cycle many times per task, and the model has no memory between calls. To decide what to do on step 6, it has to be shown everything that happened on steps 1 to 5: the system prompt and tool definitions, the original request, every reply it wrote and every result a tool returned. Each call carries the full history of the task so far.

Why the cost grows faster than the steps

Picture the context as a stack of paper handed to the model on every step. Step 1 gets the starting stack. Step 2 gets the starting stack plus what step 1 added. Step 3 gets the starting stack plus what steps 1 and 2 added, and so on. Over a task of N steps, the total input is:

Total input = N × (base context + request) + (output per step + tool result) × N × (N − 1) ÷ 2

The first part grows in line with the steps. The second part, the history the agent keeps re-reading, grows with the square of the steps. That is why doubling the steps more than doubles the bill.

A worked example

Take an agent running on Claude Sonnet 5.5, at $2 per million input tokens and $10 per million output tokens. Every step sends 2,000 tokens of system prompt and tool definitions, the user’s request is 500 tokens, the model writes 300 tokens per step and each tool call returns 700 tokens. A typical task takes 10 steps.

  • Total input: 10 × 2,500 + 1,000 × 45 = 70,000 tokens
  • Total output: 10 × 300 = 3,000 tokens
  • Cost per task: 70,000 × $2 ÷ 1,000,000 + 3,000 × $10 ÷ 1,000,000 = $0.14 + $0.03 = $0.17

A plain one-step call with the same request would use 2,500 input tokens and 300 output tokens: 2,800 tokens, or $0.008. The agent uses about 26 times as many tokens and costs about 21 times as much per task. Notice where the money goes: the model only writes 3,000 tokens, but it reads 70,000. In agents, input is almost always the bigger line item.

How much the number of steps matters

Keeping everything else the same, this is how the cost per task changes with the number of steps:

Steps Cost per task Cost at 10,000 tasks a month
1 $0.008 $80
5 $0.06 $600
10 $0.17 $1,700
20 $0.54 $5,400

Going from 10 to 20 steps doubles the steps but multiplies the cost by 3.2. An agent that “sometimes takes the scenic route” can blow through a budget that looked comfortable in testing, where tasks tended to be short and clean.

The other things that inflate the bill

Tool results

Whatever a tool returns stays in the context for every step that follows. If each tool call in the example returned 3,000 tokens instead of 700, which is easy to hit when a tool fetches a whole web page or a full database record, total input would climb to 10 × 2,500 + 3,300 × 45 = 173,500 tokens and the cost per task to $0.377. That is more than double, with exactly the same number of steps.

Retries

When a task fails and starts again from the beginning, you pay for the whole run twice. With 10% of tasks retried, the average cost per task rises by 10%. In the example, an average task then uses 77,000 input tokens and 3,300 output tokens, and the cost per task goes from $0.17 to $0.187. At 10,000 tasks a month, the bill rises from $1,700 to $1,870: $170 a month spent purely on repeated work. Retries also tend to cluster in the longest tasks, which are the most expensive ones, so track them separately rather than assuming they are rare.

Long-context pricing

Some models charge a higher rate once a single call goes over a certain size. Because an agent’s context grows on every step, the late steps of a long task can cross that threshold even when the early ones are well below it. Our calculator applies the higher price step by step, only to the calls that cross it.

How to bring the cost down

1. Cap the steps

Set a maximum number of steps per task and a clear stopping condition. Because the cost grows faster than the steps, this is the single change with the biggest impact.

2. Trim what tools return

Pass the model only the useful part of each result: the relevant fields, not the whole response or document. In the example, cutting tool results from 700 to 300 tokens brings total input down to 10 × 2,500 + 600 × 45 = 52,000 tokens and the cost per task to $0.134, which is 21% less.

3. Summarize the history

On long tasks, replace the full history with a short summary every few steps. The context then grows slowly instead of carrying every earlier result verbatim.

4. Cache the base context

The system prompt and tool definitions are identical on every step. If your provider offers prompt caching, that repeated part can cost much less after the first call. Discounts and conditions vary by provider and model, so check the details for yours.

5. Match the model to the step

Not every step needs your most capable model. Many systems use a cheaper model for routine steps, such as classifying a request or extracting a field, and save the stronger one for planning and hard decisions. Our guide on how to reduce LLM API costs works through this routing approach with numbers.

6. Measure cost per task, not per token

The price per million tokens tells you nothing about what it costs to finish a job. Log how many steps and tokens each real task uses, and set an alert when a task goes over a sensible cost.

Getting realistic inputs

The estimate is only as good as the numbers you feed it, and the numbers from a demo are usually too optimistic. Before you set a budget, run the agent on a sample of real tasks, including messy ones, and log for each call the input and output tokens your provider reports. From those logs you can read the base context (the size of the first call minus the request), the average output per step, the average tool result and the number of steps per task. Use the average for a typical month and a high percentile for a bad one. If you plan to compare models, compare a single call first with our LLM API cost calculator, then check the per-task picture in the agent calculator, since a model that is cheaper per token can still lose if it needs more steps.

Is it worth it?

Even at 20 steps, $0.54 per task can be a bargain if a person would spend 15 minutes on the same task. What matters is comparing the cost with the real value, keeping in mind that tasks the agent gets wrong still need human review. Our calculator includes an optional comparison with doing the task by hand.

Say the task takes a person 15 minutes at $25 an hour. Doing it by hand costs 15 ÷ 60 × $25 = $6.25. Even at 20 steps, the agent costs $0.54 and saves $5.71 per task, or $57,100 a month at 10,000 tasks. The math changes once review enters the picture: if someone spends 5 minutes checking every task, that review costs about $2.08, almost four times what the agent costs. The number that matters most is not the price per token but how many tasks the agent gets right without help.

The bottom line

An AI agent costs more than a chatbot for a structural reason: every step carries the context of all the steps before it, so the cost grows faster than the number of steps. Capping steps, trimming tool results and summarizing the history are the most effective ways to keep it under control. Before putting an agent in production, work out its cost per task in the AI agent cost calculator and see how it changes with more or fewer steps.