How to stop a runaway AI agent on your API
The situation
One of your customers points an AI agent at your API. Something goes wrong: it doesn't decide it's done, or it retries every error, or a loop runs all night. By morning it is far past the plan they're on.
The agent didn't read your pricing page, and it won't stop on its own. Your options after the fact are all bad: pay for the extra work, send a surprise bill, or turn off the customer's key and break their other integrations too.
The fix is to cap usage per agent, and to check that cap before each call does any work.
How to cap usage per agent
- Give each agent its own agent key. Not one key per customer: one key per integration or agent. Then a cap can stop one agent without touching the rest.
- Put each key on a plan. The plan sets how many calls are allowed each month, day or minute, for one tool or for every tool.
- Ask before each call. At the top of your handler (an HTTP route or an MCP tool handler), call
decide()with the caller's agent key and the tool name. Ordainer answers allow or deny and counts the call in the same step. - On a deny in enforce mode, don't run the work. Send the caller the reason and the reset time. The message is written so an agent, or the person behind it, can read it and stop retrying.
- Start in shadow mode. Plans you create start in shadow: they log what they would have denied and let those calls run, so you can see which agents would go over before you enforce. (The two sandbox plans you get at sign-up start in enforce, so you can see a deny right away.)
The agent that's over gets a clear no. The same customer's other agents keep working, and each decision leaves an audit row you can show them.
"Runaway spend": calls, not dollars
People often ask this as "how do I stop runaway agent spend?" Ordainer Cap counts calls, not dollars. If each call costs you compute or a paid service behind it, capping the calls caps the cost: in enforce mode, when the calls stop, the cost stops.
It is also not a rate limiter. A rate limit smooths traffic spikes to protect your servers. A usage cap enforces the plan for each agent key over a period. Keep both.
For working code, see how to cap each API customer's usage, which has the Python and Node samples from our quickstarts.
Common questions
Does this work with MCP?
Yes. In each MCP tool handler, call decide() with the calling client or agent's key before the tool runs. Today that's a plain HTTPS request from any language.
Can one cap cover all of a customer's agents together?
Not today. Each agent key gets its own count, even when several keys share a plan.
Does our traffic go through you?
No. The check sends the agent key, the tool name and, if you set them, an idempotency key, a mode or a session lease. Your request payloads stay on your servers.
Try it
Ordainer is free during the beta: sign up for test keys with 1,000 decisions a month, no credit card needed.
Get test keys · Produce a deny in the live demo
Has an agent run away on your API? We'd like to hear what happened and what you did about it: support@ordainer.ai.