keys
Create API key
Create a new API key for user authentication and authorization.
Use this endpoint when users sign up, upgrade subscription tiers, or need additional keys. Keys are cryptographically secure and unique to the specified API namespace.
Important: The key is returned only once. Store it immediately and provide it to your user, as it cannot be retrieved later.
Common use cases:
- Generate keys for new user registrations
- Create additional keys for different applications
- Issue keys with specific permissions or limits
Required Permissions
Your credential needs one of:
- api.*.create_key (create keys in any API)
- api.<api_id>.create_key (create keys in specific API)
- unkey:v1:<workspace_id>:keyspaces/*#create_key (create keys in any keyspace)
- unkey:v1:<workspace_id>:keyspaces/<keyspace_id>#create_key (create keys in a specific keyspace)
post/v2/keys.createKey
Request body
Example request
{
"apiId": "api_1234abcd",
"prefix": "prod",
"name": "Payment Service Production Key",
"byteLength": 24,
"externalId": "user_1234abcd",
"meta": {
"plan": "enterprise",
"featureFlags": {
"betaAccess": true,
"concurrentConnections": 10
},
"customerName": "Acme Corp",
"billing": {
"tier": "premium",
"renewal": "2024-12-31"
}
},
"roles": [
"api_admin",
"billing_reader"
],
"permissions": [
"documents.read",
"documents.write",
"settings.view"
],
"expires": 1704067200000,
"credits": {
"remaining": 1000,
"refill": {
"interval": "daily",
"amount": 1000,
"refillDay": 15
}
},
"ratelimits": [
{
"name": "requests",
"limit": 100,
"duration": 60000,
"autoApply": true
},
{
"name": "heavy_operations",
"limit": 10,
"duration": 3600000,
"autoApply": false
}
],
"enabled": true
}Response
Successfully created a new API key. The response includes both the keyId (for reference in your system) and the full key string. IMPORTANT: This is the only time the complete key is available - it cannot be retrieved later. You must securely provide this key to your end user immediately.
Example response
{
"meta": {
"requestId": "req_123"
},
"data": {
"keyId": "key_2cGKbMxRyIzhCxo1Idjz8q",
"key": "prod_2cGKbMxRjIzhCxo1IdjH3arELti7Sdyc8w6XYbvtcyuBowPT"
}
}