# Rate limits

Turn on Clerk's request and update limits, so the 11th update to one user in 10 seconds returns 429 with Retry-After.

Use this page to test how your code waits and retries when Clerk refuses a burst of requests. [`rate_limits: real`](https://www.rystic.ai/docs/network-profiles.md) turns on the limits that [Rate limits](https://www.rystic.ai/docs/simulators/clerk.md#rate-limits) sets out. Each user and each organization has its own 10 updates beside the key's 100 requests.

With the limits off, the default, 11 updates to one user all go through. They still count, so that user's next update is refused once the limits are on. Send 11 updates to a second user over one connection. Then send one more whose response you keep, a read and a jump of the simulator's clock, all inside 10 seconds:

```bash
AUTH='Authorization: Bearer sk_test_placeholder'
NEW_USER='{"email_address":["limits@example.com"],"skip_password_requirement":true,"legal_accepted_at":"2026-01-01T00:00:00Z"}'
FIRST=$(curl -s -H "$AUTH" -H 'Content-Type: application/json' "$RYSTIC_URL/v1/users" -d "$NEW_USER" | jq -r .id)
curl -s -X PATCH -H "$AUTH" -H 'Content-Type: application/json' -d '{"public_metadata":{"plan":"pro"}}' -w '%{http_code}\n' $(for i in $(seq 11); do echo "-o /dev/null $RYSTIC_URL/v1/users/$FIRST/metadata"; done) | sort | uniq -c | awk '{print $2, $1}'
# -> 200 11
USER=$(curl -s -H "$AUTH" -H 'Content-Type: application/json' "$RYSTIC_URL/v1/users" -d "${NEW_USER/limits@/limits2@}" | jq -r .id)
META="$RYSTIC_URL/v1/users/$USER/metadata"
BODY=$(mktemp); HEADERS=$(mktemp)
curl -s -X POST "$RYSTIC_URL/_rystic/network" -o /dev/null -w '%{http_code}\n' -d '{"rate_limits": "real"}'
# -> 204
curl -s -X PATCH -H "$AUTH" -H 'Content-Type: application/json' -d '{"public_metadata":{"plan":"pro"}}' -o /dev/null -w '%{http_code}\n' "$RYSTIC_URL/v1/users/$FIRST/metadata"
# -> 429
curl -s -X PATCH -H "$AUTH" -H 'Content-Type: application/json' -d '{"public_metadata":{"plan":"pro"}}' -w '%{http_code}\n' $(for i in $(seq 11); do echo "-o /dev/null $META"; done) | sort | uniq -c | awk '{print $2, $1}'
# -> 200 10
# -> 429 1
curl -s -X PUT -H "$AUTH" -H 'Content-Type: application/json' -d '{"public_metadata":{"plan":"team"}}' -D "$HEADERS" -o "$BODY" -w '%{http_code}\n' "$META"
# -> 429
jq -c '[.errors[].code]' "$BODY"
# -> ["too_many_requests"]
curl -s -X PATCH -H "$AUTH" -H 'Content-Type: application/json' -d '{"first_name":"Ada"}' -o /dev/null -w '%{http_code}\n' "$RYSTIC_URL/v1/users/$USER"
# -> 429
awk 'tolower($1) == "retry-after:" {print ($2 >= 1 && $2 <= 10)}' "$HEADERS"
# -> 1
curl -s -H "$AUTH" "$RYSTIC_URL/v1/users/$USER" | jq -c .public_metadata
# -> {"plan":"pro"}
curl -s -X POST "$RYSTIC_URL/_rystic/clock" -o /dev/null -w '%{http_code}\n' -d '{"advance_seconds":3600}'
# -> 204
curl -s -X PATCH -H "$AUTH" -H 'Content-Type: application/json' -d '{"public_metadata":{"plan":"pro"}}' -o /dev/null -w '%{http_code}\n' "$META"
# -> 429
```

The `PUT` and the `PATCH` of the user itself were refused too, since both metadata routes and `PATCH /v1/users/{user_id}` draw on one allowance per user. The read still returned the user, whose metadata kept the last update that went through. `Retry-After` gives the whole seconds until the window ends. The window runs on wall time, so the hour the clock jumped did not end it.

An organization has its own 10 updates, shared by its update routes as a user's are. A second key gets its own 100 requests. Neither the browser companion's script nor the JWKS, which Clerk leaves unlimited, counts toward any limit. A reset keeps the setting and gives every user and key a fresh allowance:

```bash
ORG=$(curl -s -H "$AUTH" -H 'Content-Type: application/json' "$RYSTIC_URL/v1/organizations" -d '{"name":"Limits"}' | jq -r .id)
curl -s -X PUT -H "$AUTH" -H 'Content-Type: application/json' -d '{"public_metadata":{"plan":"pro"}}' -w '%{http_code}\n' $(for i in $(seq 10); do echo "-o /dev/null $RYSTIC_URL/v1/organizations/$ORG/metadata"; done) | sort | uniq -c | awk '{print $2, $1}'
# -> 200 10
curl -s -X PATCH -H "$AUTH" -H 'Content-Type: application/json' -d '{"name":"Limits 2"}' -o /dev/null -w '%{http_code}\n' "$RYSTIC_URL/v1/organizations/$ORG"
# -> 429
curl -s -X PATCH -H "$AUTH" -H 'Content-Type: application/json' -d '{"public_metadata":{"plan":"team"}}' -o /dev/null -w '%{http_code}\n' "$RYSTIC_URL/v1/organizations/$ORG/metadata"
# -> 429
curl -s -H 'Authorization: Bearer sk_test_second' -w '%{http_code}\n' $(for i in $(seq 101); do echo "-o /dev/null $RYSTIC_URL/v1/users?limit=1"; done) | sort | uniq -c | awk '{print $2, $1}'
# -> 200 100
# -> 429 1
curl -s -w '%{http_code}\n' $(for i in $(seq 101); do echo "-o /dev/null $RYSTIC_URL/clerk.js"; done) | sort | uniq -c | awk '{print $2, $1}'
# -> 200 101
curl -s -H 'Authorization: Bearer sk_test_second' -w '%{http_code}\n' $(for i in $(seq 101); do echo "-o /dev/null $RYSTIC_URL/v1/jwks"; done) | sort | uniq -c | awk '{print $2, $1}'
# -> 200 101
curl -s -X POST "$RYSTIC_URL/_rystic/reset" -o /dev/null -w '%{http_code}\n'
# -> 204
curl -s "$RYSTIC_URL/_rystic/network" | jq -r .rate_limits
# -> real
USER=$(curl -s -H "$AUTH" -H 'Content-Type: application/json' "$RYSTIC_URL/v1/users" -d "$NEW_USER" | jq -r .id)
curl -s -X PATCH -H "$AUTH" -H 'Content-Type: application/json' -d '{"public_metadata":{"plan":"pro"}}' -w '%{http_code}\n' $(for i in $(seq 10); do echo "-o /dev/null $RYSTIC_URL/v1/users/$USER/metadata"; done) | sort | uniq -c | awk '{print $2, $1}'
# -> 200 10
curl -s -H 'Authorization: Bearer sk_test_second' -o /dev/null -w '%{http_code}\n' "$RYSTIC_URL/v1/users?limit=1"
# -> 200
```

---

Source: https://www.rystic.ai/docs/simulators/clerk/features/rate-limits · Markdown: https://www.rystic.ai/docs/simulators/clerk/features/rate-limits.md
