Skip to main content
The Limitly Next.js SDK provides built-in middleware functionality to easily add rate limiting to your Next.js API routes.

Basic Middleware

Create middleware for your API routes:

Using withRateLimit Helper

The withRateLimit helper provides a simpler way to add rate limiting:

Custom Middleware Options

Configure middleware with custom options:

Global Middleware Setup

Set up middleware globally for all API routes:

Error Handling

Handle different types of errors in your middleware:

Multiple API Keys

Handle multiple API key formats:

Testing Middleware

Test your middleware with different scenarios:

Next Steps