OverpayingForAIPricing desk
9 min read·Last reviewed for accuracy · 2026-09-11·Prices verified · 2026-09-12

How Much Does an AI Agent Cost to Run? Cost Per Task in 2026

Worked cost traces for 5-, 12- and 30-step tool-using agent runs on Claude Sonnet 5, GPT-5.4, Gemini 3.8 Flash and DeepSeek V4 Flash, and why cost per successful task is the only number that matters.

The article text carries the review date. The rate table below is rebuilt from the live catalogue on every deploy.

Fastest win

A typical 12-step tool-using agent run sends about 167,000 input tokens and 3,600 output tokens, because every step re-sends the whole growing context. That is $0.37 on Claude Sonnet 5, $0.47 on GPT-5.4, $0.14 on Gemini 3.8 Flash and under a cent on DeepSeek V4 Flash. Prompt caching cuts the Sonnet 5 figure to roughly $0.12. Budget per successful task, not per token.

The direct answer: $0.01 to $0.50 per run, $0.05 to $5 per 30-step task

A tool-using agent run costs between one cent and about fifty cents per task on today's mainstream API models, and a long 30-step run costs between five cents and five dollars. Using a 4,000-token system prompt plus tool definitions, 1,500-token tool results and 300 output tokens per step, a 12-step run costs $0.0089 on DeepSeek V4 Flash ($0.05/$0.16 per 1M), $0.14 on Gemini 3.8 Flash ($0.75/$3.75), $0.37 on Claude Sonnet 5 ($2/$10) and $0.47 on GPT-5.4 ($2.50/$15). All prices are USD per 1M tokens from our catalogue, updated 2026-09-11.

Those numbers assume no prompt caching. With caching the same runs land at roughly $0.12 (Sonnet 5), $0.15 (GPT-5.4) and $0.06 (Gemini 3.8 Flash). The rest of this guide shows where every token comes from so you can rebuild the estimate for your own agent; the cheapest LLM for AI agents guide ranks 30 models on the same trace.

What an agent run actually sends to the API

An agent is a loop. Each iteration sends the system prompt, the tool schemas, the user task, every previous assistant turn and every previous tool result, then reads back a short assistant turn that usually contains a tool call. The model never remembers the last step; you re-send it.

The reference trace used throughout this guide:

  • System prompt plus tool definitions: 4,000 tokens, sent on every step
  • Tool result appended after each step: 1,500 tokens
  • Assistant output per step (reasoning plus the tool call): 300 tokens
  • Context at step k = 4,000 + (k - 1) × 1,800 tokens

So step 1 sends 4,000 tokens, step 12 sends 23,800 and step 30 sends 56,200. Summed over a run:

  • 5 steps: 38,000 input tokens, 1,500 output tokens
  • 12 steps: 166,800 input tokens, 3,600 output tokens
  • 30 steps: 903,000 input tokens, 9,000 output tokens

A 30-step run only ever produces 49,000 tokens of unique material (4,000 system plus 30 × 1,500 results) yet bills 903,000 input tokens. That 18× multiplier is the whole story of agent cost.

Worked traces: 5, 12 and 30 steps on four models

Cost = input tokens × input rate + output tokens × output rate. For Claude Sonnet 5 at 12 steps: 166,800 × $2/1M = $0.3336, plus 3,600 × $10/1M = $0.036, total $0.3696. The same arithmetic on each model:

Model$/1M in / out5-step run12-step run30-step run
DeepSeek V4 Flash$0.05 / $0.16$0.0021$0.0089$0.047
Gemini 3.8 Flash$0.75 / $3.75$0.034$0.139$0.711
Claude Sonnet 5$2 / $10$0.091$0.370$1.896
GPT-5.4$2.50 / $15$0.118$0.471$2.393

Two things stand out. Going from 12 to 30 steps multiplies cost by about 5×, not 2.5×, because context growth is quadratic in step count. And output tokens are almost irrelevant: on Sonnet 5 the 30-step run spends $1.806 on input and $0.09 on output. "Keep responses short" barely moves an agent bill; keeping the context short does. Per step on Sonnet 5, step 1 costs $0.011 and step 12 costs $0.051, five times as much for the same amount of new work.

Why context re-send dominates, and what caching does about it

In the 12-step trace, 166,800 of the 170,400 billed tokens (98%) are input, and most of those are identical to what was sent one step earlier. Prompt caching exists for exactly this shape: the provider stores the processed prefix and charges a reduced rate when you send it again.

