Quickstart
By the end of this page, each of your users will have a $2 AI budget a month. Your code will check it before each AI reply, then charge what the reply actually cost.
1. Create a workspace
Section titled “1. Create a workspace”Sign up, verify your email and create a workspace. Limits, keys and usage all belong to a workspace.
2. Get a test key
Section titled “2. Get a test key”Every workspace has a test side and a live side, and you start in test. Test keys have their own limits and counts, and we don’t bill their checks. Test and live explains the difference.
Create a key with Manage limits under Settings → Developers. Choose Test for its side. Manage limits can create limits and make checks, so every step in this guide works with it.
The key starts with lim_test_. Copy the secret now, because we show it
only once. Keep it in your secret manager or environment rather than in
your code.
export LIMITRY_API_KEY="lim_test_…" # the SDKs read thisexport LIMITRY_TOKEN="$LIMITRY_API_KEY" # the CLI reads thisWorkspace owners and admins can create keys, and members can create test keys. If you add your first limit in the app instead, the dashboard offers Create a test key as your next step, with the access this guide needs already set.
Then install the client you’ll use. curl needs nothing:
npm install @limitry/sdkpip install limitrynpm install -g @limitry/cli3. Create a limit
Section titled “3. Create a limit”Count in cents, so $2 is 200. In the app, open Limits while you’re
in test, and add a limit of 200 cents a month for subjects of kind
user and the action ai-call. You can also create it from your code
or a terminal:
import { createClient } from "@limitry/sdk";
const limitry = createClient(); // uses the LIMITRY_API_KEY environment variable
const limit = await limitry.limits.create({ name: "AI budget", subject: { kind: "user" }, action: "ai-call", amount: 200, unit: "cents", window: "month",});console.log(limit.id);from limitry import Limitry
limitry = Limitry() # uses the LIMITRY_API_KEY environment variable
limit = limitry.limits.create( name="AI budget", subject={"kind": "user"}, action="ai-call", amount=200, unit="cents", window="month",)print(limit.id)limitry limits create --name "AI budget" --subject '{"kind":"user"}' \ --action ai-call --amount 200 --unit cents --window monthcurl -X POST https://api.limitry.com/v1/limits \ -H "Authorization: Bearer $LIMITRY_API_KEY" \ -H "Content-Type: application/json" \ -d '{"name":"AI budget","subject":{"kind":"user"},"action":"ai-call", "amount":200,"unit":"cents","window":"month"}'The limit applies in test to every subject of kind user, starting
with the next check. To try it with the CLI, run this. It spends 5 of
the user’s cents:
limitry check user:user_123 ai-call --cost 5# Allowed. AI budget: 195 cents left, resets 2026-11-01T00:00:00.000Z4. Check before the work
Section titled “4. Check before the work”Ask whether user user_123 may make an AI request that costs 5 cents:
import { createClient } from "@limitry/sdk";
const limitry = createClient(); // uses the LIMITRY_API_KEY environment variable
const decision = await limitry.checks.create({ subject: { kind: "user", id: "user_123" }, action: "ai-call", cost: 5,});console.log(decision);from limitry import Limitry
limitry = Limitry() # uses the LIMITRY_API_KEY environment variable
decision = limitry.checks.create( subject={"kind": "user", "id": "user_123"}, action="ai-call", cost=5,)print(decision)limitry check user:user_123 ai-call --cost 5curl -X POST https://api.limitry.com/v1/checks \ -H "Authorization: Bearer $LIMITRY_API_KEY" \ -H "Content-Type: application/json" \ -d '{"subject":{"kind":"user","id":"user_123"},"action":"ai-call","cost":5}'The response, after the CLI’s check in step 3:
{ "allowed": true, "reason": null, "reservation": null, "limits": [ { "limitId": "lmt_…", "limitName": "AI budget", "unit": "cents", "window": "month", "rolling": false, "failMode": "open", "amount": 200, "remaining": 190, "resetsAt": "2026-11-01T00:00:00.000Z" } ], "retryAfterSeconds": null}When a check costs more than the user has left, it returns
"allowed": false and spends nothing. Its retryAfterSeconds tells
you when the budget resets. A “no” is a normal result, not an error.
5. Use it from your code
Section titled “5. Use it from your code”You don’t know what a reply costs until it’s done. So in your code,
the SDK’s reserve holds what the reply will probably cost, runs your
request, then charges what it actually cost. Whatever the reply didn’t
use goes straight back to the user. The
TypeScript and Python SDK pages
have the details.
import { createClient } from "@limitry/sdk";
const limitry = createClient(); // uses the LIMITRY_API_KEY environment variable
// Your prices, in cents per million tokens.const priceCents = (usage: { inputTokens: number; outputTokens: number }) => Math.ceil((usage.inputTokens * 300 + usage.outputTokens * 1500) / 1_000_000);
const reply = await limitry.reserve( { subject: { kind: "user", id: user.id }, action: "ai-call", cost: 5 }, async (reservation) => { const res = await callModel(prompt); reservation.cost(priceCents(res.usage)); return res.text; },);console.log(reply);import math
from limitry import Limitry
limitry = Limitry() # uses the LIMITRY_API_KEY environment variable
# Your prices, in cents per million tokens.def price_cents(usage) -> int: return math.ceil((usage.input_tokens * 300 + usage.output_tokens * 1500) / 1_000_000)
with limitry.reserve( subject={"kind": "user", "id": user.id}, action="ai-call", cost=5) as reservation: res = call_model(prompt) reservation.cost = price_cents(res.usage) print(res.text)When the user’s budget can’t cover the hold, reserve throws
LimitReachedError, or raises it in Python. The reply is never generated,
so you don’t pay for it. If your request fails, reserve gives the hold
back, so a failed reply costs the user nothing.
Limit AI spend per user goes further:
what to tell a user Limitry refuses, what to do when your code can’t
reach Limitry, and a budget for each model. When every request costs the same,
guard checks and runs your code in one step, without a hold.
6. Go live
Section titled “6. Go live”When your limits work in test, move them to production:
- On the Limits page, still in test, click Copy to live. Check what it will create, then confirm.
- Create a key with Check limits under Settings → Developers,
and choose Live for its side. Your production code only checks,
and that’s what Check limits allows. The key starts with
lim_live_. - Give your production code the live key. Nothing else changes. The same code now uses your live limits, and its checks count toward your plan.
Next, Checks covers everything a check can do. The introduction lists guides for what you might be building. Two good next steps are Show users where they stand and Warn your users before they hit a limit.