What you’ll build
An Express server with rate-limited endpoints. Users who exceed the limit get a 429 response. Time to complete: ~5 minutesPrerequisites
- Unkey account (free)
- Root key with
ratelimit.*.limitpermission - Node.js 18+
What’s in the response?
limiter.limit() returns:
| Field | Type | Description |
|---|---|---|
success | boolean | true if allowed, false if rate limited |
remaining | number | Requests left in current window |
reset | number | Unix timestamp (ms) when window resets |
limit | number | The configured limit |
Using as middleware
For cleaner code, create reusable middleware:middleware/ratelimit.js
createMiddleware helper
Create an Express middleware from a Ratelimit instance:Different limits per route
Create multiple limiters:Next steps
How it works
Understand the architecture
Per-user overrides
Give specific users higher limits
SDK Reference
All configuration options
Add API key auth
Combine with API key authentication
Troubleshooting
Rate limit not applying?
Rate limit not applying?
- Verify
UNKEY_ROOT_KEYis set and hasratelimit.*.limitpermission - Make sure you’re using a consistent identifier per user
- Check that
.envis loaded before creating the limiter
TypeScript version?
TypeScript version?
Install types and use imports:

