Cost Control for AI Agents
Agents can get expensive fast - tokens times iterations times subagents. A few simple controls help.
Why agents get expensive
A single chat call usually costs little. An agent, though, often calls the model many times in a row - for planning, tool use, intermediate steps, sometimes across several subagents at once. Costs multiply: tokens per call times number of iterations times number of parallel subagents.
Lever 1: Budgets and caps
Set hard limits - a maximum number of iterations, a maximum token budget per task, or a maximum cost per run. That way a stuck agent can't let costs run indefinitely.
Lever 2: Model routing
Not every subtask needs the most expensive model. Simple, mechanical steps (formatting, short summaries) can run on cheaper, smaller models, while complex planning stays reserved for the pricier one.
Lever 3: Keep context small
The more context (files, history) gets sent with every call, the more input tokens you pay for - on every single step. Sharing only the relevant excerpts instead of whole files or full chat histories saves money directly.
Lever 4: Usage monitoring
Track how many tokens actually get used - per task, per day, per user. Without monitoring, you often only notice a cost blowup once the bill arrives.
EXAMPLE
Conceptual example: a code-review agent gets a limit of at most 10 iterations and a cost cap per run - if it exceeds that, it stops in a controlled way instead of running forever.
QUICK QUIZ
Why do agents often end up more expensive than single chat requests?
SOURCES
- Anthropic docs: Pricing โ claude.com
- OpenAI: API Pricing โ openai.com