Skip to main content
The official Unkey TypeScript/JavaScript SDK provides two packages for managing API keys and rate limiting in your applications.

Packages

  • @unkey/api — Manage keys, APIs, and rate limits (requires root key)
  • @unkey/ratelimit — Standalone rate limiting (requires root key)
For framework-specific wrappers, see @unkey/nextjs and @unkey/hono.

Installation

Both packages support CommonJS and ES Modules. Compatible with Node.js 18+, Deno 1.25+, Bun 1.0+, Cloudflare Workers, and edge runtimes.

Initialization

Initialize the API client

Initialize the rate limiter

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

Verify API Keys

The most common operation — validate a user’s API key:

Verification Response

The data object contains:

Verify with Permission Check


Create API Keys

Issue new keys for your users:
The full API key is only returned once at creation. Unkey stores only a cryptographic hash.

Create Key with Permissions


Update Keys

Modify an existing key’s configuration:

Delete Keys

Permanently revoke a key:
Or disable temporarily (can re-enable later):

Rate Limiting

Using @unkey/ratelimit

Standalone rate limiting without API keys:

Cost-Based Rate Limiting

Expensive operations can consume more of the limit:

Duration Options

Rate Limit Response


Error Handling

Use try/catch for error handling:

Production-Ready Verification


TypeScript Types

The SDK is fully typed. Import types as needed:

Framework Integration

Next.js

Use the @unkey/nextjs wrapper:

Hono

Use the @unkey/hono middleware:

Express

Cloudflare Workers


Advanced Usage

Managing APIs

Create and manage API namespaces:

Identity Management

Link keys to your users:

Custom Caching

Reduce latency with caching:

Complete Examples

E-commerce API with Usage Limits


GitHub Repository

@unkey/api on GitHub

Complete auto-generated API reference and source code

Next Steps

Next.js SDK

Framework wrapper for Next.js

Hono SDK

Middleware for Hono apps

Rate Limiting Guide

Advanced rate limiting features

API Reference

REST API documentation