What you’ll build
A Bun HTTP server with rate limiting. Users who exceed the limit get a 429 response. Time to complete: ~3 minutesPrerequisites
- Unkey account (free)
- Root key with
ratelimit.*.limitpermission - Bun installed
1
Create a Bun project
2
Install the SDK
3
Add your root key
Create a
.env file:.env
4
Create your server
Replace
index.ts:index.ts
5
Run your server
6
Test it
What’s in the response?
limiter.limit() returns:
Multiple rate limiters
Create different limiters for different use cases:index.ts
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 in your.envfile - UseBun.env.UNKEY_ROOT_KEY(notprocess.env) - Check your root key hasratelimit.*.limitpermission
Environment not loading?
Environment not loading?
Bun loads
.env automatically. Make sure the file is in your project root
and restart the server.