# Checks API

> The checks endpoints, each in TypeScript, Python, the CLI and curl.

The checks endpoints, each in TypeScript, Python, the CLI and curl.

## Set up

* TypeScript

  ```bash
  npm install @limitry/sdk
  export LIMITRY_API_KEY="lim_test_…"
  ```

* Python

  ```bash
  pip install limitry
  export LIMITRY_API_KEY="lim_test_…"
  ```

* CLI

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

* curl

  ```bash
  export LIMITRY_API_KEY="lim_test_…"
  ```

To pass the key yourself, use `createClient({ apiKey: key })` in TypeScript or `Limitry(api_key=key)` in Python.

## Check whether a subject may act

`POST /v1/checks`[ Try it in the API playground (opens in a new tab)](https://api.limitry.com/v1/docs#tag/checks/POST/checks)

Scope: `checks:write`.

Asks whether `subject` may do `action` at `cost`, given every enabled limit that applies.

* TypeScript

  ```ts
  import { createClient } from "@limitry/sdk";

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();
  const check = await limitry.checks.create({
    subject: {
      kind: "user",
      id: "user_123",
    },
    action: "ai-call",
    cost: 5,
  });
  console.log(check);
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()
  check = limitry.checks.create(
      subject={"kind": "user", "id": "user_123"},
      action="ai-call",
      cost=5,
  )
  print(check)
  ```

* CLI

  Day to day: `limitry check <kind>:<id> <action>`. This endpoint’s own command:

  ```bash
  limitry checks create \
    --subject '{"kind":"user","id":"user_123"}' \
    --action 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}'
  ```

**Returns:**

```json
{
  "allowed": true,
  "reason": null,
  "limits": [
    {
      "limitId": "lmt_6f1c2a9e-4b7d-4e3a-9c5f-8d2b1a0e7c34",
      "limitName": "AI budget",
      "unit": "cents",
      "window": "month",
      "rolling": false,
      "failMode": "open",
      "amount": 200,
      "remaining": 195,
      "resetsAt": "2026-12-01T00:00:00.000Z"
    }
  ],
  "retryAfterSeconds": null,
  "reservation": {
    "id": "rsv_WyJ1c2VyIiwidXNlcl8xMjMiXQ_9f2c4e1a7b3d4c8e9a0f1b2c3d4e5f6a",
    "expiresAt": "2026-11-06T12:05:00.000Z"
  }
}
```

| Field                      | Description                                                                                                                                                                                                                                                                                                                          |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `subject` object, required | Who is acting, such as `{"kind": "user", "id": "user_123"}`.                                                                                                                                                                                                                                                                         |
| `shared` array             | Shared subjects the check also draws from, such as a team's, an organization's or a project's pool. Send at most 4. Every limit on every subject must fit, and Limitry charges either all of them or none.                                                                                                                           |
| `action` string, required  | What the subject wants to do.                                                                                                                                                                                                                                                                                                        |
| `cost` number              | The units the action would use. Default: 1.                                                                                                                                                                                                                                                                                          |
| `mode` string              | How the check counts. `consume` decides and counts, and is the default. `preview` decides without counting anything. `reserve` decides and holds `cost`, your estimate, until you commit the actual amount or release it. The response's `reservation` names what it holds. Only a reservation takes a slot of a `concurrent` limit. |
| `ttlSeconds` number        | With `reserve`, how many seconds the reservation lasts before it releases itself. Default: 300. At most 3600.                                                                                                                                                                                                                        |

More about this endpoint

In `consume` mode, it also counts the use. Every decision returns 200, whether it’s allowed or refused, so read `allowed`. `limits` shows what’s left on each limit, and `retryAfterSeconds` says when to try again. With an `Idempotency-Key` header, a retried check gets the same decision for an hour and counts only once. We cache its API key check briefly for speed. A revoked key can keep working here for up to 60 seconds.

## List checks

`GET /v1/checks`[ Try it in the API playground (opens in a new tab)](https://api.limitry.com/v1/docs#tag/checks/GET/checks)

Scope: `limits:read`.

Lists the checks of the last 3 days, newest first, with every subject each one named and whether Limitry allowed it.

* TypeScript

  ```ts
  import { createClient } from "@limitry/sdk";

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();
  const checks = await limitry.checks.list();
  console.log(checks);
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()
  checks = limitry.checks.list()
  print(checks)
  ```

* CLI

  ```bash
  limitry checks list
  ```

* curl

  ```bash
  curl -X GET "https://api.limitry.com/v1/checks" \
    -H "Authorization: Bearer $LIMITRY_API_KEY"
  ```

**Returns:**

```json
{
  "items": [
    {
      "checkedAt": "2026-11-21T14:32:08.000Z",
      "action": "ai-call",
      "cost": 5,
      "unit": "cents",
      "mode": "consume",
      "subjects": [
        {
          "kind": "user",
          "id": "user_123",
          "name": "Sara Khan"
        }
      ],
      "allowed": false,
      "refusedBy": {
        "limitId": "lmt_6f1c2a9e-4b7d-4e3a-9c5f-8d2b1a0e7c34",
        "limitName": "Team AI budget",
        "subject": {
          "kind": "user",
          "id": "user_123",
          "name": "Sara Khan"
        }
      }
    }
  ],
  "nextCursor": null
}
```

| Field                   | Description                                                                                                          |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `limit` number, query   | Items per page, 1–100 (default 25).                                                                                  |
| `cursor` string, query  | Opaque token from a previous page's nextCursor.                                                                      |
| `before` string, query  | Start from this moment: items older than it, newest first. Ignored with `cursor`, which already says where to go on. |
| `subject` string, query | Only checks that named this subject, as `kind:id`.                                                                   |
| `refused` string, query | `true` for only refused checks.                                                                                      |

More about this endpoint

A refused check says whose budget refused it. Name a `subject` as `kind:id` for only the checks that named it, or set `refused` for only refused ones. Send `before` to start from a moment. Limitry keeps the last 3 days, and at most 100,000 checks in each environment. Results come a page at a time.
