An AI agent task costs the sum of its steps, and each step costs more than the last. Every step sends the conversation so far as input, generates reasoning and an answer billed at the output rate, and may call tools that carry their own fees and run in compute that is billed separately. A 10-step task is not ten times a chat request; it is closer to the cost of a long conversation, and an agent that loops 40 times instead of 10 can cost more than four times as much. This guide breaks the bill into its parts, works one task through at list rates, and sets out the budgets, limits and questions that keep agent spend bounded.
What an agent bill is made of
| Component | How it is billed | What drives it |
|---|---|---|
| Input tokens per step | Model input rate; cached prefix at the cache-read rate | Context grows every step: system prompt, tool definitions, earlier steps and tool results |
| Output and reasoning tokens | Model output rate, typically several times the input rate | Effort setting, task difficulty, planning steps |
| Tool calls | Per call, plus result tokens at model rates | Searches, fetches, file search, computer use |
| Hosted compute | Per container session, container-hour or session-hour | Code execution, sandboxes, long-running sessions |
| Retries and loops | Every repeated step is billed again | Errors, timeouts, an agent that does not converge |
| Seats (coding agents) | Per user per month, with usage limits | Number of developers, plan tier |
Tokens per step, and why context grows
A chat request sends one prompt. An agent step sends the system prompt, the tool definitions, the user's task and everything that happened in earlier steps: the model's own messages, its tool calls and every tool result. A web page fetched at step 2 is still in the input at step 9 unless the agent trims it.
Tool definitions add tokens on their own. Anthropic, for example, adds a tool-use system prompt of 286 tokens on Claude Opus 5.5, Sonnet 5.5 and Haiku 5.5 whenever tools are provided, on top of the tool names, descriptions and schemas you send1. An agent with thirty tools carries their schemas on every step.
Prompt caching is what makes long agent contexts affordable. On Claude Opus 5.5 and Sonnet 5.5, a cache hit costs 0.05 times the base input price, while a 5-minute cache write costs 1.25 times1. On OpenAI, GPT-6 Sol lists cached input at $0.20 against $2.00 uncached2.
Reasoning tokens
Thinking models bill their reasoning as output, and output is the expensive side. On agent loops the cost is uneven: steps that plan carry most of the reasoning, steps that only read a tool result carry less. Anthropic notes that you cannot turn thinking off on Opus 5.5, Sonnet 5.5, Haiku 5.5 or the Fable models in Claude Code3; lowering effort is the lever. How each provider counts reasoning is in reasoning tokens: the hidden cost of thinking models.
Tool calls
Server-side tools are billed per use on top of tokens:
- Web search. OpenAI lists $10.00 per 1,000 calls, with search content tokens billed at model rates2. Anthropic lists $10 per 1,000 searches plus the tokens of search-generated content, and counts search results as input tokens both within the turn and in later turns1.
- Web fetch. Anthropic charges no fee beyond the tokens of the fetched content1, which can still be large: a fetched page stays in context.
- File search. OpenAI lists $2.50 per 1,000 tool calls plus $0.10 per GB per day of storage after the first GB2.
The fee per call is small. The tokens a search or fetch adds to every later step are usually larger.
Hosted sandboxes and code execution
Agents that run code need somewhere to run it, and that compute is billed apart from tokens.
- OpenAI. Hosted Shell and Code Interpreter containers are listed at $0.03 (1 GB), $0.12 (4 GB), $0.48 (16 GB) or $1.92 (64 GB) per 20-minute session per container, and the same page says eligible sessions are billed by the minute with a 5-minute minimum2. On 9 October 2026 OpenAI changed sandboxes used by the Agents API: "OpenAI-hosted sandbox compute is now billed during active turns," with no charge for idle time between turns, and added pre-warming of a sandbox before it is attached to a session4.
- Anthropic. The code execution tool is free when web search or web fetch is in the same request; otherwise each organization gets 1,550 free hours a month and then pays $0.05 per hour per container1. Claude Managed Agents bill tokens plus $0.08 per session-hour of runtime, measured only while the session is
running; idle time does not count, and it replaces container-hour billing1.
For a short task, compute is small next to tokens. For a sandbox held open on large memory it is not: a 64 GB container at $1.92 per 20 minutes is $5.76 an hour if it stays busy. The 9 October change matters most for agents that wait on people between turns.
Retries and loops
A retried step is billed again in full, including its whole context. A loop that does not converge is the largest single cost risk in agent systems, because context keeps growing while it runs. Bounding loops is covered in detail in bounding AI agent loops.
One agent task, worked through
Two conclusions survive any change to the inputs. Step count is the variable that matters most, because context, and therefore input, grows with it. And caching is not optional for agents: it is the difference between a context that costs little to resend and one that dominates the bill.
At volume the per-task numbers become a budget line. At $0.62 a task, 2,000 tasks a day is about $1,240 a day of estimated provider usage, roughly $37,000 over a 30-day month. If one task in fifty loops to 40 steps, the month gains about $2,500 more.
Coding agents: seats versus API usage
Coding agents are the agents most companies already run, and they are bought two ways.
| Per seat | Per token (API) | |
|---|---|---|
| Example | ChatGPT Business, which includes Codex: $20 per user per month billed annually, $25 monthly5 | Codex with an API key, or Claude Code on API billing, at API rates53 |
| Cost shape | Fixed per person | Scales with use |
| Ceiling | Usage limits per window; Claude Team and Enterprise seats draw on an allowance shared with Claude chat3 | None unless you set one |
| Visibility | Vendor admin analytics | Per-key usage, cost APIs, telemetry |
| Fits | Interactive individual use | Automation, CI, shared agents, heavy users |
For budgeting, Anthropic reports that across enterprise deployments Claude Code on API billing averages around $13 per developer per active day and $150 to $250 per developer per month, with 90% of users under $30 per active day3. It also notes that agent teams use roughly seven times more tokens than standard sessions when teammates run in plan mode3. OpenAI warns that API token prices are separate from subscription usage and should not be used to estimate what a seat includes5. The full comparison is in coding agent costs for teams.
Budgets and kill switches
Agent spend needs limits at three levels, and each level catches what the one inside it misses.
- Per run, in the agent's code. A maximum number of steps, tokens, wall-clock time and estimated spend. When any is reached, the run stops and reports why. This is the cheapest control and the easiest to bypass by a bug.
- Per agent, outside the code. Give each agent or worker its own API key with a hard spend limit, daily or lifetime. Whatever the loop does, the key cannot spend past it. Set
max_tokenson every call so a single step cannot run away. - Per organization and per provider account. A monthly cap and alerts, and the provider's own spend limit on the account, which holds even if everything in front of it fails.
A kill switch is a control that stops model calls immediately without deploying code: disabling the agent's key, or a provider-side limit set to zero. Test it before you need it, and write down who may use it.
Questions to ask the team
- How many steps does a typical run take, and what is the 95th percentile? What stops a run that does not converge?
- What is the cost per completed task, and per failed one? How many runs fail?
- Is prompt caching working, and what share of input tokens are cache reads?
- Which tools does the agent call, at what fee, and how much context does each result add?
- Where does code run, and is that compute billed while idle?
- Does each agent have its own key with a hard limit, and who can turn it off?
- For coding agents: how many seats are used, how much API spend sits beside them, and what has changed in lead time or merged changes since rollout?
Capping agent spend with INFRO
INFRO is a control plane between your agents and the provider accounts you connect; your providers bill you directly, and INFRO's limits act on its estimate of that provider cost.
A key per agent, with a hard cap. A gateway key can carry a spend limit that resets daily, weekly or monthly, or a lifetime limit; key limits always block, and a request over one returns 402 with a code such as key_budget or key_lifetime_limit before the provider is called. A key can also be turned off, after which its requests return 403 key_disabled, which is the kill switch above. See spend controls and authentication.
Reservation before the call. A blocking budget admits a request only if its worst-case estimated cost fits the room left, counting requests still in flight; a chat request with no max_tokens reserves the model's maximum output, so setting it lets more concurrent steps fit.
Cost per run. Tag each call with metadata.trace_id, and request traces return every request in the run with estimated cost by step. Per-customer caps on metadata.user_id bound what each of your customers' agent runs can spend (end-customer caps). Claude Code and Codex can be pointed at INFRO with a base URL and a gateway key, so the same limits apply to them (coding agents).
What INFRO does not cover: provider-side tool fees and hosted sandbox or container compute are billed by your provider and are outside INFRO's estimates, and seat-based plans such as ChatGPT Business never pass through INFRO. Keep provider-side spend limits on as well.
