# Rate limits

Every `/api/v1/*` request is metered. The main limits are per token, so one integration can't starve another. A per-IP safety net for failed sign-ins and a few per-organisation caps sit on top.

## Per-token limits

Every token (a personal access token, or PAT, or an organisation API key) gets its own budget:

| Limit | Window | Applies to |
| --- | --- | --- |
| **1,000 reads/min** | fixed 60 seconds | Every GET on `/api/v1/*`. |
| **100 mutations/min** | fixed 60 seconds | Every POST / PATCH / DELETE / PUT on `/api/v1/*`, including verb endpoints. |

The two budgets are separate. Burning 1,000 reads doesn't reduce your mutation budget; burning 100 mutations doesn't reduce reads.

Mutations are metered **before** body parse. A 400 from a malformed body still ticks the counter — without that, an attacker holding a leaked token could trigger unbounded parse work by replaying malformed bodies. Successful mutations carry an explicit signal:

```
X-RateLimit-Limit-Mutations: 100
```

That is the only rate-limit header. No header reports what is left of a budget or when its window resets, and reads carry none at all. To stay under a limit, count your own requests; when you do hit one, the 429's `Retry-After` says how long to wait.

### A whole register in one call

`POST /api/v1/registers/from-document` saves up to 200 risks in one request, so it costs more than one mutation. It is charged in two steps.

1. It pays the same single mutation as any request when it arrives.
2. Once the document has been checked, the rest of its cost is charged before anything is written: one mutation per 25 risks plus one per 64 KiB of JSON, at most the whole 100-a-minute budget.

If the rest does not fit in the current window, the request is a 429 and nothing is saved, and nothing beyond the entry mutation is charged. A replay with the same `Idempotency-Key` pays only the entry mutation. The 429 message says what the document costs.

## Pre-auth IP safety net

Both token shapes share a single per-IP failed-auth counter:

| Limit | Window | Counts |
| --- | --- | --- |
| **60 failures/min/IP** | fixed 60 seconds | Only confirmed auth failures (401). Successful auth never ticks this counter. |

This is the brute-force backstop. Legitimate traffic from behind a NAT (multiple users behind one corporate IP) is bounded by the per-token limits, not this one. Requests that authenticate successfully never trigger it.

## Per-org per-minute caps

Some surfaces have per-organisation caps in addition to the per-token limits:

| Surface | Per-org cap | Notes |
| --- | --- | --- |
| Webhook outbox dispatch | 300 events/min | The outbox is swept once a minute, up to 300 events per organisation per sweep and 450 across all organisations, shared fairly between them. A bulk import can queue thousands of events; they drain over the following minutes (a 1,000-row import takes at least four). Backpressure falls on the delivery queue, never on your requests. |
| Webhook deliveries to one endpoint | 100 attempts/min | Per endpoint, not per organisation. A delivery over the cap waits and is sent later, up to about two hours on, without using one of the event's attempts on the [webhook retry schedule](https://riskregister.com/docs/webhooks.md#retry-policy). |
| AI burst guard | 3 calls/min | Per organisation. Across every AI surface (register generation, suggest, auto-categorise). Separate from the per-organisation monthly cap (5 AI calls a month on Free, unlimited on Team and above). |

## 429 response

When you hit a limit:

```
HTTP/1.1 429 Too Many Requests
Retry-After: 18
Content-Type: application/json

{
  "error": "Rate limit exceeded. Retry after 18 seconds.",
  "code": "RATE_LIMITED",
  "details": { "retryAfterSeconds": 18 },
  "requestId": "…"
}
```

The `Retry-After` header is RFC 6585 / RFC 9110 §10.2.3 compliant. Most HTTP clients with retry support (axios-retry, fetch-retry, the Stripe SDK pattern) honour it automatically. The published TypeScript SDK does too: ≤5 second waits auto-retry once; longer waits throw `RateLimitError` so the agent loop can back off.

## What counts as a request?

Almost every request that reaches the API counts, whatever its outcome:

- A request that authenticates ticks one per-token counter: the read counter for a GET, the mutation counter for a POST, PATCH, PUT or DELETE. That includes requests answered with 400, 403, 404, 409, 412, 413 or 422, and with a 5xx (the cost was already incurred).
- A 401 ticks the pre-auth IP counter only.
- A 429 doesn't tick further; you're already over budget.

## Burst protection

The per-token mutation limit (100/min) is a fixed window: it opens with your first mutation and resets 60 seconds later. Bursting 100 requests in 1 second is fine; the 101st gets a 429, and `Retry-After` says when the window resets. Most legitimate traffic patterns (one-off scripts, agent loops) sit well below 100/min. If you're approaching it, the right answer is usually a bulk endpoint (`POST /api/v1/registers/from-document` saves a whole register in one call, see [above](#a-whole-register-in-one-call)) rather than hundreds of single-risk calls.


## SLA

There is no SLA on the rate limits today. The numbers are set conservatively and will change as we see real traffic. We'll announce changes via the changelog with a deprecation window matching the [API contract](https://riskregister.com/docs/overview.md#versioning--deprecation-policy).

## See also

- [Errors](https://riskregister.com/docs/errors.md) — the 429 surface.
- [Authentication](https://riskregister.com/docs/authentication.md) — the token shapes that share these counters.
