Upstash Rate Limiter
Serverless rate limiting with Redis.
MicroservicesAgent: claude
Required Configuration
This use case works best with the following environment variables, which are injected into your sandbox at runtime:
UPSTASH_REDIS_REST_URLUPSTASH_REDIS_REST_TOKEN
Prompt
Implement a production-grade rate limiting system using Upstash Redis:
1. Next.js middleware that enforces per-IP and per-user rate limits
2. Sliding window algorithm with configurable limits per route
3. Custom rate limit headers (X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)
4. Graceful 429 responses with retry-after information
5. Admin endpoint to view current rate limit status and top consumers
6. Bypass mechanism for allowlisted IPs
Use @upstash/ratelimit and @upstash/redis packages.