# Errors and rate limits

> The error envelope, the error codes you can rely on, and how fast each credential may call the API.

Every response outside the 2xx range uses the same envelope:

```json
{
  "error": {
    "code": "invalid_request",
    "message": "Invalid request",
    "requestId": "9f0c1c2e-…",
    "docs": "https://limitry.com/docs/errors/#invalid_request",
    "details": [{ "path": "name", "message": "Required" }]
  }
}
```

| Field       | What it is                                                                       |
| ----------- | -------------------------------------------------------------------------------- |
| `code`      | One of a small, stable set of codes. Branch on this.                             |
| `message`   | A sentence for people. It may change, so don’t parse it.                         |
| `requestId` | Matches the `X-Request-Id` response header. Include it when you contact support. |
| `details`   | Only on validation errors: one entry per field, with its `path` and `message`.   |
| `docs`      | A link to the code’s entry on this page.                                         |

## Successful responses

A request that works answers with one of these:

| Status | When                                                                                           |
| ------ | ---------------------------------------------------------------------------------------------- |
| `200`  | The request worked, and the body holds the result.                                             |
| `201`  | The request created something. The body is the new resource, and `Location` holds its path.    |
| `202`  | We accepted the request and finish it in the background, such as a webhook delivery we queued. |
| `204`  | The request worked, and there’s nothing to return, such as after a removal.                    |

`Location` is a path under `/v1`, such as `/v1/limits/lmt_123`. Send a `GET` to it to read the resource again.

## Error codes

We may add new codes over time. Treat a code you don’t recognise as `internal_error`.

### `unauthorized`

`401`. The credential is missing, malformed, invalid, revoked or expired. Send `Authorization: Bearer <key or token>` with a working credential. If someone revoked the credential or it has expired, create a new one.

### `forbidden`

`403`. The credential is valid but isn’t allowed to do this. There are three possible causes:

