Skip to content

2026-10-24

How a polite loop becomes a four-figure API bill

Runaway detection for agents: baselines, hard limits, and why a successful ping can still be an incident.

The second way agents fail is louder on the invoice than in the logs. A retry loop, a planner that re-enters the same tool, or a webhook that fires on its own output can do exactly what you asked, thousands of times. Every call succeeds. The monitor that only understands silence stays green.

Count the work, not just the heartbeat

A useful ping for an agent is not an empty GET. Send the tokens and the dollar cost of that run:

curl -fsS -X POST "$NIGHTSHIFT_PING_URL" \
  -H "content-type: application/json" \
  -d '{"tokens":18420,"cost_usd":0.041}'

Nightshift keeps those numbers. On Pro and Team plans it watches three windows: runs in the last hour, tokens in the last hour, and dollars in the last 24 hours.

Two kinds of threshold

  • A hard limit is a number you already know is wrong. Forty runs an hour. Ten dollars a day. The alert fires the moment the window passes it.
  • A baseline alert compares the current window with the previous complete hours (or previous days, for cost). It needs a few samples, ignores a median of zero, and only fires when the spike is several times normal and above a floor. A daily job that runs once will not look like a runaway.

The same signal will not page you again until the window has cooled off: an hour for runs and tokens, a day for cost. That keeps a stuck loop from sending sixty emails.

Put the limit where the money is

If you only have time to set one number, set max dollars per day on the agent that calls a paid model. Silence detection still covers the case where it stops. The dollar cap covers the case where it will not.