Skip to content

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.

Sign up, verify your email and create a workspace. Limits, keys and usage all belong to a workspace.

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.

Terminal window
export LIMITRY_API_KEY="lim_test_…" # the SDKs read this
export LIMITRY_TOKEN="$LIMITRY_API_KEY" # the CLI reads this

Workspace 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:

Terminal window
npm install @limitry/sdk

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);

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:

Terminal window
limitry check user:user_123 ai-call --cost 5
# Allowed. AI budget: 195 cents left, resets 2026-11-01T00:00:00.000Z

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);

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.

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);

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.

When your limits work in test, move them to production:

  1. On the Limits page, still in test, click Copy to live. Check what it will create, then confirm.
  2. 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_.
  3. 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.