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 a subject may use per window — for example 200 cents a month for every user.

await limitry.limits.create({
subject: {
kind: "user",
},
amount: 200,
window: "month",
});
FieldDescription
namestringA name, unique among the environment's active limits. Default: the sentence the limit reads as, such as "200 cents per user per month". If a limit already has that name, the answer is 409: give this one a name.
subjectobject, requiredWho it applies to: {"kind": "user"} for every user, {"kind": "user", "id": "usr_123"} for one.
actionstringThe action to limit. Default: *, every action.
amountnumber, requiredHow many units each subject may use per window.
unitstringWhat the amount counts, in words. Default: units.
windowstring, requiredminute, hour, day, week, month or year: a period of every of them, reset where start says (or rolling: see rolling). total: a balance that never resets, raised by credits. concurrent: at most amount open 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). billing_date: from the subject's billing date, set with subjects.update (its first check until then), so an annual plan can reset 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

Only subject.kind, amount and window are needed: action defaults to every action (*), unit to units, and name to the sentence the limit reads as. Checks enforce it from then on. What it counts (subject, action, unit, window, every, start, rolling) is fixed once created. 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("lmt_3f0c…");
FieldDescription
limitIdstring, path, required

PATCH /v1/limits/{limitId}

Changes a limit’s name, amount, fail mode or whether it is enabled; checks use the new rule at once.

await limitry.limits.update("lmt_3f0c…");
FieldDescription
limitIdstring, path, required
namestringA new name, unique among the environment's active limits.
amountnumberHow many units each subject may use per window.
enabledbooleanWhether checks enforce it.
failModestringWhat your code should do when Limitry can't be reached: open (allow) or closed (deny).
subjectobjectWho it applies to. Fixed once the limit is created: to change it, create a new limit and archive this one.
actionstringThe action. Fixed once the limit is created: to change it, create a new limit and archive this one.
unitstringWhat the amount counts. Fixed once the limit is created: to change it, create a new limit and archive this one.
windowstringThe window. Fixed once the limit is created: to change it, create a new limit and archive this one.
everynumberHow many windows a period lasts. Fixed once the limit is created: to change it, create a new limit and archive this one.
startstringWhere a period begins. Fixed once the limit is created: to change it, create a new limit and archive this one.
rollingbooleanWhether it counts the last window. Fixed once the limit is created: to change it, create a new limit and archive this one.
More about this endpoint

What a limit counts (subject, action, unit, window, every, start, rolling) is fixed: a different value is refused (400) — create a new limit and archive this one. Owners and admins only, for a person’s token.

POST /v1/limits/{limitId}/archive

Stops a limit: checks stop enforcing it at once, and it leaves the list.

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

It is archived, not erased — its usage history and credits 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("lmt_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",
subject: {
kind: "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. What a limit counts (subject, action, unit, window, every, start, rolling) is fixed: to change it, rename the entry, which creates a new limit. At most 200.
archiveMissingbooleanArchive the environment's active limits whose names aren't in limits (restorable). Default: false, which leaves them alone.
previewbooleanAnswer 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. What a limit counts is fixed: a different subject, action, unit or window under an existing name is refused until the entry is renamed. preview answers what it would do 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}/credits

Credits added to (or taken back from) subjects’ balances for this limit, newest first.

await limitry.limits.credits.list("lmt_3f0c…");
FieldDescription
limitIdstring, path, required

POST /v1/limits/{limitId}/credits

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

await limitry.limits.credits.create("lmt_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 more credits are added. Owners and admins, or a workspace API key; an agent asks a person (the limit.credit approval).