Use cases

Limitry works the same way in every one of these. All that changes is the limit and who it applies to.

Keep your product's AI costs per user under control

Your product has AI features your users rely on, and you pay for them by the token. A few heavy users, or one script, can cost more than they pay you.

The rule. Each of your free users gets a $2 AI budget a month. Reserve what each reply will probably cost, and charge what it actually cost.

Limit AI spend per user: the full guide

await limitry.reserve(
  {
    subject: { kind: "user", id: user.id },
    action: "ai-call",
    cost: 54,
  },
  async (reservation) => {
    const res = await llm(prompt);
    reservation.cost(priceInCents(res.usage));
    return res;
  },
);
with limitry.reserve(
    subject={"kind": "user", "id": user.id},
    action="ai-call",
    cost=54,
) as reservation:
    res = llm(prompt)
    reservation.cost = price_in_cents(res.usage)

Sell prepaid credits

Customers buy credits, and everyone on their team spends from the same balance. When it runs out, you want them to buy more, not wait.

The rule. Each team has a balance that never resets. Your payment webhook adds credits, and every member's request draws from them.

Sell prepaid credits: the full guide

await limitry.guard(
  {
    subject: { kind: "user", id: user.id },
    shared: [
      { kind: "team", id: user.teamId },
    ],
    action: "report",
    cost: 25,
  },
  () => buildReport(params),
);
with limitry.guard(
    subject={"kind": "user", "id": user.id},
    shared=[
        {"kind": "team", "id": user.team_id},
    ],
    action="report",
    cost=25,
):
    report = build_report(params)

Rate-limit your own API's customers

Your customers call your API with their own keys. One customer's runaway loop shouldn't slow down everyone else.

The rule. Each key gets 60 requests in any minute and 1,000 in any hour. Over either, respond with 429 and Retry-After.

Rate-limit your API's customers: the full guide

await limitry.guard(
  {
    subject: { kind: "apikey", id: keyId },
    action: "api-request",
  },
  () => route(request),
);
with limitry.guard(
    subject={"kind": "apikey", "id": key_id},
    action="api-request",
):
    response = route(request)

Give each AI agent your product runs a budget

Agents in your product call models and paid tools in a loop. A loop that goes wrong can spend a lot before anyone looks.

The rule. Each AI agent your product runs gets $5 a day across every model and tool call. At the cap, it stops between steps until the next day, and someone on your team can reset it early from the Usage page.

Budgets for AI agents: the full guide

await limitry.reserve(
  {
    subject: { kind: "agent", id: agentId },
    action: "tool",
    cost: 10,
  },
  async (reservation) => {
    const result = await callTool(input);
    reservation.cost(result.costCents);
    return result;
  },
);
with limitry.reserve(
    subject={"kind": "agent", "id": agent_id},
    action="tool",
    cost=10,
) as reservation:
    result = call_tool(tool_input)
    reservation.cost = result.cost_cents

Cap heavy jobs running at once

Exports, imports and renders are heavy. You want each customer to run only a few at a time, and a crashed job mustn't hold its place forever.

The rule. Each customer's workspace runs at most 3 exports at once. A job takes a slot when it starts and gives it back when it ends, or when its worker stops responding.

Cap jobs running at once: the full guide

await limitry.reserve(
  {
    subject: {
      kind: "workspace",
      id: workspaceId,
    },
    action: "export",
    ttlSeconds: 600,
  },
  async (reservation) => {
    for (const chunk of chunks) {
      await exportChunk(chunk);
      // Still running: keep the slot
      await reservation.extend(600);
    }
  },
);
with limitry.reserve(
    subject={
        "kind": "workspace",
        "id": workspace_id,
    },
    action="export",
    ttl_seconds=600,
) as reservation:
    for chunk in chunks:
        export_chunk(chunk)
        # Still running: keep the slot
        reservation.extend(600)

Reset on each customer's billing date

Your customers subscribe on any day of the month, and some pay yearly. Their allowance should reset on the day they're billed, not on the 1st.

The rule. Each team's 1,000 reports reset every month on the team's billing day, even on an annual plan. Support can reset a team early.

When limits reset: how it works

// From your billing webhook,
// when a subscription starts
await limitry.subjects.update(
  "team",
  team.id,
  { billingAnchorAt: subscription.startedAt },
);
# From your billing webhook,
# when a subscription starts
limitry.subjects.update(
    "team",
    team.id,
    billing_anchor_at=subscription.started_at,
)

Limits that reset after first use

In a chat product, each user can get a burst of messages that resets a few hours after their first one. A user who starts late still gets the whole window.

The rule. On top of their monthly budget, each user gets 45 messages every 5 hours, starting from their first message.

A short limit from first use: in the guide

await limitry.limits.create({
  name: "Messages per 5 hours",
  subject: { kind: "user" },
  action: "chat",
  amount: 45,
  window: "hour",
  every: 5,
  start: "first_use",
});
limitry.limits.create(
    name="Messages per 5 hours",
    subject={"kind": "user"},
    action="chat",
    amount=45,
    window="hour",
    every=5,
    start="first_use",
)

A free plan no one can use up on day one

Your free plan has a monthly quota. One new sign-up shouldn't use up the whole month on day one.

The rule. Free teams get 3,000 emails a month and at most 100 a day. Paid teams get their quota with no daily cap.

Offer a free plan with a daily cap: the full guide

await limitry.guard(
  {
    subject: {
      kind: `team-${team.plan}`,
      id: team.id,
    },
    action: "send-email",
  },
  () => sendEmail(message),
);
with limitry.guard(
    subject={
        "kind": f"team-{team.plan}",
        "id": team.id,
    },
    action="send-email",
):
    send_email(message)

Something else?

If you can say it as "this many, per this, per this long", Limitry can probably enforce it. Read how limits work.

Start free Tell us what you need Compare plans

Free for 100,000 checks a month. No card needed.