Tutorial: Auth and Rate Limits
Protect API with a key
Start server with:
bash
CLAUDE_API_KEY=secret-key npx clauditoriumRequests to /ask and /chat must include:
bash
-H "x-api-key: secret-key"Missing/invalid key returns 401 unauthorized.
Trigger and handle rate limiting
Example config:
bash
CLAUDE_API_RATE_LIMIT_WINDOW_SECONDS=60 \
CLAUDE_API_RATE_LIMIT_MAX_REQUESTS=1 \
npx clauditoriumSecond request in the window returns 429 rate_limited with:
Retry-Afterheaderretry_after_secondsbody field
Client retry pattern
- If
429, waitretry_after_seconds. - Retry once or with bounded backoff.
- Log
request_idfor debugging.
Related transient errors
concurrency_limited(429): queue fullqueue_timeout(504): waited too long in queuetimeout(504): Claude execution timeout
Treat these as retryable with limits.