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.
1. Connect the agent
Section titled “1. Connect the agent”Give it Limitry’s tools, through the MCP server or the CLI, and the skill that explains how Limitry works (Use with AI agents).
2. Paste this prompt
Section titled “2. Paste this prompt”Add Limitry to this codebase. Find the calls that cost us money or that auser could abuse (LLM calls, paid APIs, emails, exports). Propose limitsin a table: subject, action, amount, window, fail mode. Wait for my answerbefore creating any. Then create the ones I agree to, wrap the code withthe Limitry SDK's guard or hold helpers, handle a refusal where we answerthe user, and add a test for it.3. What it writes
Section titled “3. What it writes”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),);from limitry import Limitry
limitry = Limitry() # reads LIMITRY_API_KEY
with limitry.guard(subject={"kind": "user", "id": user.id}, action="ai-call"): reply = call_model(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; },);with limitry.hold( subject={"kind": "user", "id": user.id}, action="ai-call", estimate=5) as held: res = call_model(prompt) held.cost(price_cents(res.usage)) # your prices, in centsA refusal throws LimitExceeded, with limit, reason and
retryAfterSeconds, for your code to turn into a 429 or a message.
4. Go live
Section titled “4. Go live”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:
- 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).
- 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.
If Limitry is unreachable
Section titled “If Limitry is unreachable”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.