When to use API keys
API keys work best when you need:- Machine-to-machine authentication — Backend services, scripts, or integrations calling your API
- Usage tracking per customer — Know who’s making requests and how many
- Simple integration — A single header (
Authorization: Bearer sk_...) that developers understand - Granular control — Per-key rate limits, expiration, and permissions
For user-facing authentication (login flows, sessions), you’ll typically use OAuth, JWTs, or an auth provider like Clerk or Auth0 alongside Unkey. Unkey handles the API key layer, not user sessions.
How it works
Create an API in Unkey
An “API” in Unkey is a container for keys. You might have separate APIs for “Production” and “Staging”, or for different products.
Issue keys to users
When a user signs up or requests API access, create a key for them. You can attach metadata (user ID, plan tier), set limits, and configure expiration.
Verify on every request
When a request hits your API, extract the key from the header and verify it with Unkey. We’ll tell you if it’s valid, who it belongs to, and how many requests they have left.
Quick example
Here’s what verification looks like in practice:What you get with each verification
When you verify a key, Unkey returns:| 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[]? | Permissions 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) |
Features
Unkey keys support much more than basic authentication:Rate limiting
Limit requests per key — per second, minute, hour, or any window.
Usage limits
Cap total requests per key. Perfect for API credits or trial limits.
Auto-refill
Automatically restore usage limits on a schedule (daily, monthly, etc).
Expiration
Create keys that automatically expire after a set time.
Permissions
Attach roles and permissions for fine-grained access control.
Analytics
See usage patterns, top consumers, and verification trends.

