API Reference
Next.js helpers for @g14o/ratelimit.
Next.js types
@g14o/ratelimit-nextjs binds @g14o/ratelimit to Next.js NextRequest / NextResponse.
| Symbol | Description |
|---|---|
createRateLimit(options) | Factory returning a client typed for NextRequest / NextResponse. |
RateLimitClient | Alias of RateLimitClient<NextRequest, NextResponse> from core. |
RateLimitOptions | Per-call options. identifierFn and skipRateLimit (boolean or callback) receive NextRequest. Global skipRateLimit on CreateRateLimitOptions is boolean-only. |
CreateRateLimitOptions
| Option | Type | Description |
|---|---|---|
env? | | Environment name override. When omitted, falls back to Values |
inMemoryDuringBuild? | | When true |
hooks? | | Optional lifecycle hooks for observability and side effects. Hooks are awaited; hook errors are logged and swallowed so they never affect rate limiting or fail-open behavior. |
logger? | | Application logger. Defaults to a silent no-op logger. |
skipRateLimit? | | When |
tiers? | | Override built-in tier limits/windows/prefixes. Each tier key is optional; each field inside a tier is optional and merged onto factory defaults. |
redis? | | Legacy Upstash credentials or client. Mutually exclusive with |
store? | | Explicit store implementation (preferred). |
RateLimitClient
| Prop | Type | Description |
|---|---|---|
checkRateLimit | | Checks the rate limit for a request without wrapping a handler. Fails open on internal errors (returns |
getRateLimiter | | Returns a cached rate limiter adapter for a tier. |
reset | | Clears in-memory limiter state and the adapter cache. Useful in tests; does not reset Upstash Redis counters. |
withRateLimit | | Wraps an async handler with rate limiting. Returns |
withUserRateLimit | | Wraps a handler with per-user rate limiting. Uses |
RateLimitOptions
| Option | Type | Description |
|---|---|---|
identifierFn? | | Function to get the identifier for the request. Defaults to the IP address of the request. |
prefix? | | Key prefix override for this call. Defaults to the tier prefix. |
skipRateLimit? | | Skip rate limit for this request. |
tier? | | Rate limit tier to use. Defaults to "moderate". |