Create API key
Changed onCreate 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: Store the returned key securely. Unless you create a recoverable key, the plaintext cannot be retrieved later. Recoverable keys require key encryption and permission to decrypt them.
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)
Request
- Base URLhttps://api.unkey.com
- URLhttps://api.unkey.com/v2/keys.createKey
- AuthHTTP bearer
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. Store the key securely. The plaintext cannot be retrieved later unless the key was created as recoverable. Retrieving a recoverable key requires permission to decrypt it.
Example response
{
"meta": {
"requestId": "req_123"
},
"data": {
"keyId": "key_2cGKbMxRyIzhCxo1Idjz8q",
"key": "prod_2cGKbMxRjIzhCxo1IdjH3arELti7Sdyc8w6XYbvtcyuBowPT"
}
}Changes
- breaking
added the pattern
^[a-zA-Z0-9_:\-\.\*]+$to the request property/ - info
the
/request property's maxLength was increased from100to128 - info
removed the pattern
^[a-zA-Z][a-zA-Z0-9._-]*$from the request property
- breaking
- info
the
/request property's maxLength was increased from100to128 - info
removed the pattern
^[a-zA-Z0-9_:\-\.\*]+$from the request property/
- info