Skip to main content

Your agent ran overnight and ran up a large API bill. What probably happened, and what do you change?

Agents and tools · Pro 1

Short answer

Most likely it got stuck in a loop: retrying a failing tool, re-planning, or calling itself with ever-growing context. I would read the trace to find the loop, then add hard limits: maximum steps and spend per run, a daily budget with alerts, detection of repeated identical calls, and a kill switch. Then add a test that reproduces it.

Deeper answer

Agents fail expensively because each step adds tokens, and a loop multiplies them. Common causes are a tool that keeps returning an error the agent tries to fix by calling it again, a goal it cannot reach so it never decides it is done, or memory that keeps the whole history so each call is larger than the last.

The fix is layered. Per-run caps on steps, tokens and money stop one task; a budget at the account or gateway level stops many; alerts tell a person early. Logging every step with its cost lets you find the cause, and a regression test keeps it from coming back.

What a strong answer covers

Answer it out loud in the mock interview about 1.5 min

Follow-ups to expect

Common mistakes

Learn it

Loop limits, budgets and kill switches

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.