Home / Blog / AI agent cost control

AI agent cost control: how to stop your bill from exploding

Published 2026-05-27 · Updated 2026-10-18 · 12 min read · By Real Problem AI

Short answer: AI agent costs explode through tool-call loops, growing context, oversized default models and blind retries. Stop them with a per-request token budget, a per-user daily cap, a loop detector and a model router. On the Claude API in October 2026, input prices span 100x across models, and batch jobs cost 50% less.

The first big model invoice is often when an agent team finds out its cost model was a guess. A product priced as a monthly subscription can cost more per active user to run than it earns, and a single agent stuck in a loop can multiply that before anyone notices.

This essay is a playbook for keeping agent inference inside its lane. Four failure modes, four guardrails, the built-in levers to switch on first, and three dashboards.

How agents actually overspend

1. Tool-call loops

The most common failure mode. The agent calls a tool, gets a result it cannot quite use, calls the tool again with a small variation, and so on. Each pass adds the previous results to the context of the next request, so every step costs more than the one before.

2. Silent context bloat

Agents accumulate context across turns. A well-designed agent prunes; most do not. After many turns the system prompt, tool definitions, earlier tool results and history can fill most of the context window, and every later request pays for all of it.

3. Wrong-model defaults

Teams ship with the strongest model as the default ("we'll optimise later") and never optimise. Sending every task to the largest model when many would succeed on a smaller one is overspend baked into the architecture. The gap is large: on Anthropic's price list in October 2026, input tokens cost from $0.10 per million (Claude Haiku 5.5, prompts up to 100,000 tokens) to $10 per million (Claude Fable 5.1), a 100x spread, and output prices show the same spread (Claude API pricing, checked 18 October 2026).

4. Misclassified retries

Network blips, tool failures and tokenization issues all look like "transient errors" to retry logic. Without idempotency tracking, a single user request can spawn several full model calls before anyone notices. One live problem in our directory describes exactly this: a retry-stuck headless agent that burned $313 in one night.

How much does an AI agent cost to run?

The arithmetic is simple; the trap is that agents re-send their growing context on every step, so input tokens dominate. An illustration, not measured data:

Run shapeInput tokens per runAt $2 per millionAt $10 per million
30 steps, 40,000 tokens of context each1.2 million$2.40$12.00
Same run, 1,000 times a day1.2 billion$2,400$12,000

Prices match Claude Sonnet 5.5 ($2) and Claude Fable 5.1 ($10) base input rates on 18 October 2026; output tokens are extra. Check the current price list before you plan.

Double the steps through a loop and the bill more than doubles, because each extra step carries a longer context than the last.

The built-in levers to switch on first

Before you build anything, use what your provider already gives you. On the Claude API, as of October 2026:

What spend limits do not do: they are monthly and shared across an organisation or workspace. They cap your worst month, not your worst run. A single loop can still burn a large share of the month before the limit trips, and then every user is blocked, not just the one who caused it. That is why the guardrails below live in your own code.

The four guardrails

Guardrail 1: per-request budget

Every request enters with a hard token budget. Track input + output + retried tokens. When the request crosses 80% of budget, downgrade the model. When it crosses 100%, terminate and return a degraded but real answer. The budget must sit in code or at your gateway; a line in the prompt asking the model to be frugal is a suggestion, not a limit.

Set the budgets from your own data: measure the 95th percentile of real requests for each task type and set the budget a little above it.

Guardrail 2: per-user, per-day cap

Set a hard daily cost cap per user, from your own usage data, high enough that ordinary users never reach it. The few who do are either power users (charge them) or runaway loops (block them). Either way, the cap puts a ceiling on your worst day, and it blocks one user instead of everyone.

Guardrail 3: loop detector

Maintain a fingerprint of recent tool calls (tool name + arg hash). If the same fingerprint appears 4 times in 10 calls, you are in a loop. Break the conversation and ask the user to clarify, rather than burning tokens hoping the model figures it out.

Guardrail 4: model router

Route by task class, not by default. A small, cheap classifier picks the cheapest viable model for each agent step. With a 100x price spread between the smallest and largest models, the router costs almost nothing next to what it saves.

Three dashboards worth checking weekly

Cost per active user, by cohort. If this number trends up while you ship features, you are accumulating debt. If it trends up without new features, you have a leak.

Top 10 most expensive requests, by user. Look at the actual transcripts. Often one of them is a loop. Patch the underlying logic, not the user.

Token-to-action ratio. How many tokens did you spend per useful customer action (message sent, ticket resolved, lead qualified)? This number alone tells you whether your unit economics work. Add your cache hit rate next to it; the Claude Console shows it on the Usage page.

The tooling gap

Most tools teams use today focus on tracing: they show you what happened. Provider spend limits stop the month, not the run. What is missing is a true cost firewall: drop-in middleware with per-run and per-user budgets, an auto-downgrade router, and forensic playback of which loop burned the tokens. It is one of the highest-scoring problems in our live directory: an agent that repeated one broken action all night (score 9.0). A close neighbour is not being able to tell whether an agent did what it said (8.6). Our original May entry is in the archive.

Until that exists as a single product, the playbook above is something you build yourself. In our estimate it is a few days of work. If you have already built it, list your tool under the problem it solves.

Questions builders ask

How much does an AI agent cost to run?

Multiply the tokens each run reads and writes by your model's per-token price, then by runs per day. Agents re-send their growing context on every step, so input tokens dominate: 30 steps that each re-send 40,000 tokens read 1.2 million input tokens, which is $2.40 at $2 per million or $12 at $10 per million.

Does the Anthropic spend limit stop a runaway agent?

Partly. The Claude Console lets you set organisation and workspace spend limits below your tier's monthly cap, and requests stop when a limit is reached. Those limits are monthly and shared, so a single looping run can still burn a large share before they trigger. A per-run budget in your own code is what stops one loop.

What is the fastest way to reduce Claude API costs?

Route simple steps to a smaller model, cache the long repeated prefix (system prompt and tool definitions), and send non-urgent work through the Batch API, which Anthropic prices at 50% off input and output tokens. Then add a loop detector so the savings are not undone by one stuck run.

The full agent-cost-firewall opportunity plus the rest of the catalogue.

Browse the directory