AI Agent Cost Control: Budgets, Model Routing and Cost per Task
A chatbot calls a model once per reply. An agent might call it a dozen times to finish one task: to plan, to choose tools, to read results, to retry, to write the answer. Each call carries a long prompt of instructions, history and retrieved documents. Costs that looked tiny in a demo can grow quickly at real volume.
The good news is that agent costs are predictable once you measure the right thing. This guide explains where the costs come from, how to calculate cost per completed task, the levers that lower it, and the budgets and guardrails that stop a runaway agent from becoming a runaway bill.
Where agent costs come from
The second row is easy to overlook. Input is usually the bigger share of tokens, because every call resends the same instructions and context. Trimming what goes into each call often saves more than switching models.
Cost per task: the number that matters
Price per million tokens tells you what a model charges. Cost per completed task tells you what your agent costs. To calculate it:
cost per task = (input tokens × input price) + (output tokens × output price), summed over every call in the task, including retries
Here's an illustrative task: a support agent that makes 6 model calls, each with about 3,000 input tokens and 400 output tokens. That's 18,000 input and 2,400 output tokens per task. Using prices from the MegaNova pricing page as of November 2, 2026, per 1 million tokens:
The numbers are only an illustration; your token counts and prices will differ. The pattern is what matters: the same task can cost several times more depending on which model handles which call, and retries multiply whatever the base cost is. Whether a cheaper model is good enough for each call is something only your own tests can tell you.
Levers that lower cost
Route by job. Not every call needs your strongest model. Use a stronger model where planning and hard reasoning happen, and faster, cheaper models for classification, routine steps and summaries. Test each role separately.
Trim the context. Every call resends the system prompt, tool descriptions, history and retrieved documents. Keep prompts focused, give each agent only the tools it needs, summarize long histories instead of resending them, and retrieve fewer, better passages.
Cap steps and retries. Set a maximum number of model calls, tool calls and retries per task. Without caps, a confused agent can loop until something times out.
Get it right the first time. Structured output that validates, clear tool descriptions and good error handling reduce retries, and retries are pure cost.
Reuse work. If many tasks need the same lookup or the same document summary, compute it once and reuse it rather than asking the model again.
Don't run what isn't needed. Background work that can wait can run in batches at quieter times; tasks a simple rule can handle don't need a model at all.
The order matters: routing and trimming context usually save the most, and they don't require changing what the agent does.
Budgets and guardrails
Levers lower the average cost. Guardrails protect you from the worst case:
- Per-task limits: a maximum number of steps, tokens and minutes for any single task.
- Per-user or per-customer budgets: daily or monthly caps, so one heavy user or a misbehaving integration can't consume everything.
- Alerts before limits: a warning at, say, 80% of a budget, while there's still time to act.
- A clear behavior at the limit: stop the task and hand it to a person, with a note on what was done, rather than failing silently or carrying on.
Put these limits in the system around the agent, not in its prompt. The model can't reliably count its own tokens, and a limit it's asked to respect isn't a limit.
What to measure
Track these from the first day of testing, not after the first surprising invoice.
Common mistakes
- Comparing price per token instead of cost per task. A cheaper model that needs more retries can cost more per completed task.
- One model for everything. Paying top prices for classification and routine steps.
- Ever-growing context. Resending the full history and every tool description on every call.
- No caps. A looping agent with no step limit is a bill with no ceiling.
- Limits in the prompt. "Use no more than five steps" is a request; enforce it in the system.
- Measuring late. Costs are cheapest to fix while you're still designing.
Checklist
- ☐ Cost per completed task is measured, including retries.
- ☐ Models are chosen per role and tested for each.
- ☐ Prompts, tool lists and retrieved context are trimmed to what each call needs.
- ☐ Steps, tokens, time and retries are capped per task.
- ☐ Per-user or per-customer budgets exist, with alerts before the limit.
- ☐ Hitting a limit stops the task and hands it to a person.
- ☐ Cost is tracked by feature or workflow.
Conclusion
Agent costs are predictable once you stop looking at price per token and start looking at cost per completed task. Route each job to a model that's good enough for it, trim what every call carries, cap steps and retries, and put budgets and alerts in the system around the agent. Then measure from day one, and re-check whenever models, prices or prompts change.
Explore LibraOS: libraos.com
Sources
What’s Next?
Sign up and explore now.
🔍 Learn more: Visit our blog and documents for more insights or contact us for a demo of how MegaNova can power your AI products.
📬 Get in touch: Join our Discord community for help or Contact Us.
Stay Connected
💻 Website: meganova.ai
📖 Docs: docs.meganova.ai
🎮 Discord: Join our Discord
👽 Reddit: r/MegaNovaAI
𝕏 X: @meganovaai