Skip to main content
Unkey provides official SDKs for the most popular programming languages, making it easy to integrate API key management, verification, and rate limiting into your applications.

Available SDKs

TypeScript/JavaScript

Full-featured SDK for Node.js, Deno, Bun, and Cloudflare Workers

Go

Native Go SDK with middleware for popular frameworks

Python

Python SDK with FastAPI, Flask, and Django support

Core Capabilities

All official SDKs provide:

API Key Verification

Validate API keys on every request with built-in support for:
  • Expiration checking
  • Usage limits and credits
  • Rate limiting
  • Permissions and roles
  • Custom metadata

Key Management

Create, update, and revoke API keys programmatically:
  • Generate keys with custom prefixes
  • Set expiration dates
  • Configure usage limits and auto-refill
  • Attach metadata and permissions

Rate Limiting

Protect your APIs from abuse:
  • Flexible time windows (seconds, minutes, hours, days)
  • Cost-based limiting for expensive operations
  • Per-user or per-key limits
  • Multiple concurrent rate limits

Quick Start

Installation

npm install @unkey/api

Initialize the Client

import { Unkey } from "@unkey/api";

const unkey = new Unkey({
  rootKey: process.env.UNKEY_ROOT_KEY!,
});
Never expose your root key in client-side code or commit it to version control. These SDKs are designed for server-side use only.

Verify an API Key

const { data } = await unkey.keys.verifyKey({
  key: "sk_live_...",
});

if (!data.valid) {
  console.log(`Key invalid: ${data.code}`);
  return;
}

console.log("Key is valid!");
console.log(`Key ID: ${data.keyId}`);

Create an API Key

const { data } = await unkey.keys.create({
  apiId: "api_...",
  prefix: "sk_live",
  externalId: "user_123",
  remaining: 1000,
  meta: {
    plan: "pro",
  },
});

console.log("New key:", data.key);
console.log("Key ID:", data.keyId);
The full API key is only returned once at creation. Unkey stores only a cryptographic hash. Make sure to display it to your user immediately or store it securely.

Common Operations

Rate Limiting

Protect your endpoints from abuse:
import { Ratelimit } from "@unkey/ratelimit";

const limiter = new Ratelimit({
  rootKey: process.env.UNKEY_ROOT_KEY!,
  namespace: "my-app",
  limit: 100,
  duration: "60s",
});

const { success, remaining, reset } = await limiter.limit("user_123");

if (!success) {
  console.log(`Rate limited. Reset at: ${reset}`);
}

Update a Key

await unkey.keys.update({
  keyId: "key_...",
  name: "Updated name",
  enabled: true,
  meta: { plan: "enterprise" },
});

Delete a Key

await unkey.keys.delete({
  keyId: "key_...",
});

Framework-Specific Guides

TypeScript/JavaScript

Next.js

withUnkey wrapper for API routes

Hono

Middleware for Hono apps

Express

Express.js integration guide

Bun

Fast verification with Bun runtime

Go

See the Go SDK documentation for middleware examples with:
  • net/http (standard library)
  • Gin
  • Echo
  • Fiber

Python

See the Python SDK documentation for integration examples with:
  • FastAPI
  • Flask
  • Django

Error Handling

All SDKs use language-idiomatic error handling:
try {
  const { data } = await unkey.keys.create({
    apiId: "api_...",
  });
  
  console.log("Created:", data.key);
} catch (err) {
  console.error("API Error:", err);
  // Handle error
}

Runtime Support

TypeScript/JavaScript

  • Node.js 18+
  • Deno 1.25+
  • Bun 1.0+
  • Cloudflare Workers
  • Edge runtimes (Vercel, Netlify)

Go

  • Go 1.21 or higher

Python

  • Python 3.9 or higher

Community SDKs

The community has built SDKs for additional languages:

Rust

Community-maintained Rust SDK

PHP

Community-maintained PHP SDK

Java

Community-maintained Java SDK

.NET

Community-maintained .NET SDK
Community SDKs are maintained by the community and may have different features or update schedules than official SDKs.

Next Steps

TypeScript SDK

Full TypeScript/JavaScript SDK reference

Go SDK

Complete Go SDK documentation

Python SDK

Complete Python SDK documentation

API Reference

REST API documentation

Build docs developers (and LLMs) love