What does one agent task actually cost?
A single ReAct agent run is not one API call — it is a loop of think, act and observe steps, each one a fresh LLM call that resends the growing conversation history. That is why agentic workloads can cost 10–50× a simple completion. This calculator models the loop honestly so you can budget per task and spot where the cost is hiding.
How it works
The tool simulates the loop step by step. At each step the agent’s prompt includes the system/task prompt plus all prior thoughts and observations, so the input grows every iteration. The model emits a thought/action (your output tokens per step), the tool returns an observation that is appended to the next prompt, and the cycle repeats for the number of steps you specify. Because history accumulates, total input tokens scale roughly quadratically with step count — the single biggest driver of agent cost. A retry budget then inflates the total to reflect backtracking and failed attempts.
Worked example
Suppose you run a web-research agent with these parameters:
- System + task prompt: 800 tokens
- Reasoning steps: 5
- Output tokens per step (thought + action): 150
- Tool calls per step: 1, each returning 300-token observations
- Retry budget: 15%
At step 1 the input is 800 tokens (system). After the step, the history grows by 150 (thought/action) + 300 (observation) = 450 tokens. At step 2 the input is 800 + 450 = 1,250. By step 5, the input is 800 + 4 × 450 = 2,600 tokens. The total across all five steps is roughly 800 + 1,250 + 1,700 + 2,150 + 2,600 = 8,500 input tokens, plus 5 × 150 = 750 output tokens, before the retry budget. A 15% retry budget inflates that to about 9,775 input and 863 output tokens. On a mid-range model at typical pricing, a task like this might cost a few cents — but multiply by thousands of tasks daily and the number becomes significant.
Why the quadratic growth matters so much
For a simple task with a compact system prompt and short observations, the quadratic effect is mild. But tasks that produce large observations — for example, reading whole web pages or database query results — compound quickly. An observation that returns 2,000 tokens per step means the input at step 10 is the system prompt plus nine steps’ worth of 2,000-token blocks, dwarfing the system prompt itself. This is where most unexpected agent bills come from.
Tips to control agent cost
- Cap the steps. A hard maximum on loop iterations prevents a runaway task from quietly burning your budget.
- Compress history. Summarise old thoughts and observations instead of resending them verbatim — this directly attacks the quadratic growth.
- Keep observations lean. Truncate or post-process tool outputs before feeding them back; raw API dumps are expensive to carry forward.
- Mix models. Use a cheap model for routine reasoning steps and a stronger one only for planning or the final answer.
- Batch or cache repeated context. If every task starts with the same large system prompt, caching that prefix (where the API supports it) avoids paying for those tokens on every step of every run.
- Profile a real run first. Log the actual token counts for a sample task, then use this calculator to project costs at scale. Estimates made without a real sample often undercount by 2–5× because tool observation size is hard to predict without data.