Cache reads cost roughly 10% of the list input rate on Anthropic and OpenAI, and roughly 25% on Gemini. Anthropic also charges roughly 125% of list for the initial cache write. These are approximate multipliers, not catalogue rows, so treat the figures below as estimates:

Model12-step, no cache12-step, cached (approx.)30-step, cached (approx.)
Claude Sonnet 5$0.370$0.12$0.40
GPT-5.4$0.471$0.15$0.49
Gemini 3.8 Flash$0.139$0.06$0.23

With caching, the 30-step Sonnet 5 run drops from $1.90 to about $0.40, a 79% cut, because only the newest 1,800 tokens per step bill at full rate. Caching works on a prefix, so anything that changes early in the prompt (a timestamp, a re-ordered tool list) silently disables it; check the cached token count in the usage object on every call. Our prompt caching cost comparison covers the per-provider rules.

Cost per successful task, not per token

Per-token prices tell you what a run costs, not what a finished task costs, and the finished task is what a buyer should optimise. Cost per successful task = cost per run ÷ success rate, plus whatever a failed run costs in retries or human review.

A worked example with assumed success rates (measure your own; these are illustrative):

  • DeepSeek V4 Flash: $0.0089 per run at 50% success = $0.018 per success
  • Gemini 3.8 Flash: $0.139 per run at 75% = $0.185 per success
  • Claude Sonnet 5: $0.370 per run at 92% = $0.40 per success

The cheap model still wins on API spend alone. It stops winning the moment a failure costs anything: five minutes of a person's time per failed run outweighs the $0.35 saved. It also stops winning when the weaker model takes more steps. A Gemini 3.8 Flash run that wanders for 30 steps ($0.71) costs nearly twice a Sonnet 5 run that finishes in 12 ($0.37). Track steps-to-completion per model; it predicts cost better than the per-token rate. The practical pattern is to route to the cheap model first, validate, and escalate failures; the cheapest LLM for AI agents guide has the routing code.

Cheapest model that still does this reliably, and when to pay for the flagship

For a well-specified agent with strict tool schemas and a validator on every tool call, Gemini 3.8 Flash ($0.75/$3.75) and GPT-5.4 mini ($0.75/$4.50) are the cheapest models we would run unattended: both cost about $0.14 for the 12-step trace, follow JSON schemas consistently, and rarely need more steps than a flagship for routine work. DeepSeek V4 Flash at $0.0089 per run is a genuine option for high-volume, low-stakes loops (classification, enrichment, scraping) where a retry is free.

Pay for Claude Sonnet 5 or GPT-5.4 when the task is open-ended, when a wrong tool call has side effects (sending email, editing code, moving money), or when the cheap model's step count blows out. Pay for Claude Opus 5 ($5/$25, $0.92 per 12-step run) or GPT-5.5 ($5/$30, $0.94) only for the planner role in a multi-agent setup or where a single failure costs more than a dollar. Most teams get the best per-task cost from a flagship planner delegating to cheap workers. The Claude, OpenAI and Gemini agent cost guides break down each family.

How to cap spend on an agent loop

Agents fail expensively when they loop. Four controls, in order of how often they save money:

  • Max steps: hard-stop the loop at N tool calls. For most task types 15 is generous; if a run needs 30 it is usually stuck.
  • max_tokens per call: the largest plausible tool call plus a short explanation, typically 1,000 to 4,000 for agent turns. It stops runaway monologues, not context growth.
  • Stop conditions: end on a final_answer tool call, a repeated identical tool call (a loop signature), or an empty tool result twice in a row.
  • A per-run USD budget computed from usage: after each call, add input_tokens × rate_in + output_tokens × rate_out (cache reads at the reduced rate) to a running total and abort past your ceiling.

A $0.50 per-run budget on Sonnet 5 permits about 14 uncached steps of the reference trace, or roughly 35 cached steps. For work that is not latency-sensitive, batch endpoints cut list prices by roughly 50% on Anthropic and Google; useful for overnight backfills, useless for a loop that needs each step's result before the next. See LLM batch API pricing.

A repeatable estimate for your own agent

Plug your own figures into the formula. With S = system plus tools tokens, R = average tool result tokens, O = average output tokens per step and N = steps:

  • Total input tokens = N × S + (R + O) × N × (N - 1) ÷ 2
  • Total output tokens = N × O
  • Run cost = input tokens × rate_in ÷ 1,000,000 + output tokens × rate_out ÷ 1,000,000

Then divide by your measured success rate and add the cost of the escalation path. Three reductions worth trying before you change model: summarise or drop tool results once they are a few steps stale (this attacks the quadratic term directly), trim tool schemas so S is nearer 2,000 than 6,000, and enable caching so re-sent context bills at the reduced rate. The AI cost calculator takes monthly token volumes; multiply run cost by runs per month for a budget line, and see the API vs subscription guide if a subscription tool is on the table.

