Skip to content

Add Limitry with your agent

Your coding agent can add Limitry for you. It reads your code, proposes limits, asks you before creating any, and wraps the costly calls. It works in test unless you name live, so nothing it does affects your real customers until you copy its limits to live.

Give it Limitry’s tools, through the MCP server or the CLI, and the skill that explains how Limitry works (Use with AI agents).

Add Limitry to this codebase. Find the calls that cost us money or that a
user could abuse (LLM calls, paid APIs, emails, exports). Propose limits
in a table: subject, action, amount, window, fail mode. Wait for my answer
before creating any. Then create the ones I agree to, wrap the code with
the Limitry SDK's guard or hold helpers, handle a refusal where we answer
the user, and add a test for it.

Say your product has an AI feature. The agent might propose 100 AI replies a day for each of your users and a budget of 200 cents a month for each, both on the action ai-call.

For a call whose cost you know up front, such as one call against the daily count, guard checks first and runs the work only if it’s allowed:

import { createClient, LimitExceeded } from "@limitry/sdk";
const limitry = createClient(); // reads LIMITRY_API_KEY
const reply = await limitry.guard(
{ subject: { kind: "user", id: user.id }, action: "ai-call" },
() => callModel(prompt),
);

When you only know the cost afterwards, as with an AI reply your product pays for by the token, use hold; it also covers “at most N at once”. It reserves an estimate, runs the work, and commits what it actually used. If the work fails, it releases the hold:

const answer = await limitry.hold(
{ subject: { kind: "user", id: user.id }, action: "ai-call", estimate: 5 },
async (held) => {
const res = await callModel(prompt);
held.cost(priceCents(res.usage)); // your prices, in cents
return res;
},
);

A refusal throws LimitExceeded, with limit, reason and retryAfterSeconds, for your code to turn into a 429 or a message.

The agent’s limits are in test, and your code reads its key from LIMITRY_API_KEY. Use a test key (lim_test_…) while you try it. To go live:

  1. Copy the limits to live. Click Copy to live on the Limits page, or let the agent ask for it: you approve the request in the app (see Approvals).
  2. Give your production code a live key (lim_live_…). An owner creates it in the app with Live picked at the top right, or approves the agent’s request for one. The secret never reaches the agent.

Each limit has a fail mode. The SDK remembers the fail mode from the last answer, and if Limitry doesn’t answer within 1.5 seconds (timeoutMs), it either lets the work run (open, the default) or throws LimitExceeded with the reason unavailable (closed). Your product never hangs waiting for Limitry.