Skip to content

Limits

Terminal window
npm install @limitry/sdk
import { createClient } from "@limitry/sdk";
const limitry = createClient(); // reads LIMITRY_API_KEY

GET /v1/limits

The workspace’s active limits, newest first (archived=true: the archived ones).

await limitry.limits.list();
FieldDescription
limitnumber, queryItems per page, 1–100 (default 25).
cursorstring, queryOpaque token from a previous page's nextCursor.
subjectKindstring, queryOnly this kind.
actionstring, queryOnly this action.
archivedstring, querytrue: the archived limits instead.
More about this endpoint

Filter by subjectKind and action; paginate with the opaque nextCursor token.

POST /v1/limits

Limits how much of an action a subject may use per window — for example 200 cents of ai-call a month for every user.

await limitry.limits.create({
name: "AI budget",
subjectKind: "user",
action: "ai-call",
amount: 200,
window: "month",
});
FieldDescription
namestring, requiredA name for the limit, unique among its environment's active limits.
subjectKindstring, requiredYour own label for who is checked.
subjectIdstringOne subject; omit or null for every subject of the kind. A subject's own limit replaces the kind's limits with the same action and window.
actionstring, requiredThe action to limit; * for every action.
amountnumber, requiredHow many units each subject may use per window.
unitstringWhat the amount counts (display only). Default: units.
windowstring, requiredminute, hour, day, week, month or year: a period of every of them, refilled where start says (or rolling: see rolling). total: a balance that never resets, topped up by grants. concurrent: at most amount held reservations at once.
everynumberHow many window units a period lasts: window: "month", every: 3 is a quarter, window: "hour", every: 5 five hours. Default: 1.
startstringWhere a period begins. calendar: UTC boundaries (midnight, Monday, the 1st, 1 January). anchor: from the subject's anchor, its billing date, set with subjects.update (its first check until then), so an annual plan can refill monthly from its start day. first_use: at the first check after the previous period ended. Default: calendar.
rollingbooleanCount the last window instead of the calendar one (minute, hour or day only). Default: false.
enabledbooleanWhether checks enforce it. Default: true.
failModestringWhat your code should do when Limitry can't be reached: open (allow) or closed (deny). Default: open.
More about this endpoint

Checks enforce it from then on. Names are unique among the environment’s active limits. Owners and admins only, for a person’s token.

GET /v1/limits/{limitId}

One limit: who it applies to, the action, amount and window.

await limitry.limits.get("lim_3f0c…");
FieldDescription
limitIdstring, path, required

PATCH /v1/limits/{limitId}

Changes any of a limit’s fields; checks use the new rule within a minute.

await limitry.limits.update("lim_3f0c…");
FieldDescription
limitIdstring, path, required
namestringA name for the limit, unique among its environment's active limits.
subjectKindstringYour own label for who is checked.
subjectIdstringOne subject; omit or null for every subject of the kind. A subject's own limit replaces the kind's limits with the same action and window.
actionstringThe action to limit; * for every action.
amountnumberHow many units each subject may use per window.
unitstringWhat the amount counts (display only). Default: units.
windowstringminute, hour, day, week, month or year: a period of every of them, refilled where start says (or rolling: see rolling). total: a balance that never resets, topped up by grants. concurrent: at most amount held reservations at once.
everynumberHow many window units a period lasts: window: "month", every: 3 is a quarter, window: "hour", every: 5 five hours. Default: 1.
startstringWhere a period begins. calendar: UTC boundaries (midnight, Monday, the 1st, 1 January). anchor: from the subject's anchor, its billing date, set with subjects.update (its first check until then), so an annual plan can refill monthly from its start day. first_use: at the first check after the previous period ended. Default: calendar.
rollingbooleanCount the last window instead of the calendar one (minute, hour or day only). Default: false.
enabledbooleanWhether checks enforce it. Default: true.
failModestringWhat your code should do when Limitry can't be reached: open (allow) or closed (deny). Default: open.
More about this endpoint

Owners and admins only, for a person’s token.

POST /v1/limits/{limitId}/archive

Stops a limit: checks stop enforcing it within a minute, and it leaves the list.

await limitry.limits.archive("lim_3f0c…");
FieldDescription
limitIdstring, path, required
More about this endpoint

It is archived, not erased — its usage history and credit grants stay, and POST /v1/limits/{limitId}/restore brings it back. Owners and admins only, for a person’s token.

POST /v1/limits/{limitId}/restore

Brings an archived limit back into force — refused while an active limit has its name.

await limitry.limits.restore("lim_3f0c…");
FieldDescription
limitIdstring, path, required
More about this endpoint

Owners and admins only, for a person’s token.

POST /v1/limits/sync

Makes the environment’s limits match limits, by name: creates the missing, changes those that differ (an omitted field means its default) and, with archiveMissing, archives active limits the list doesn’t name.

await limitry.limits.sync({
limits: [
{
name: "AI budget",
subjectKind: "user",
action: "ai-call",
amount: 200,
unit: "cents",
window: "month",
},
],
});
FieldDescription
limitsarray, requiredEvery limit you want, each described whole: an omitted field is its default, as on create. Names are the key and must be unique in the list. At most 200.
archiveMissingbooleanArchive the environment's active limits whose names aren't in limits (restorable). Default: false, which leaves them alone.
dryRunbooleanAnswer what the sync would do and change nothing. Default: false.
More about this endpoint

Running it twice changes nothing the second time. Limitry checks the whole list first, and a problem anywhere changes nothing (400, each problem in details); then it writes every change at once. dryRun answers the plan without writing. For keeping limits in a file in your repository (limitry sync). Owners and admins only, for a person’s token.

GET /v1/limits/{limitId}/grants

Credits added to subjects’ balances for this limit, newest first.

await limitry.limits.grants.list("lim_3f0c…");
FieldDescription
limitIdstring, path, required

POST /v1/limits/{limitId}/grants

Adds amount to one subject’s balance — a limit whose window is total.

await limitry.limits.grants.create("lim_3f0c…", {
subject: {
kind: "team",
id: "team_42",
},
amount: 5000,
});
FieldDescription
limitIdstring, path, required
subjectobject, requiredWho gets the credits, as {"kind": "team", "id": "team_42"}.
amountnumber, requiredCredits to add; negative to take them back. Not 0.
notestringRequired when amount is negative.
More about this endpoint

A negative amount takes credits back (a refund, a chargeback) and needs a note saying why; the balance may go below zero, and checks are refused until it is topped up. Owners and admins, or a workspace API key; an agent asks a person (the limit.grant approval).