# CLI

> Install the CLI, sign in, and set up and test your limits from a terminal or a script.

The Limitry command-line interface (CLI) lets you set up your limits and try them from a terminal or a script. You can create a limit, try a check, and see who is using what. It acts as **you**, in the workspaces you allow.

## Install

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

## Sign in

```bash
limitry login
```

Your browser opens. Sign in and choose which workspaces the CLI may use. Keep **Manage limits**, which every command in this guide needs, then click **Allow**. The CLI creates a personal access token for this computer and stores it in `~/.config/limitry/`. The token lasts 90 days. You’ll find the token under **Account → Personal access tokens**.

On a server or in CI there’s no browser, so pass a token instead. Create it with **Manage limits** under **Account → Personal access tokens**. Set it in the environment and the CLI writes nothing to disk, or use `login --token` to save it the same way a browser sign-in does. A workspace API key works too. It acts in its own workspace, so you don’t choose one.

```bash
LIMITRY_TOKEN=pat_… limitry whoami           # a personal access token
LIMITRY_TOKEN=lim_test_… limitry limits list   # a workspace API key
limitry login --token "$TOKEN"   # or save it (or: echo "$TOKEN" | limitry login)
```

`limitry logout` revokes the token and forgets it.

## Common tasks

Create a limit, in test:

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

Check a user, as your code would, for a reply that costs 5 cents:

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

See where a user stands, without counting anything:

```bash
limitry subjects standing user user_123
```

See who is using a limit now, and its usage over time:

```bash
limitry usage subjects --limit-id lmt_123
limitry usage query --limit-id lmt_123 --granularity day
```

When a limit is right, copy it to live from the **Limits** page in the app, or create it with `--environment live`.

## Choose a workspace

```bash
limitry workspace list
limitry workspace use acme       # the default for later commands
limitry workspace audit-events list --workspace other-co   # one call elsewhere
```

## Test and live

Commands act in **test** unless you say otherwise, so a mistake changes test limits, never the ones your customers depend on. To act in live, name it for one command, for a shell, or as the default:

```bash
limitry limits list --environment live      # one command
export LIMITRY_ENVIRONMENT=live             # this shell
limitry environment use live                # the default from now on
limitry environment                         # which one, and where it came from
limitry environment unset                   # back to test
```

`--environment` wins over `LIMITRY_ENVIRONMENT`, which wins over the default you set. After every command that calls the API, it prints `Environment: test` or `Environment: live` on stderr, so you always know which side it changed. Stdout stays the command’s output. With `--json`, an error’s JSON carries `environment` too. See [Test and live](/docs/test-and-live/).

## Commands

The commands come in groups, by what they work on:

```bash
limitry limits list
limitry limits create --name "AI budget" --subject '{"kind":"user"}' \
  --action ai-call --amount 200 --unit cents --window month
limitry checks create --subject '{"kind":"user","id":"user_123"}' \
  --action ai-call --cost 5
limitry limits archive lmt_123
```

Two everyday commands have shortcuts. Each sends the same request as its long form:

| Shortcut                             | Long form                                                 |
| ------------------------------------ | --------------------------------------------------------- |
| `limitry check <kind>:<id> <action>` | `limitry checks create --subject '{…}' --action <action>` |
| `limitry sync [file]`                | `limitry limits sync [file]`                              |

