Skip to main content

Overview

Complete guide to Unkey's TypeScript and JavaScript SDKs including @unkey/api, @unkey/hono, @unkey/nextjs, @unkey/cache, and @unkey/ratelimit.
2 min read

Unkey provides two TypeScript packages:

  • @unkey/api: Manage keys, APIs, and rate limits (server-side, requires root key)
  • @unkey/ratelimit: Standalone rate limiting (server-side, requires root key)

For framework-specific wrappers, see @unkey/nextjs and @unkey/hono.

Installation#

Quick Start#

Initialize the client#

Warning

Never expose your root key in client-side code. These SDKs are for server-side use only.


Verify an API Key#

The most common operation, check if a user's API key is valid:

Verification response#

FieldTypeDescription
validbooleanWhether the key passed all checks
codestringStatus code (VALID, NOT_FOUND, RATE_LIMITED, etc.)
keyIdstringThe key's unique identifier
namestring?Human-readable name of the key
metaobject?Custom metadata associated with the key
expiresnumber?Unix timestamp (in milliseconds) when the key will expire (if set)
creditsnumber?Remaining uses (if usage limits set)
enabledbooleanWhether the key is enabled
rolesstring[]?Roles attached to the key
permissionsstring[]?Permissions attached to the key
identityobject?Identity info if externalId was set when creating the key
ratelimitsobject[]?Rate limit states (if rate limiting configured)

Check permissions during verification#


Create API Keys#

Issue new keys for your users:

Warning

The full API key is only returned once at creation. Unkey stores only a hash. Make sure to display it to your user immediately.


Update Keys#

Modify an existing key's configuration:


Delete Keys#

Permanently revoke a key:

Or disable temporarily (can re-enable later):


Rate Limiting#

Use @unkey/ratelimit for standalone rate limiting:

Cost-based rate limiting#

Expensive operations can consume more of the limit:


Error Handling#

Use try/catch to handle errors:

Resilient verification#

For production, handle edge cases:


TypeScript Types#

The SDK is fully typed. Import types as needed:


Framework Guides#


Full Reference#

GitHub

Complete auto-generated API reference