# Subjects API

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

The subjects 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.

## Get a subject

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

Scope: `limits:read`.

Returns a subject: its billing date, the day its `billing_date` limits start each new period, its name and labels if you gave it any, its budgets, and the subjects it’s checked with.

* TypeScript

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

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();
  const subject = await limitry.subjects.get("team", "team_42");
  console.log(subject);
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()
  subject = limitry.subjects.get("team", "team_42")
  print(subject)
  ```

* CLI

  ```bash
  limitry subjects get team team_42
  ```

* curl

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

**Returns:**

```json
{
  "subject": {
    "kind": "user",
    "id": "user_123"
  },
  "billingAnchorAt": "2026-03-17T14:30:00.000Z",
  "name": "Sara Khan",
  "labels": {
    "plan": "pro"
  },
  "budgets": [
    {
      "limitId": "lmt_6f1c2a9e-4b7d-4e3a-9c5f-8d2b1a0e7c34",
      "limitName": "AI budget",
      "unit": "cents",
      "window": "month",
      "amount": 200,
      "used": 120,
      "remaining": 80,
      "credited": 0,
      "resetsAt": "2026-12-01T00:00:00.000Z"
    }
  ],
  "links": [
    {
      "subject": {
        "kind": "user",
        "id": "user_123",
        "name": "Sara Khan"
      },
      "direction": "within",
      "limitId": "lmt_6f1c2a9e-4b7d-4e3a-9c5f-8d2b1a0e7c34",
      "limitName": "Team AI budget",
      "unit": "cents",
      "periodStart": "2026-11-01T00:00:00.000Z",
      "spent": 120,
      "allowed": 4,
      "refused": 1
    }
  ]
}
```

| Field                                | Description            |
| ------------------------------------ | ---------------------- |
| `subjectKind` string, path, required | The subject kind's ID. |
| `subjectId` string, path, required   | The subject's ID.      |

More about this endpoint

A subject is one of yours, such as a user, a team or an agent. It exists once a check names it. Its links say what was spent within each budget this period: within another subject’s budget, or another subject within its own.

## Update a subject

`PATCH /v1/subjects/{subjectKind}/{subjectId}`[ Try it in the API playground (opens in a new tab)](https://api.limitry.com/v1/docs#tag/subjects/PATCH/subjects/{subjectKind}/{subjectId})

Scope: `limits:write`.

Sets a subject’s billing date, its name, its labels, or any of them.

* TypeScript

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

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();
  const subject = await limitry.subjects.update("team", "team_42", {
    billingAnchorAt: "2026-03-17T14:30:00Z",
    name: "Design team",
    labels: {
      plan: "pro",
    },
  });
  console.log(subject);
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()
  subject = limitry.subjects.update(
      "team",
      "team_42",
      billing_anchor_at="2026-03-17T14:30:00Z",
      name="Design team",
      labels={"plan": "pro"},
  )
  print(subject)
  ```

* CLI

  ```bash
  limitry subjects update \
    team \
    team_42 \
    --billing-anchor-at 2026-03-17T14:30:00Z \
    --name 'Design team' \
    --labels '{"plan":"pro"}'
  ```

* curl

  ```bash
  curl -X PATCH "https://api.limitry.com/v1/subjects/team/team_42" \
    -H "Authorization: Bearer $LIMITRY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"billingAnchorAt":"2026-03-17T14:30:00Z","name":"Design team","labels":{"plan":"pro"}}'
  ```

**Returns:**

```json
{
  "subject": {
    "kind": "user",
    "id": "user_123"
  },
  "billingAnchorAt": "2026-03-17T14:30:00.000Z",
  "name": "Sara Khan",
  "labels": {
    "plan": "pro"
  }
}
```

| Field                                | Description                                                                                                                                                                            |
| ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `subjectKind` string, path, required | The subject kind's ID.                                                                                                                                                                 |
| `subjectId` string, path, required   | The subject's ID.                                                                                                                                                                      |
| `billingAnchorAt` string             | The moment the subject's periods start from, in ISO 8601, such as a subscription's start.                                                                                              |
| `name` string                        | A name people can read, up to 200 characters. Optional. Names don't have to be unique. Send null to clear it.                                                                          |
| `labels` object                      | Labels to filter by, such as a plan or a region: up to 20 keys of up to 40 characters, with values of up to 200. Optional. They replace the subject's labels. Send null to clear them. |

