Skip to content

Give AI agents a budget

Say your product runs AI agents on your customers’ behalf, and each agent calls models and paid tools in a loop. A loop that goes wrong can spend a lot before anyone notices. Give every agent a budget in money, and have the agent check it before every step.

Count in cents. $5 a day for every agent:

Terminal window
curl -X POST https://api.limitry.com/v1/limits \
-H "Authorization: Bearer $LIMITRY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name":"Agent daily budget","subjectKind":"agent","action":"*",
"amount":500,"unit":"cents","window":"day","failMode":"closed"}'

action is *, so model calls and tool calls all draw from the same budget. The fail mode is closed: if Limitry can’t be reached, the agent stops rather than spending without a count.

For a budget that never resets, such as $20 for one long task, use the window total instead of day. See Pools, balances and budgets.

Hold an estimate before each model or tool call, and settle what it actually cost:

import { createClient, createLimits, LimitExceeded } from "@limitry/sdk";
const limits = createLimits(
createClient({ token: process.env.LIMITRY_API_KEY! }),
);
async function step(agentId: string, action: string, run: () => Promise<Step>) {
return limits.hold(
{ subject: { kind: "agent", id: agentId }, action, estimate: 10 },
async (held) => {
const result = await run();
held.cost(result.costCents);
return result;
},
);
}
export async function runAgent(agentId: string, task: Task) {
try {
while (!task.done) {
await step(agentId, "llm", () => nextModelCall(task));
}
} catch (err) {
if (err instanceof LimitExceeded) {
return pause(task, "This agent reached its budget for today.");
}
throw err;
}
}

When the budget is used up, Limitry refuses the next step before it runs, so the agent stops between steps rather than in the middle of one.

With a total budget, the agent can ask for more credits through Limitry’s MCP server, and a workspace owner or admin approves or declines the request in the app. See Approvals.

The first time an agent hits its budget in a window, your webhook endpoints receive limit.exceeded, with the agent’s id, so you can tell the person who started it.

Related: Reservations, Limit AI spend per user.