OverpayingForAIPricing desk

Lesson 5 of 5 · 7 min read · Beginner

The five caps that stop a runaway loop

An agent fails expensively in one way: it loops. Five caps, in the order they save money, and a compare exercise on two agent designs so you can tell a safe loop from a bill waiting to happen.

In this lesson you will

  • Name the five caps and what each one stops
  • Read an agent's settings and spot which cap is missing
  • Set a per-run dollar budget from the reference trace

A single chat turn has a natural end: the model stops writing. A loop does not. If the stop condition never fires (a tool keeps returning an error, the agent keeps re-trying the same call, the task was never achievable), it goes round until something external stops it, and every lap costs more than the last. These five caps are the something external.

Five caps, in the order they save money

  1. 1

    1. Max steps

    Hard-stop the loop at N tool calls. Fifteen is generous for most tasks; a run that needs thirty is usually stuck. This is the cap that catches the most incidents.

  2. 2

    2. max_tokens per call

    The largest plausible tool call plus a short explanation, typically 1,000 to 4,000 tokens for an agent turn. It stops a runaway monologue. It does not stop context growth, which is why it is second, not first.

  3. 3

    3. Stop conditions

    End the run on a final-answer call, on the same tool call repeated with identical arguments (the signature of a loop), or on an empty tool result twice in a row.

  4. 4

    4. A per-run dollar budget

    After every call, add input tokens × input rate plus output tokens × output rate to a running total, and abort past your ceiling. On Sonnet 5, a $0.50 budget allows about 14 uncached steps of the reference trace, or roughly 35 cached.

  5. 5

    5. A confirmation gate on side effects

    Any tool that sends, pays, deletes or edits waits for a human yes. This does not save tokens; it saves the thing the tokens were spent on.

What each cap stops, and what it does not. No single cap is enough.
CapStopsDoes not stop
Max stepsEndless loopsFifteen expensive steps on a flagship
max_tokensRunaway outputInput growth, which is 98% of the bill
Stop conditionsThe stuck-repeating case earlyA loop that varies its calls slightly each time
Dollar budgetSpend past a number you choseNothing else; it is the backstop
Confirmation gateA wrong action with consequencesAny token spend at all

Which would you trust?

Two agent designs for the same job: classifying 500 incoming support emails a day and drafting a reply for each. Which should you trust with your card on file?

Lesson FAQ

How do I stop an AI 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, stop conditions for repeated identical tool calls, and a per-run dollar budget computed from token usage after every call. Add a confirmation gate on any action with side effects.

What is the most important cap for an agent?

Max steps. It is the one that catches the most incidents, because the common failure is a loop that never reaches its stop condition. The per-run dollar budget is the backstop when everything else is misconfigured.

Does max_tokens stop an agent from getting expensive?

Only partly. It caps output, but 98% of agent spend is re-sent input, which grows every step regardless of max_tokens. Cap steps and dollars to control the input side.

Can I set these caps in ChatGPT or Claude apps?

Some, depending on the product and the month: look for step or time limits, an ask-before-acting toggle, and a spend limit in billing. Where a product exposes none of them, the vendor's usage cap is your only ceiling, which is fine for a $20 seat and not fine for an API key.

Finished reading?

Mark it done to track your progress through the course.

Save progress across devices

Get a private link that restores your lessons on any device. Email is optional and only used to send you the link.

Compare, calculate, decide

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.