github.com/unkeyed/sdks/tree/main/nextjs
Install
withUnkey handler:
What’s in req.unkey?
The req.unkey.data object contains the verification result:
| Field | Type | Description |
|---|---|---|
valid | boolean | Whether the key passed all checks |
code | string | Status code (VALID, NOT_FOUND, RATE_LIMITED, etc.) |
keyId | string | The key’s unique identifier |
name | string? | Human-readable name of the key |
meta | object? | Custom metadata associated with the key |
expires | number? | Unix timestamp (in milliseconds) when the key will expire (if set) |
credits | number? | Remaining uses (if usage limits set) |
enabled | boolean | Whether the key is enabled |
roles | string[]? | Roles attached to the key |
permissions | string[]? | Permissions attached to the key |
identity | object? | Identity info if externalId was set when creating the key |
ratelimits | object[]? | Rate limit states (if rate limiting configured) |
Access these via
req.unkey.data.valid, req.unkey.data.keyId, etc.withUnkey processes incoming requests, you can do so as follows:
getKey
By default, withUnkey will look for a bearer token located in the authorization header. If you want to customize this, you can do so by passing a getter
in the configuration object:
onError
You can specify custom error handling. By default errors will be logged to the console, and withUnkey will return a NextResponse with status 500.

