The Limitly Next.js SDK provides a simple and powerful way to integrate rate limiting into your Next.js application, optimized for server-side rendering and API routes.

Installation

NPM

npm install @limitly/limitly-nextjs

Yarn

yarn add @limitly/limitly-nextjs

PNPM

pnpm add @limitly/limitly-nextjs

Requirements

  • Node.js 18.0.0 or higher
  • Next.js 13.0.0 or higher

Basic Setup

Import and initialize the SDK:
import { Limitly } from '@limitly/limitly-nextjs';

const limitly = new Limitly({
  apiKey: 'your_limitly_api_key'
});

Configuration Options

The SDK accepts the following configuration options:
apiKey
string
required
Your Limitly API key. You can find this in your Limitly dashboard.
baseUrl
string
The base URL for the Limitly API. Defaults to https://api.limitly.dev.
timeout
number
Request timeout in milliseconds. Defaults to 30000 (30 seconds).

Example Configuration

import { Limitly } from '@limitly/limitly-nextjs';

const limitly = new Limitly({
  apiKey: 'lk_1234567890abcdef',
  baseUrl: 'https://api.limitly.dev',
  timeout: 30000
});

Next.js Specific Features

The Next.js SDK includes additional features optimized for Next.js applications:
  • Middleware Support: Built-in middleware for API routes
  • Server-Side Optimization: Optimized for server-side rendering
  • TypeScript Support: Full TypeScript support with proper types
  • Error Handling: Enhanced error handling for Next.js environments

Next Steps