GintiCalcEvery calculation

TraceMath

AI Agent Run Cost Calculator

Agent costs grow quadratically, not linearly — because every step re-sends the whole conversation.

Why an agent run costs more than steps times tokens

Each step re-sends the whole conversation, so input tokens grow quadratically with step count. Rows use a 2,000-token base prompt, 300 output and 800 tool-result tokens per step, at $3 and $15 per million.

StepsBase promptRetry rateInput tokensTotal tokensCost/runNaive estimateHidden multiple
52,00010%23,10024,750$0.0940$0.05251.79x
102,00010%76,45079,750$0.2789$0.10502.66x
105,00010%109,450112,750$0.3779$0.19501.94x
102,00030%90,35094,250$0.3296$0.10503.14x
202,00010%273,900280,500$0.9207$0.21004.38x

Doubling the steps from 10 to 20 does not double the cost, it triples it, because every earlier turn is re-sent on every later step. This is the single biggest surprise in agent budgets.

An AI agent cost calculator prices a single multi-step agent run the way the tokens are actually consumed, which is very different from how most teams estimate it. The near-universal mistake is to price an agent as steps multiplied by a per-call cost. That undercounts badly, because a conversational agent is stateless underneath: at every step the entire conversation so far — the system prompt, each prior model output, and every tool result returned along the way — is re-sent as input. Context does not stay flat; it accumulates.

The consequence is that input tokens follow an arithmetic series rather than a straight line. Step one sends just the base prompt. Step two sends the base prompt plus the first turn. Step ten sends the base prompt plus nine prior turns. Summed across a run, the growth term is the per-turn size multiplied by n(n−1)/2 — quadratic in step count. This calculator models that explicitly: it separates the base prompt re-sent each step from the accumulated context growth, adds the output tokens the model generates, applies a retry-and-error overhead for the failed calls every real agent makes, and prices input and output at their separate rates. It then shows the same run priced the naive flat-context way and reports the ratio between them, so the hidden multiple is visible rather than a surprise on the invoice.

That multiple is the point. Doubling an agent's step count does not double its cost — it roughly quadruples the context portion. This is why an agent that seemed affordable in a five-step demo becomes alarming at fifteen steps in production, and why the highest-leverage optimizations are architectural rather than commercial: trimming tool results before they enter context, summarizing or truncating old turns, splitting long chains into separate shorter runs, and using prompt caching so the stable prefix is not re-billed at full rate. The source research recommends deriving these numbers from real traces or provider exports rather than estimates, and that remains the gold standard — treat this calculator as the model you validate against your OpenTelemetry or provider usage data. It prices tokens only, and excludes tool-side compute, vector-database queries, and the engineering time to build and maintain the agent.

Why agent cost grows with the square of steps

Each step re-sends every prior turn, so total input tokens include a growth term of roughly (turn size) × n(n−1)/2. Going from 5 steps to 15 doesn't triple the context cost — it multiplies it about ninefold. Any agent design conversation should treat step count as the primary cost driver, well ahead of which model you pick.

Tool results are usually the biggest lever

Verbose tool output is the most common cause of runaway agent cost, because every token a tool returns gets re-sent on every subsequent step. Truncating a 5,000-token API response to the 300 tokens the model actually needs saves that difference multiplied across all remaining steps. Trim at the tool boundary before optimizing anything else.

Frequently asked questions

A 12-step agent with a 1,500-token prompt, 250 output and 800 tool tokens per step, at $3/$15 per million — what does one run cost?

Base prompt re-sent: 18,000 tokens. Context growth: 1,050 × 12×11/2 = 69,300 tokens. Output: 3,000 tokens. With 15% retry overhead that's about $0.35 per run — roughly 3.6× the $0.099 a naive flat-context estimate gives. At 1,000 runs/day that gap alone is about $7,600/month.

Why is my agent bill so much higher than my estimate?

Almost always context growth. If you estimated steps × per-call cost, you assumed context stays flat, but every step re-sends the full conversation including all prior tool results. The longer the chain, the worse the gap — it grows quadratically, so long-running agents diverge from naive estimates dramatically.

How do I actually reduce agent cost?

In order of impact: trim tool results before they enter context, cap or summarize conversation history, reduce step count by combining tools or improving planning, enable prompt caching so the stable prefix isn't re-billed at full rate, and route simple steps to a cheaper model. Changing model price alone is usually the weakest lever.

How is this different from the AI feature gross margin calculator?

The gross margin calculator prices per-user usage of a feature you sell and reports profitability against your price. This one prices a single agent run's token consumption in detail, exposing context growth and retries. Use this to understand and reduce what one run costs, then feed that figure into the margin calculator.

Related Developer calculators

You might also like

Last updated: August 12, 2026