How much does it cost to run an AI agent, and how can you reduce it?
Agent costs can surprise people. A single task may involve many model calls, each resending a growing context.
What drives cost
- Number of steps: every tool call usually means another model call
- Context size: long instructions, big tool outputs and full histories get re-sent repeatedly
- Model choice: larger models cost more per token
- Retries and loops: failures that cause repeated attempts
- Parallel sub-agents: useful, but each one consumes its own tokens
Ways to reduce cost
- Prompt caching: many providers discount repeated prompt prefixes, so keep stable instructions at the start
- Trim tool outputs: return only the fields the agent needs, not entire documents or API responses
- Use smaller models for simple steps like classification or routing, and larger ones for hard reasoning
- Summarize history instead of carrying everything forward
- Set step and budget limits to stop runaway tasks
- Cache results of expensive tool calls
- Improve tool design so tasks need fewer steps
Measure first Log token usage per step to see where spend actually goes. It is often one bloated tool output or an unnecessary loop.
What has been the biggest cost surprise in your agent projects? Which optimization saved the most?
Comments · 3
Cost per task is the number that matters. A cheaper model with retries can end up more expensive than a stronger one that finishes in one pass.
If you charge customers for agent work, margin per task needs tracking from day one. Surprise bills can kill a pricing plan.
Caching and context trimming are the standard savers, but I'd measure the quality hit. Cheap shortcuts sometimes reduce accuracy in ways that show up later.