AI agent token budget calculator
Autonomous AI agents don’t consume tokens linearly — they grow quadratically. Every tool call appends observations back into the prompt history, so a 25-step agent re-reads the accumulated transcript 25 times. Model exact per-run token burn, retry inflation, and your safe hard cap below.
Interactive calculator
| Steps per Run | Total Input Tok | Final Context | Cost / Run (Cached) | Cost / Run (No Cache) | Monthly Spend |
|---|
Frequently asked questions
Why do AI agent costs grow quadratically with step count?
In a standard ReAct or tool-use loop, step k sends the initial prompt plus all k-1 prior tool outputs. Summing k from 1 to N produces O(N^2) cumulative input tokens: going from 10 steps to 40 steps can increase input token cost by 6x-10x.
How much does context compaction save on long agent runs?
Summarizing or truncating old tool outputs once context passes 40K-60K tokens caps the quadratic curve into a linear one, routinely cutting 40+ step agent run costs by 50%-70%.
What is a safe hard budget cap to set per autonomous agent run?
A good rule of thumb is 1.5x-2.0x your P50 expected run cost. If a normal 25-step coding run costs $0.85, setting a hard gateway cap at $1.50-$2.00 prevents infinite retry loops from burning $40+ while rarely interrupting valid runs.
How much do prompt caching and model routing help agent budgets?
Prompt caching slashes repeated prefix reads by 50%-90%, while routing observation parsing and lint/test steps to a cheaper model (Haiku 3.5 or DeepSeek-V3) cuts total run spend another 30%-50%.
Why should budget caps live outside the agent process?
An LLM stuck in a retry loop cannot reliably police its own token bill. Enforcing hard caps in a PreToolUse hook or API gateway guarantees execution stops at the exact dollar threshold.
All calculations run locally in your browser. Quadratic input token sum uses S = N*C0 + g*N*(N-1)/2 scaled by the retry multiplier; Anthropic/OpenAI/DeepSeek cache discounts reflect 2026 published rates.