# Rate limits and idempotency

Built in modules/identity for authentication, key creation and sign-in routes. In v1, identity limits are fixed-window counters in memory per API process.

## Identity rate limits (built)

Buckets are isolated so bad cookies or links do not lock out working API keys, and code verification outages refund the try so a WorkOS blip does not burn your five tries.

Fixed-window limits enforced by modules/identity

| Bucket | Limit | Window | Keyed by |
| --- | --- | --- | --- |
| Failed auth checks | 20 | 10 minutes | Client IP |
| Unauthenticated POST /v1/keys | 10 | 1 hour | Client IP |
| Unauthenticated POST /v1/keys | 3 | 1 hour | Target email (also caps emails sent) |
| Failed sign-in callbacks / wrong codes | 20 | 10 minutes | Client IP |
| Failed /v1/auth/refresh checks | 20 | 10 minutes | Client IP |
| Failed link token checks | 30 | 10 minutes | Client IP |
| POST /v1/auth/code tries | 5 | 10 minutes | Target email (counted before WorkOS is called) |
| POST /v1/auth/code tries | 20 | 10 minutes | Client IP (counted before WorkOS is called) |

## Handling HTTP 429

Every rate-limited response returns HTTP 429 with code rate_limited, a Retry-After header in whole seconds, and a fix field stating how long to wait. Wait at least Retry-After seconds before retrying.

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

{
  "code": "rate_limited",
  "message": "Too many sign-in code tries for this email or from this address.",
  "fix": "Wait 540 seconds, or sign in at /v1/auth/sign-in instead."
}
```

## Idempotency keys

Retriable write routes in upcoming product modules (profiles, generations, sites, banner publishes and evidence packs) accept an Idempotency-Key header backed by platform.idempotency_keys. Route-specific rules are added as modules/documents, modules/sites and modules/evidence ship.
