# Rate limits

Rate limits cap how many requests a key, session or IP can make per minute on each group of endpoints, with headers on every response and a 429 when you go over.

Rate limits are per-minute caps on how many requests one caller can make to each group of endpoints, which keep a shared API responsive. Every response says how much of the current limit is left, and a request over it gets a `429` that says when to retry.

## When to use it

- Pace a batch job so it doesn't hit `429`.
- Handle a `429` with the right wait instead of guessing.
- Understand why a keyless endpoint, such as the free verify endpoint, is throttled by IP.

## How it works

1. **Each request is counted in a 60-second window**, for the endpoint group it belongs to.
2. **It's counted against the caller:** the API key, the signed-in console session, or the client IP when there's no credential. The embed render endpoints count against the embed token, or against the publishable key and the client IP together when the token isn't one Provenance issued for that key's account. A publishable key is public, so someone who copies it from your page uses up only their own share, not your visitors'. A publishable key Provenance doesn't recognize, or one that's revoked, counts against the client IP.
3. **Over the limit, the API answers `429`** [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded) with a `Retry-After` header, and doesn't run the request.

| Endpoints | Requests per minute |
| --- | --- |
| `POST /v1/attest/verifications` | 500 |
| `POST /v1/attest/attestations` and capture sessions | 200 |
| Embed render endpoints, `POST /v1/trace/readings` | 120 |
| Most other endpoints | 100 |
| The public trace registry and trace shares | 60 |
| `POST /v1/trace/chat/completions`, `/v1/public/*`, trace disclosure | 30 |
| `POST /v1/attest/claims/{id}/escalate` | 20 |

`POST /v1/attest/media/screen` also has an hourly cap per IP, because each screening calls a paid external detector. Sign-in links have a separate limit per email address.

## Headers

Every response, including successful ones, carries the current window. Check them on any request:

**curl**

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_full_K7mN3xQp9RbT2vWm8sYd4cFjLhXn6gAe

curl -s -o /dev/null -D - $PROVENANCE_API/v1/attest/claims \
  -H "Authorization: Bearer $PROVENANCE_KEY" | grep -i ratelimit
```

**Node**

```ts
const res = await fetch(`${process.env.PROVENANCE_API}/v1/attest/claims`, { headers: { Authorization: `Bearer ${process.env.PROVENANCE_KEY}` } });
console.log(res.headers.get("x-ratelimit-remaining"));
```

**Python**

```python
import os
import httpx

res = httpx.get(f"{os.environ['PROVENANCE_API']}/v1/attest/claims", headers={"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"})
print(res.headers["x-ratelimit-remaining"])
```

```text
x-ratelimit-limit: 100
x-ratelimit-remaining: 99
x-ratelimit-reset: 1792856810
```

- `X-RateLimit-Limit` (integer): The limit for this endpoint group.
- `X-RateLimit-Remaining` (integer): Requests left in the current window.
- `X-RateLimit-Reset` (integer): When the oldest counted request leaves the window, as a Unix time.
- `Retry-After` (integer): On a `429` only: seconds to wait before retrying.

## Back off on a 429

Wait for `Retry-After` seconds, then retry with exponential backoff and a little random jitter. Better still, slow down when `X-RateLimit-Remaining` gets low. The Node and Python SDKs retry `429` and `5xx` responses for you, honoring `Retry-After`, up to three times.

## Related

- [Errors](https://provenanceauth.com/docs/platform/errors.md)
- [Plans and usage](https://provenanceauth.com/docs/account/plans-and-usage.md), for monthly allowances, which are separate from rate limits
- [SDKs](https://provenanceauth.com/docs/get-started/sdks.md)
