# Quickstart

> Create a limit and make your first check, in about five minutes.

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

[Sign up](https://app.limitry.com/sign-up), verify your email and create a workspace. Limits, keys and usage all belong to a workspace.

## 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](/docs/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.

```bash
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:

* TypeScript

  ```bash
  npm install @limitry/sdk
  ```

* Python

  ```bash
  pip install limitry
  ```

* CLI

  ```bash
  npm install -g @limitry/cli
  ```

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

* TypeScript

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

* Python

  ```python
  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)
  ```

* CLI

  ```bash
  limitry limits create --name "AI budget" --subject '{"kind":"user"}' \
    --action ai-call --amount 200 --unit cents --window month
  ```

* curl

  ```bash
  curl -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:

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

## 4. Check before the work

Ask whether user `user_123` may make an AI request that costs 5 cents:

* TypeScript

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

* Python

  ```python
  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)
  ```

* CLI

  ```bash
  limitry check user:user_123 ai-call --cost 5
  ```

* curl

  ```bash
  curl -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:

```json
{
  "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

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](/docs/typescript/) and [Python](/docs/python/) SDK pages have the details.

* TypeScript

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

* Python

  ```python
  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](/docs/guides/limit-ai-spend/) 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

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](/docs/checks/) covers everything a check can do. The [introduction](/docs/#what-are-you-building) lists guides for what you might be building. Two good next steps are [Show users where they stand](/docs/guides/show-usage/) and [Warn your users before they hit a limit](/docs/guides/warn-users/).
