Agent loop pricing

What does one agent run actually cost?

Most calculators price a single API call. An agent makes dozens of them, and every step re-sends everything that came before it. Input tokens grow with the square of the step count. This models that.

18 models · No signup · Nothing leaves your browser

Raw conversation21,700tokens
Billed input135,600tokens
Multiplier6.2×
With 90% caching−69%cost

A 12-step agent. 2,000-token system prompt, 500-token task, 400 output and 1,200 tool-result tokens per step, zero retries. The calculator below defaults to a 10% retry rate, which reports 6.9×, because retries re-send context too.

Model your workload

Set the shape of one agent run. Everything recalculates as you drag, and the URL updates so you can share the exact configuration.

Workload

Sent on every single step. Usually cacheable.
One step is one model call. A tool call plus its response counts as one.
Include reasoning tokens. They are billed as output.
Search results, file reads, API responses. The quiet budget killer.
Failed tool calls, malformed output, guardrail rejections.
Cached input costs about 90% less. The biggest single lever you have.

Scale

Cost of one run

···
Per run
···
Per day
···
Per month
···
Per year

Where the money goes

Context re-sent System prompt Output Task input

Same workload, every model

ModelPer run Per monthvs. best

Cost accumulation by step

StepContext sentStep cost Running total
Step 1 is cheap. Step 40 is not. Context sent at step i equals system + input + (i−1) × (output + tool result), which makes total input tokens grow as O(N²) rather than O(N). Capping steps or trimming tool output beats switching models more often than teams expect.

Why agent costs surprise people

Language models are stateless. They remember nothing between calls, so an agent has to re-send its entire history on every step. Step 1 sends a little. Step 2 re-sends step 1 plus whatever is new. Step 10 pays for steps 1 through 9 all over again.

Total input tokens across N steps come out as:

N × (system + user) + (output + tool_result) × N × (N−1) / 2

That second term is quadratic. Double the steps and you roughly quadruple the input cost. It is the most consistent reason real invoices beat estimates.

Which half of the formula matters flips early, and this is where most cost-cutting goes wrong. The system prompt and the task sit in the linear term. Only the output and tool results carry the quadratic one. For the workload below the two are equal at about four steps; by step 12 the quadratic term is 78% of billed input, and by step 50 it is 94%. So shortening the system prompt attacks the part that has almost stopped growing. Cache it instead, and spend the effort on step count and tool-result size.

A worked example

A 12-step agent with a 2,000-token system prompt, 500-token task, 400 output tokens and 1,200 tool-result tokens per step has a raw conversation length of 21,700 tokens, and bills 135,600 input tokens. That is a 6.2× multiplier which shows up on the invoice and in nobody's estimate.

The 6.2× figure is the context effect on its own, at a 0% retry rate. The calculator defaults to a more realistic 10% retry rate, which is why it reports 6.9×. Retries re-send context too. Set retries to zero to isolate the pure loop effect.

The three levers, in order

  1. Prompt cachingMost of the bill is context re-sent verbatim, and cache reads cost roughly 90% less. In the example above, a 90% hit rate takes the run from $0.351 to $0.110 on Claude Sonnet 5. Same model, same agent. The system prompt is the one segment sent byte-identical on every call, which makes it the easiest thing to cache and the wrong thing to trim.
  2. Step countCutting steps beats switching to a cheaper model in most configurations, because step count is superlinear while price is linear. Going from 20 steps to 10 saves more than moving from a frontier model to a small one.
  3. Tool-result sizeUnderrated, because every tool result is re-sent by every step that follows it. Truncating a 5,000-token search result to 1,000 compounds across the whole run.

Assumptions and limits

Retries are modelled as a flat multiplier on total cost. Real retries occur at a specific context depth, so failures late in a run are under-counted. Cache hit rate is a single figure rather than per-prefix. Providers use different tokenizers, so cross-vendor token counts are approximate. The same is true inside Anthropic's own lineup: Claude 4.7 and later, which covers Sonnet 5, Opus 5 and Fable 5, use a newer tokenizer that turns the same text into about 30% more tokens than Haiku 4.5 does. Entering one token count and comparing those models therefore understates what Sonnet 5 bills for the same work. OpenAI's GPT-5.6 charges 1.25× uncached input for cache writes, which is not modelled here, only reads. Treat the output as a planning estimate, not a billing forecast.

Each model carries one rate, so tiered pricing is flattened, and the direction of the error differs by provider. DeepSeek bills peak and off-peak, with off-peak half the peak rate; the figures here are peak, so a run scheduled outside 01:00 to 04:00 and 06:00 to 10:00 UTC on a weekday costs about half what is shown. OpenAI, xAI and Google instead raise rates once a single request gets large, and the figures here are the base tier, so a long agent is undercharged rather than overcharged. Grok and Gemini change gear at 200K tokens, Grok by doubling every rate. OpenAI's threshold is higher at 272K, where the whole request is rebilled at 2× input and 1.5× output, taking GPT-6 Astra from $10 / $50 to $20 / $75. On the default workload the largest single request is about 81K tokens at 50 steps, so this starts to bite past roughly 125 steps on Grok and Gemini and 170 on OpenAI.

Questions

Why does an AI agent cost more than the token math suggests?
Every step of the loop re-sends the entire prior context, because the model holds no state between calls. Total input across N steps is N × (system + user) + (output + tool result) × N × (N−1) / 2. The second term is quadratic, so a 12-step agent with a 2,000-token system prompt and 1,200-token tool results bills about 135,600 input tokens against a raw conversation length of 21,700.
What is the fastest way to reduce agent costs?
Prompt caching, usually by a wide margin, because most of the bill is re-sent context and cache reads cost about 90% less. Reducing step count comes next, since step count is superlinear while price is linear. Trimming tool-result size is third, because each result is re-sent by every subsequent step.
How is this different from a normal LLM pricing calculator?
Standard calculators price a single API request: input tokens times rate, plus output tokens times rate. That is correct for a chatbot, and it understates agent costs by several times, because it ignores the context re-sent on every step of the loop.
Does this send my data anywhere?
No. Every calculation runs in your browser. There is no account, no request carrying your numbers and no analytics on what you type. Shareable links encode the configuration in the URL itself, so the link is the only thing that travels.
Where do the prices come from?
Each rate is taken from the provider's own public pricing page and carries a verification date. Prices were last checked on 5 September 2026. Claude Sonnet 5's $2 / $10 was announced as introductory through 31 August 2026, but Anthropic cancelled the increase to $3 / $15 and $2 / $10 is now the standard rate. Confirm against the official page before you commit budget.