`limitry check` prints one line: allowed or refused, what’s left, and when it resets. It takes `--cost`, and `--shared <kind>:<id>` once for each shared subject. A refusal exits `5`, so a script can stop on it: `limitry check user:user_123 ai-call && run-job`. For a reservation, use `limitry checks create --mode reserve`. `limitry sync` keeps your limits in a file, as [Sync limits from GitHub](/docs/guides/sync-from-github/) shows. `limitry sync --dry-run` shows what a sync would change, and changes nothing. `limitry sync -` reads the file from standard input. [limitry.json](/docs/limitry-json/#syncing) has the details.

* `limitry --help` lists the groups. `limitry limits --help` lists the commands in a group. `--help` after any command lists its options.
* A list prints one page, and its last line gives the `--cursor` for the next one. `--all` prints every page.
* A field that takes a list takes its flag once for each value, such as `--event-type a --event-type b`. Commas work too: `--event-type a,b`.
* A yes-or-no field takes `--x` and `--no-x`. A field you can empty takes `--clear-<field>`.
* A command that can’t be undone asks for `--yes`.

Every command:

### General

* `limitry login`

  Sign in through the browser, or store a personal access token with --token

* `limitry logout`

  Revoke the stored token and forget it

* `limitry whoami`

  Show who the token acts as and which workspaces it can use

* `limitry config`

  Show the settings in effect, with the token hidden

* `limitry sync [file]`

  Short for \`limitry limits sync\`

* `limitry check <subject> <action>`

  Short for \`limitry checks create\`

* `limitry api <method> <path>`

  Call any API endpoint directly, in the selected workspace

### Checks

* [`limitry checks create`](/docs/reference/checks/#check-whether-a-subject-may-act)

  Check whether a subject may act

* [`limitry checks list`](/docs/reference/checks/#list-checks)

  List checks

### Limits

* [`limitry limits archive <limit-id>`](/docs/reference/limits/#archive-a-limit)

  Archive a limit

* [`limitry limits create`](/docs/reference/limits/#create-a-limit)

  Create a limit

* [`limitry limits credits create <limit-id>`](/docs/reference/limits/#add-credits-to-a-balance)

  Add credits to a balance

* [`limitry limits credits get <limit-id> <credit-id>`](/docs/reference/limits/#get-a-credit)

  Get a credit

* [`limitry limits credits list <limit-id>`](/docs/reference/limits/#list-a-balances-credits)

  List a balance's credits

* [`limitry limits get <limit-id>`](/docs/reference/limits/#get-a-limit)

  Get a limit

* [`limitry limits list`](/docs/reference/limits/#list-limits)

  List limits

* [`limitry limits restore <limit-id>`](/docs/reference/limits/#restore-an-archived-limit)

  Restore an archived limit

* [`limitry limits sync [file]`](/docs/reference/limits/#sync-limits-from-a-list)

  Make your limits match a file (shortcut: limitry sync)

* [`limitry limits update <limit-id>`](/docs/reference/limits/#change-a-limit)

  Change a limit

### Usage

* [`limitry usage overview`](/docs/reference/usage/#get-every-limits-usage-at-once)

  Get every limit's usage at once

* [`limitry usage query`](/docs/reference/usage/#get-a-limits-usage-over-time)

  Get a limit's usage over time

* [`limitry usage subjects`](/docs/reference/usage/#list-who-is-using-a-limit)

  List who is using a limit

### Subjects

* [`limitry subjects get <subject-kind> <subject-id>`](/docs/reference/subjects/#get-a-subject)

  Get a subject

* [`limitry subjects import`](/docs/reference/subjects/#name-many-subjects)

  Name many subjects

* [`limitry subjects list`](/docs/reference/subjects/#list-subjects)

  List subjects

* [`limitry subjects names delete <subject-kind> <subject-id>`](/docs/reference/subjects/#erase-a-subjects-name-and-labels)

  Erase a subject's name and labels

* [`limitry subjects reset <subject-kind> <subject-id>`](/docs/reference/subjects/#reset-a-subjects-limits)

  Reset a subject's limits

* [`limitry subjects standing <subject-kind> <subject-id>`](/docs/reference/subjects/#get-where-a-subject-stands)

  Get where a subject stands

* [`limitry subjects update <subject-kind> <subject-id>`](/docs/reference/subjects/#update-a-subject)

  Update a subject

### Reservations

* [`limitry reservations commit <reservation-id>`](/docs/reference/reservations/#commit-a-reservation)

  Commit a reservation

* [`limitry reservations extend <reservation-id>`](/docs/reference/reservations/#extend-a-reservation)

  Extend a reservation

* [`limitry reservations get <reservation-id>`](/docs/reference/reservations/#get-a-reservation)

  Get a reservation

* [`limitry reservations release <reservation-id>`](/docs/reference/reservations/#release-a-reservation)

  Release a reservation

### Environment

* `limitry environment list`

  Show the environment commands act in

* `limitry environment use <name>`

  Make \<name> the default environment for commands

* `limitry environment unset`

  Forget the environment you chose and use the workspace's default

### Workspace and team

* `limitry workspace list`

  List the workspaces the token can act in

* `limitry workspace use <slug>`

  Make \<slug> the default workspace for workspace commands

* [`limitry workspace approval-actions list`](/docs/reference/approvals/#list-the-actions-you-can-ask-approval-for)

  List the actions you can ask approval for

* [`limitry workspace approval-requests create`](/docs/reference/approvals/#ask-a-person-to-approve-an-action)

  Ask a person to approve an action

* [`limitry workspace approval-requests get <approval-request-id>`](/docs/reference/approvals/#check-an-approval-request)

  Check an approval request

* [`limitry workspace approval-requests redeem <request-id>`](/docs/reference/approvals/#redeem-an-approved-request)

  Collect an approved secret once, into an env file (never printed)

* [`limitry workspace audit-events list`](/docs/reference/audit-events/#list-workspace-audit-events)

  List workspace audit events

* [`limitry workspace event-types list`](/docs/reference/webhooks/#list-event-types)

  List event types

* [`limitry workspace get`](/docs/reference/workspace/#get-the-current-workspace)

  Get the current workspace

* [`limitry workspace invitations list`](/docs/reference/workspace/#list-pending-invitations)

  List pending invitations

* [`limitry workspace members list`](/docs/reference/workspace/#list-workspace-members)

  List workspace members

* [`limitry workspace plan-usage get`](/docs/reference/workspace/#get-your-plans-usage-this-period)

  Show your plan's usage this period

* [`limitry workspace teams list`](/docs/reference/workspace/#list-teams)

  List teams

* [`limitry workspace webhook-deliveries list <endpoint-id>`](/docs/reference/webhooks/#list-an-endpoints-deliveries)

  List an endpoint's deliveries

* [`limitry workspace webhook-deliveries redeliver <endpoint-id> <delivery-id>`](/docs/reference/webhooks/#redeliver-an-event)

  Redeliver an event

* [`limitry workspace webhook-endpoints create`](/docs/reference/webhooks/#add-a-webhook-endpoint)

  Add a webhook endpoint

* [`limitry workspace webhook-endpoints delete <endpoint-id>`](/docs/reference/webhooks/#remove-a-webhook-endpoint)

  Remove a webhook endpoint

* [`limitry workspace webhook-endpoints enable <endpoint-id>`](/docs/reference/webhooks/#re-enable-a-webhook-endpoint)

  Re-enable a webhook endpoint

* [`limitry workspace webhook-endpoints get <endpoint-id>`](/docs/reference/webhooks/#get-a-webhook-endpoint)

  Get a webhook endpoint

* [`limitry workspace webhook-endpoints list`](/docs/reference/webhooks/#list-webhook-endpoints)

  List webhook endpoints

* [`limitry workspace webhook-endpoints test <endpoint-id>`](/docs/reference/webhooks/#send-a-test-event)

  Send a test event

* [`limitry workspace webhook-endpoints update <endpoint-id>`](/docs/reference/webhooks/#update-a-webhook-endpoint)

  Update a webhook endpoint

### Personal access tokens

* [`limitry user me`](/docs/reference/personal-access-tokens/#get-the-current-user)

  Get the current user

* [`limitry user revoke-token`](/docs/reference/personal-access-tokens/#revoke-the-token-making-this-request)

  Revoke the token making this request

## Scripts and agents

Add `--json` to any command, and it prints exactly the JSON the API returns to stdout. Errors then go to stderr as JSON, in the API’s [error envelope](/docs/errors/) plus the HTTP status:

```bash
limitry limits list --json | jq '.items[].name'
```

```json
{
  "error": {
    "code": "forbidden",
    "message": "…",
    "status": 403,
    "requestId": "…",
    "docs": "https://limitry.com/docs/errors/#forbidden"
  }
}
```

When the API refused a field, the error’s `details` says what is wrong with each one. Without `--json`, the CLI prints each detail and the `docs` link on stderr.

The exit code says how a command ended:

| Code | Meaning                                                    |
| ---- | ---------------------------------------------------------- |
| `0`  | Success.                                                   |
| `1`  | A failure, such as the API refusing the call.              |
| `2`  | Wrong usage, such as a missing flag or an unknown command. |
| `4`  | You aren’t logged in, or the API refused your token.       |
| `5`  | Limitry refused a `limitry check`.                         |

## The API underneath

Every command calls the same public API your code uses, signed in with your personal access token.

* A command that calls one API operation links to it in the list above. Under **Endpoints**, each operation shows its command next to the same call in TypeScript, Python and curl.
* Ids in an operation’s path become the command’s arguments, and its other inputs become flags. `--data '{…}'` sends a whole JSON body.
* Every write sends an [idempotency key](/docs/idempotency/). If an attempt fails, the CLI retries it with the same key. To run a command again without repeating its writes, pass the same `--idempotency-key <key>` both times.
* `limitry api <method> <path>` calls any endpoint directly.
* `--base-url <url>`, or the `LIMITRY_BASE_URL` environment variable, points the CLI at another API address. Give the address without `/v1`.
