Prerequisites
- Created your Unkey account
- Created an Unkey root key with the following permissions:
ratelimit.*.create_namespace- to create namespacesratelimit.*.limit- to check rate limits
1
Create Next.js Application
Run the following command to init your Next.js project
2
Install
Now install the
@unkey/ratelimit package3
Add Root Key to env
Add your root key to your
.env file4
Creating a protected route
Create a new route and add the following code
/app/protected/route.ts
5
Running it
6
Try it out
Test your ratelimited endpoint:You will need to curl a few times to see the ratelimiting error. Once you do, you, you will need to wait to perform the action again.