api.*.create_key(create keys in any API)api.<api_id>.create_key(create keys in a specific API)
See the API reference for the full HTTP endpoint documentation.
Usage
Flags
The API namespace this key belongs to. Keys from different APIs cannot access each other.
Prefix prepended to the generated key string for easier recognition in logs and dashboards (e.g.,
prod_xxxxxxxxx). Must be 1-16 characters containing only letters, numbers, and underscores.Human-readable name for the key, visible only in management interfaces and API responses. Avoid generic names like “API Key” when managing multiple keys.
Cryptographic key length in bytes. The default of 16 bytes provides 2^128 possible combinations, sufficient for most applications. Minimum 16, maximum 255.
Your system’s user or entity identifier to link to this key. Returned during verification to identify the key owner without additional database lookups. Accepts letters, numbers, underscores, dots, and hyphens.
JSON object of arbitrary metadata returned during key verification. Eliminates additional database lookups during verification, improving performance for stateless services. Avoid storing sensitive data here as it is returned in verification responses.
Comma-separated list of role names to assign. Roles must already exist in your workspace. During verification, all permissions from assigned roles are checked against requested permissions.
Comma-separated list of permission names to grant directly to this key. Wildcard permissions like
documents.* grant access to all sub-permissions. Direct permissions supplement any permissions inherited from assigned roles.Unix timestamp in milliseconds when the key expires. Verification fails with
code=EXPIRED immediately after this time passes. Omit to create a permanent key that never expires.JSON object of credit and refill configuration. Controls usage-based limits through credit consumption with optional automatic refills. Unlike rate limits which control frequency, credits control total usage with global consistency.
JSON array of rate limit configurations. Defines time-based rate limits that protect against abuse by controlling request frequency. Unlike credits which track total usage, rate limits reset automatically after each window expires.
Whether the key is active for verification. When set to
false, all verification attempts fail with code=DISABLED.Whether the plaintext key is stored in an encrypted vault for later retrieval. Only enable for development keys or when key recovery is absolutely necessary.
Global Flags
| Flag | Type | Description |
|---|---|---|
--root-key | string | Override root key ($UNKEY_ROOT_KEY) |
--api-url | string | Override API base URL (default: https://api.unkey.com) |
--config | string | Path to config file (default: ~/.unkey/config.toml) |
--output | string | Output format — use json for raw JSON |
Examples
Output
Default output shows the request ID with latency, followed by the created key:--output=json, the full response envelope is returned:

