Overview
Unkey handles the complete API key lifecycle — from creation to verification to revocation — so you can focus on building your API instead of managing authentication infrastructure.Create keys
Generate API keys programmatically via API or dashboard with custom configuration
Verify instantly
Verify keys in ~50ms globally with automatic validation of limits, expiration, and permissions
Track usage
Monitor verification patterns, track remaining credits, and analyze usage per key
Revoke immediately
Disable or delete keys with global propagation in under 60 seconds
Key Creation
Create API keys through the dashboard or API with complete control over their configuration.- TypeScript
- Python
- cURL
Key Configuration Options
Basic Settings
Basic Settings
| Field | Type | Description |
|---|---|---|
apiId | string | The API this key belongs to (required) |
name | string | Human-readable name for the key |
externalId | string | Your internal user/customer ID for linking |
meta | object | Custom JSON metadata (plan tier, feature flags, etc.) |
Expiration
Expiration
Set an expiration timestamp (Unix milliseconds) to automatically invalidate keys after a certain time.Keys return
code: "EXPIRED" after expiration. Perfect for trials, temporary access, or forced rotation.Usage Limits (Credits)
Usage Limits (Credits)
Limit total requests a key can make. Each verification decrements the counter.When exhausted, verification returns
code: "USAGE_EXCEEDED".Auto-Refill
Auto-Refill
Automatically restore credits on a schedule:Perfect for subscription models: “50,000 requests/month”.
Rate Limiting
Rate Limiting
Limit request frequency per key:Multiple limits can be applied to different operation types.
Permissions & Roles
Permissions & Roles
Attach permissions for fine-grained access control:Checked during verification to authorize specific actions.
Key Verification
Verify keys on every request to authenticate users and enforce limits.- TypeScript
- Python
- Go
Verification Response
When you verify a key, Unkey returns comprehensive information:| Field | Type | Description |
|---|---|---|
valid | boolean | Whether the key passed all checks |
code | string | Status code: VALID, NOT_FOUND, EXPIRED, DISABLED, RATE_LIMITED, USAGE_EXCEEDED, INSUFFICIENT_PERMISSIONS |
keyId | string | The key’s unique identifier |
name | string | Human-readable name of the key |
meta | object | Custom metadata attached to the key |
expires | number | Unix timestamp (ms) when the key expires |
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 |
ratelimits | object[] | Rate limit states for each configured limit |
The
credits field shows remaining credits after this verification. A value of 999 means the key can be used 999 more times.Verification Status Codes
- Success
- Not Found
- Expired
- Disabled
- Rate Limited
- Usage Exceeded
Metadata Management
Store arbitrary JSON data with each key for context and configuration.Common Use Cases
User context
Plan information
Feature flags
Resource scoping
Update Metadata
Key Revocation
Revoke access immediately when keys are compromised or users churn.- Delete (Permanent)
- Disable (Temporary)
Propagation Time
- Delete: Up to 60 seconds for global invalidation
- Disable: Up to 60 seconds for global propagation
- Re-enable: Immediate
Advanced Features
Custom cost per request
Charge different amounts per operation type:
Permission checking
Verify permissions during authentication:
Key rerolling
Generate a new key while preserving configuration:
Update credits
Manually adjust credit balance:
Best Practices
Always use HTTPS
Always use HTTPS
API keys should only be transmitted over secure connections. Never send keys in URLs or query parameters.
Store keys securely
Store keys securely
Never commit keys to version control. Use environment variables or secret management services.
Implement key rotation
Implement key rotation
Regularly rotate keys for security. Use the reroll feature to generate new keys while maintaining configuration.
Use granular permissions
Use granular permissions
Give keys only the permissions they need. Create separate keys for different services or operations.
Monitor verification patterns
Monitor verification patterns
Watch for unusual activity — sudden spikes, failed verifications, or geographic anomalies.
Handle verification failures gracefully
Handle verification failures gracefully
Always check the
code field to provide helpful error messages to users:EXPIRED: “Your API key has expired. Please generate a new one.”USAGE_EXCEEDED: “You’ve reached your request limit. Upgrade for more.”RATE_LIMITED: “Too many requests. Please slow down.”
Next Steps
Rate Limiting
Protect your API from abuse with flexible rate limiting
Identities
Group multiple keys under users or organizations
Analytics
Track usage patterns and verification trends
API Reference
Complete API documentation for all endpoints