* The credential doesn’t have the endpoint’s [scope](/docs/authentication/#permissions).
* Your role in the workspace doesn’t allow the action.
* A personal access token can’t act in the workspace named by `X-Workspace`.

Use a credential with the access it needs. The `message` names the missing scope.

Two more cases come from [test and live](/docs/test-and-live/). An API key always acts in its own environment, so a request whose `X-Environment` header names another one gets `403`. A test key can read workspace-wide settings but not change them, so adding a webhook endpoint with a test key gets `403` with the message “A test key cannot change workspace-wide settings”.

### `not_found`

`404`. The resource doesn’t exist, or it isn’t yours to see. Check the path and the id. An id from another workspace also counts as not found.

### `method_not_allowed`

`405`. The path exists, but not with this method. Use one of the methods in the `Allow` response header.

### `invalid_request`

`400`. The request didn’t pass validation. `details` lists each invalid field with its `path` and `message`. An `X-Environment` header that names an environment other than `test` or `live` gets this code too.

You can’t change what a limit counts: its subject, action, unit, window, `every`, `start` or `rolling`. A request that tries gets `400` from [limits](/docs/limits/). Create a new limit instead.

### `conflict`

`409`. The request is valid, but it clashes with the resource’s current state. Change the request, or the resource, and send it again. These cases get it:

* A new or renamed limit takes the name of an active limit. Choose a name of its own.
* A request changes a limit, or the workspace’s kinds, that a sync sets. The message names where the sync came from. Change it in that file, or send `override` with a reason.
* A commit or release reaches a reservation that was already settled the other way, or that’s no longer held.
* An approval request is redeemed that isn’t approved, was already redeemed or has expired.
* A delivery is redelivered to a webhook endpoint that is switched off. Switch the endpoint back on first.

### `rate_limited`

`429`. The credential has used up its quota, or an API key is sending far too many checks that get refused. Wait the number of seconds in `Retry-After`, then retry with backoff. [API rate limits](#api-rate-limits) has the numbers.

### `plan_limit_reached`

`402`. The workspace has used up a monthly allowance this request needs. The message says which allowance ran out and when it resets. We emailed and notified the workspace’s owners at 80% and again at 100%. To carry on, upgrade the plan under **Settings → Billing** or wait for the month to reset. Retrying before then gets the same response.

On Pro and Business, live checks carry on past the plan’s allowed checks as extras, up to the workspace’s monthly spend cap. At the cap, a check gets `402` with `reason: "spend_cap"` in the error. To carry on, an owner raises the cap under **Settings → Billing**.

Test checks have their own allowance and no grace. Past it, a check made with a test key gets `402` with a message saying the workspace has used its plan’s test checks for the month. Live checks are not affected.

### `workspace_suspended`

`403`. We paused the workspace. We do this only in rare cases, such as abuse of the service, as our [terms](/terms/) describe. Nothing in it is deleted, and its owners have an email from us explaining why. To ask about it, write to the address in the `message`.

### `idempotency_key_reused`

`409`. This `Idempotency-Key` was already used for a different request. Use a new key for each new operation, and reuse a key only to retry the same request. [Idempotency](/docs/idempotency/) explains how keys work.

### `idempotency_in_progress`

`409`. A request with the same `Idempotency-Key` is still running. Wait the number of seconds in `Retry-After`, then retry with the same key.

### `moving`

`503` with `Retry-After: 1`. Some counts are moving between Limitry’s servers. That happens when a very busy workspace spreads its counts over more servers as its traffic grows, or when a workspace moves to a new region under **Settings → General**. A move takes a few seconds. Until it ends, checks, commits and releases on those subjects return `moving`.

Limitry charged nothing for the request. It gives back anything it held for it, or the retry finishes it. Retry with the same `Idempotency-Key` after `Retry-After`. The SDKs’ `guard` and `reserve` retry for you while the wait still fits in their time limit, which is 1.5 seconds by default. After that they apply the limit’s fail mode, and your request never waits longer. Other SDK calls, the CLI and the MCP server retry for up to 30 seconds.

### `busy`

`503` with a `Retry-After` header in seconds. Limitry is deciding too many checks for these subjects at once, so it returned this one straight away instead of making it wait in line.

Limitry charged nothing for the request. It gives back anything it held for it, or the retry finishes it. Wait the number of seconds in `Retry-After`, then retry with the same `Idempotency-Key`. If it happens again, back off with random jitter. The SDKs retry for you within the same time limit as `moving`, then apply the limit’s fail mode. This code is about Limitry’s load, not your quota. It isn’t `rate_limited`, and it isn’t a refusal.

### `internal_error`

`500`. Something failed on our side. Retry with backoff, and if the error keeps happening, contact support with the `requestId`. When the failure is temporary, you get [`unavailable`](#unavailable) instead.

A `503` that says Limitry “may have charged” the check means it couldn’t confirm the check in time. Retry it with the same `Idempotency-Key` to get its response, and never retry it without one. A check retried with its key is never counted twice.

### `unavailable`

`503` with a `Retry-After` header in seconds. We couldn’t serve the request right now, for example because checks are unavailable for a moment or we couldn’t check your API key. Wait the number of seconds in `Retry-After`, then retry with the same `Idempotency-Key`.

## Refusals

A refused check isn’t an error. It returns `200` with `"allowed": false`, and `reason.code` says why. The SDKs throw the first two codes below as `LimitReachedError`.

### `limit_reached`

The subject has used up a limit the check had to fit. `reason.limitId` and `reason.limitName` name that limit. `retryAfterSeconds` says when the same check could get a yes. For a balance it’s `null`, because only a credit raises a balance. The first time a limit refuses a subject in a window, your webhook endpoints also get [`limit.reached`](/docs/usage/#webhook-limitreached).

### `too_many_reservations`

The subject already has 1,000 open [reservations](/docs/reservations/). Commit or release some, or wait for them to expire.

### `UnavailableError`

This isn’t a code from the API. The SDKs throw `UnavailableError` when a limit’s fail mode is `closed` and they get no decision from Limitry. That happens when there’s no response in time, or the response is a `429`, a `5xx` or `402 plan_limit_reached`. Its `reason` says which: `timeout`, `unreachable`, `plan_limit_reached` or `rate_limited`. With `open`, the work runs instead. [How Limitry works](/docs/how-it-works/#when-your-code-cant-reach-limitry) has the details.

## API rate limits

Most authenticated requests count against a quota for their credential:

| Endpoints           | Quota counted per                                                                   |
| ------------------- | ----------------------------------------------------------------------------------- |
| Workspace endpoints | Credential: an API key, a personal access token, or a connected app for each person |
| `/v1/user/*`        | Personal access token                                                               |

Each credential may make up to 100 requests a minute. A personal access token or a connected app has a separate quota in test and in live. Checks and reservation calls made with an API key don’t count against the quota. They have their own cap, described under [Checks that keep getting refused](#checks-that-keep-getting-refused). When the quota runs out, the API returns `429` with `code: "rate_limited"`:

```http
HTTP/1.1 429 Too Many Requests
Retry-After: 15
```

`Retry-After` is the number of seconds left until the quota’s minute starts again, so it is between 1 and 60. Wait that long, then retry. Each credential has its own limit, so one busy integration never slows down another.

### Checks that keep getting refused

Allowed checks have no cap. A refused check is free, so Limitry caps refused checks for each API key in each Cloudflare location:

| Refused checks a second | What happens                                                                                                                                       |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| More than about 17      | For up to 5 seconds, repeating a check that was just refused gets the same `allowed: false` response, with the header `limitry-refusal: repeated`. |
| More than about 100     | For 10 seconds, the key’s checks get `429 rate_limited`. The SDKs treat this as Limitry being unavailable, so each limit’s fail mode decides.      |

In the first case, credits you add or a limit you raise can take up to those 5 seconds to show. Commits, releases and extends are never stopped.