More about this endpoint

A field you leave out stays as it is, and null clears a name or labels. Labels you send replace the subject’s labels. The billing date is the moment the subject’s `billing_date` limits count their periods from, usually the subscription’s start, set from your billing system’s webhook. The subject’s allowance then resets on its own billing day, and a monthly limit still resets monthly on an annual plan. A name and labels are optional, and checks never need them. With a personal access token, the owner and admins can call this. Members can call it in test only, and guests can’t. A workspace API key with this scope can.

## Get where a subject stands

`GET /v1/subjects/{subjectKind}/{subjectId}/standing`[ Try it in the API playground (opens in a new tab)](https://api.limitry.com/v1/docs#tag/subjects/GET/subjects/{subjectKind}/{subjectId}/standing)

Scope: `limits:read`.

Returns where one subject stands on every enabled limit, exact as of now.

* TypeScript

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

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();
  const result = await limitry.subjects.standing("team", "team_42");
  console.log(result);
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()
  result = limitry.subjects.standing("team", "team_42")
  print(result)
  ```

* CLI

  ```bash
  limitry subjects standing team team_42
  ```

* curl

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

**Returns:**

```json
{
  "subject": {
    "kind": "user",
    "id": "user_123"
  },
  "limits": [
    {
      "limitId": "lmt_6f1c2a9e-4b7d-4e3a-9c5f-8d2b1a0e7c34",
      "limitName": "AI budget",
      "subject": {
        "kind": "user",
        "id": "user_123"
      },
      "action": "ai-call",
      "unit": "cents",
      "window": "month",
      "rolling": false,
      "amount": 200,
      "used": 5,
      "remaining": 195,
      "credited": 0,
      "resetsAt": "2026-12-01T00:00:00.000Z"
    }
  ]
}
```

| Field                                | Description                                                                   |
| ------------------------------------ | ----------------------------------------------------------------------------- |
| `subjectKind` string, path, required | The subject kind's ID.                                                        |
| `subjectId` string, path, required   | The subject's ID.                                                             |
| `shared` string, query               | Shared subjects to include, as comma-separated `kind:id` pairs. Send up to 4. |

More about this endpoint

It covers the subject’s own limits and the limits on its shared subjects. List the shared subjects in `shared`, such as `team:team_42`. Each limit shows what’s used, what’s left and when it resets. Use it to show your users where they stand. Call it from your server with your key, never from a browser. It isn’t a check, so it counts nothing. A subject with no limits returns an empty `limits` list.

## Reset a subject’s limits

`POST /v1/subjects/{subjectKind}/{subjectId}/reset`[ Try it in the API playground (opens in a new tab)](https://api.limitry.com/v1/docs#tag/subjects/POST/subjects/{subjectKind}/{subjectId}/reset)

Scope: `limits:write`.

Resets one limit on a subject now, or every limit on it.

* TypeScript

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

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();
  const result = await limitry.subjects.reset("team", "team_42", {
    limitId: "lmt_6f1c2a9e-4b7d-4e3a-9c5f-8d2b1a0e7c34",
  });
  console.log(result);
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()
  result = limitry.subjects.reset(
      "team",
      "team_42",
      limit_id="lmt_6f1c2a9e-4b7d-4e3a-9c5f-8d2b1a0e7c34",
  )
  print(result)
  ```

* CLI

  ```bash
  limitry subjects reset \
    team \
    team_42 \
    --limit-id lmt_6f1c2a9e-4b7d-4e3a-9c5f-8d2b1a0e7c34
  ```

* curl

  ```bash
  curl -X POST "https://api.limitry.com/v1/subjects/team/team_42/reset" \
    -H "Authorization: Bearer $LIMITRY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"limitId":"lmt_6f1c2a9e-4b7d-4e3a-9c5f-8d2b1a0e7c34"}'
  ```

**Returns:**

```json
{
  "subject": {
    "kind": "user",
    "id": "user_123"
  },
  "limitIds": [
    "lmt_6f1c2a9e-4b7d-4e3a-9c5f-8d2b1a0e7c34"
  ]
}
```

| Field                                | Description                                                  |
| ------------------------------------ | ------------------------------------------------------------ |
| `subjectKind` string, path, required | The subject kind's ID.                                       |
| `subjectId` string, path, required   | The subject's ID.                                            |
| `limitId` string                     | The one limit to reset. Default: every limit on the subject. |

More about this endpoint

Send `limitId` for one limit, or `{}` for all of them. Use it for goodwill, a promotion or support. The schedule doesn’t move, so the next reset still happens when it normally would. A balance goes back to its amount, and the reset skips concurrent limits. With an Idempotency-Key, a repeated request resets only once. With a personal access token, the owner and admins can call this. Members can call it in test only, and guests can’t. A workspace API key with this scope can.

## Erase a subject’s name and labels

`DELETE /v1/subjects/{subjectKind}/{subjectId}/names`[ Try it in the API playground (opens in a new tab)](https://api.limitry.com/v1/docs#tag/subjects/DELETE/subjects/{subjectKind}/{subjectId}/names)

Scope: `limits:write`.

Erases the name and labels you gave a subject.

* TypeScript

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

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();
  await limitry.subjects.names.delete("team", "team_42");
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()
  limitry.subjects.names.delete("team", "team_42")
  ```

* CLI

  ```bash
  limitry subjects names delete team team_42 --yes
  ```

* curl

  ```bash
  curl -X DELETE "https://api.limitry.com/v1/subjects/team/team_42/names" \
    -H "Authorization: Bearer $LIMITRY_API_KEY"
  ```

**Returns** nothing (`204`).

| Field                                | Description            |
| ------------------------------------ | ---------------------- |
| `subjectKind` string, path, required | The subject kind's ID. |
| `subjectId` string, path, required   | The subject's ID.      |

More about this endpoint

Its limits, usage and billing date stay, because they’re kept by its ID. Use it when one of your users asks you to delete their data. Erasing a subject with no name or labels succeeds too. With a personal access token, the owner and admins can call this. Members can call it in test only, and guests can’t. A workspace API key with this scope can.

## Name many subjects

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

Scope: `limits:write`.

Sets the name and labels of up to 1,000 subjects at once, such as when you first connect your user list.

* TypeScript

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

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();
  const result = await limitry.subjects.import({
    items: [
      {
        kind: "team",
        id: "team_42",
        name: "Design team",
        labels: {
          plan: "pro",
        },
      },
    ],
  });
  console.log(result);
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()
  result = limitry.subjects.import_(
      items=[
          {
              "kind": "team",
              "id": "team_42",
              "name": "Design team",
              "labels": {"plan": "pro"},
          },
      ],
  )
  print(result)
  ```

* CLI

  ```bash
  limitry subjects import \
    --items '[{"kind":"team","id":"team_42","name":"Design team","labels":{"plan":"pro"}}]'
  ```

* curl

  ```bash
  curl -X POST "https://api.limitry.com/v1/subjects/import" \
    -H "Authorization: Bearer $LIMITRY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"items":[{"kind":"team","id":"team_42","name":"Design team","labels":{"plan":"pro"}}]}'
  ```

**Returns:**

```json
{
  "imported": 1
}
```

| Field                   | Description                                                                                    |
| ----------------------- | ---------------------------------------------------------------------------------------------- |
| `items` array, required | The subjects to name, from 1 to 1,000: each its kind and ID, and its name, its labels or both. |

More about this endpoint

Each item works like updating that subject’s name and labels: a field you leave out stays as it is, and null clears it. Limitry checks every item before it saves any, so a bad item saves nothing. With a personal access token, the owner and admins can call this. Members can call it in test only, and guests can’t. A workspace API key with this scope can.

## List subjects

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

Scope: `limits:read`.

Lists every subject your checks have named in this environment, and every one you named, most recently checked first.

* TypeScript

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

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

* Python

  ```python
  from limitry import Limitry

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

* CLI

  ```bash
  limitry subjects list
  ```

* curl

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

**Returns:**

```json
{
  "items": [
    {
      "subject": {
        "kind": "user",
        "id": "user_123"
      },
      "name": "Sara Khan",
      "labels": {
        "plan": "pro"
      },
      "lastCheckedAt": "2026-11-21T14:00:00.000Z"
    }
  ],
  "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.                 |
| `kind` string, query   | Only subjects of this kind.                                     |
| `label` string, query  | Only subjects with this label, as `key:value`.                  |
| `q` string, query      | Only subjects whose name or ID contains this text, in any case. |

More about this endpoint

Filter by `kind` or by one `label`, and search the name or the ID with `q`. Results come a page at a time.
