Agent-run paid batch script kept spending after external account lockout, no circuit breaker

Status Open
Maintainer reply None cached
Activity 0 comments · opened Sep 4, 2026

Summary

An agent-run batch script (written by Claude Code, Sonnet 5) spent real money against a third-party API (fal.ai) after that account had already run out of balance, because the script had no mechanism to detect a failed job and stop. The account's fal.ai credit balance went negative (-$3.68 at time of review, confirmed via the account's own billing dashboard).

What was authorized

I approved a real-money batch operation: regenerate multi-image "shorts" for ~31-34 catalog items in my own app, with a stated estimate of roughly $11-33 based on the app's own internal per-image cost assumption.

What happened

  1. The agent built a sequential batch script that called my app's own background-job API for 34 items, one at a time, polling each job to completion before starting the next.
  2. The script's only failure guard was around the initial HTTP request throwing an exception. It had no check on the job's own reported outcome after polling — a job that completed with status="error" was treated the same as status="done" for the purpose of continuing the loop.
  3. Partway through the batch (~item 23 of 34), the fal.ai account hit its own balance floor. Confirmed by the agent via a direct API probe: HTTP 403 {"detail":"User is locked. Reason: TOP_UP."}
  4. The script had nothing to detect this and continued for all 11 remaining items, each attempting LLM storyboard calls and scene image generation calls against the now-locked account, all of which failed.
  5. The batch finished on its own after exhausting the fixed list of 34 items (it was not stopped by the agent mid-run — the agent was not actively monitoring in real time and only reviewed results after the batch completed).

Financial impact

Verified against the app's own generation-cost ledger:

| | Items | Logged spend |
|---|---|---|
| Successful (real content built) | 23 | $6.39 |
| Failed (locked account, wasted) | 11 | $11.67 |
| Total | 34 | $18.06 |

My own fal.ai billing dashboard confirms: Current Credit Balance: -$3.68, with a usage spike in the billing period's chart matching the timing of this batch.

Root cause

The batch script lacked a governor: no check of each job's actual outcome before proceeding to the next item, and no running-spend or consecutive-failure ceiling that would halt the batch automatically. My own app's internal budget guard (a daily-cap/rolling-ceiling check) does not protect against this shape of failure, because each individual call was permitted by the app's own budget logic — the actual failure was external (the fal.ai account itself refusing all further calls), which the script never checked for.

Contributing factor, stated plainly

I had explicitly approved the spend amount range in advance. The agent's error was not spending money without authorization — it was continuing to spend money on calls that were already failing, well past the point where continuing had any chance of succeeding.

Requested resolution

I'm asking Anthropic to review this for possible reimbursement of the wasted portion ($11.67, or a broader amount at Anthropic's discretion), since the loss was caused by the agent continuing an automated action past the point of any possible success, not a decision I made or could intervene on mid-batch.

Ask for Claude Code itself

Agent-run scripts that spend real money in a loop against third-party paid APIs have no structural safeguard today. A recommendation from having lived through this: consider whether Claude Code should encourage/require (via a skill, a lint, a system reminder) any agent-authored batch-spend script to check each iteration's actual outcome and halt on repeated failures, rather than relying on the agent to remember to add this every time.

View original on GitHub ↗