Key Takeaways

  • A 12-step tool-using run costs $0.0089 on DeepSeek V4 Flash, $0.14 on Gemini 3.8 Flash, $0.37 on Claude Sonnet 5 and $0.47 on GPT-5.4 without caching
  • 98% of agent spend is input tokens; a 30-step run bills 903,000 input tokens for only 49,000 tokens of unique content
  • Prompt caching cuts a 30-step Sonnet 5 run from $1.90 to roughly $0.40 because cache reads are about 10% of list input
  • Cost per successful task = run cost ÷ success rate; a weaker model that needs 30 steps costs more than a stronger one that finishes in 12
  • Cap spend with a max step count, a per-call max_tokens and a per-run USD budget computed from the usage object

Editorial context

Who is this for?

Developers and technical buyers sizing the API bill for a tool-using agent before shipping it, and finance teams who need a per-task unit cost.

When NOT to use this

Consumers comparing chatbot subscriptions; people running single-shot prompts with no tool loop, where per-call pricing is enough.

Pricing insights

Input tokens are 98% of agent spend because context is re-sent every step; a 12-step run bills 166,800 input tokens for 22,000 tokens of unique content, and caching cuts the bill by 65 to 80%.

Alternatives to consider

Gemini 3.8 Flash or GPT-5.4 mini at roughly $0.14 per 12-step run for routine work; DeepSeek V4 Flash at $0.009 for high-volume low-stakes loops; Claude Sonnet 5 or GPT-5.4 when a wrong tool call has consequences.

Final verdict

Budget per successful task, not per token. Route to a cheap model with strict schemas, cap steps and dollars per run, enable caching, and escalate failures to a flagship rather than running the flagship everywhere.

Frequently Asked Questions

How much does an AI agent cost per task?

Between about one cent and fifty cents for a typical 12-step tool-using run, depending on model. On our reference trace the run costs $0.0089 on DeepSeek V4 Flash, $0.14 on Gemini 3.8 Flash, $0.37 on Claude Sonnet 5 and $0.47 on GPT-5.4. Divide by your success rate to get cost per finished task.

Why do AI agents cost so much more than a single chat call?

Because every step re-sends the whole conversation, including every earlier tool result. A 12-step run sends 166,800 input tokens although only about 22,000 tokens of unique content exist. Cost grows roughly with the square of the step count, so a 30-step run costs about five times a 12-step run.

Does prompt caching make agents cheaper?

Yes, substantially. Cache reads cost roughly 10% of the list input rate on Anthropic and OpenAI and roughly 25% on Gemini, which takes the reference 30-step Claude Sonnet 5 run from $1.90 to about $0.40. Caching only works on an unchanged prefix, so keep the system prompt and tool list stable.

Is the cheapest model always the cheapest way to run an agent?

No. A cheap model that fails half the time or takes 30 steps to do what a stronger model does in 12 can cost more per successful task once retries, extra steps and human review are counted. Gemini 3.8 Flash at 30 steps ($0.71) already costs nearly twice Claude Sonnet 5 at 12 steps ($0.37).

How do I stop an agent from running up a huge bill?

Set a hard maximum step count (15 is generous for most tasks), a per-call max_tokens of 1,000 to 4,000, and a per-run dollar budget computed from the usage object after every call. Abort on repeated identical tool calls, which almost always mean the agent is stuck.

Which model should I use for an agent on a budget?

Gemini 3.8 Flash and GPT-5.4 mini are the cheapest models we would run unattended with strict tool schemas, at about $0.14 per 12-step run. DeepSeek V4 Flash at under a cent per run suits high-volume, low-stakes loops where a retry costs nothing. Use Claude Sonnet 5 or GPT-5.4 when tool calls have side effects.

Related

Free courses · no sign-up

Still deciding? Learn the basics first, then come back to the prices.

If our calculators helped you cut down on hidden AI wallet leaks, thanks for using them. A tiny fraction of your savings is what keeps our pricing indexes updated daily.

Not sure which AI is cheapest for your use case? Find out in 30 seconds — no signup required.

AI cost intelligence

Stop overpaying for AI tools

Join the OverpayingForAI list for pricing updates, cheaper alternatives, and practical buying guidance.

Now tracking 50+ AI tools, models, platforms, subscriptions, coding tools, and automation products.

We use your email only for OverpayingForAI updates. Unsubscribe anytime.