The pattern
Full implementation
Next.js API Route
Express Middleware
Using Unkey overrides (recommended)
Instead of managing limits in your code, use Unkey overrides to set per-user limits dynamically:- No code changes when limits change
- Overrides can be managed via API or dashboard
- Default limit applies to users without overrides
With API key verification
If you’re already using Unkey for API keys, attach rate limits directly to keys:Best practices
Use identifiers consistently
Always use the same identifier format (user ID, org ID) for accurate limiting across requests.
Communicate limits clearly
Return rate limit headers so clients know their limits and can back off gracefully.
Consider burst allowance
Pro/Enterprise users often expect some burst capacity. Consider slightly higher limits with shorter windows.
Log limit hits
Track when users hit limits to inform pricing decisions and identify potential abuse.

