Skip to main content
Create a root key with the permissions listed on this page under Root Keys in the dashboard sidebar. CLI commands can instead use a session from unkey login with the required permissions. See Permission reference for every permission.
Create a key. The plaintext comes back once in this response. You can’t fetch it again unless you pass --recoverable. Calls POST /v2/keys.createKey. See Creating keys.

Usage

Flags

string
required
Id of the API (keyspace) the key belongs to.
integer
Length of the random part of the key in bytes. The API accepts 16 to 255. If you leave the flag off, it uses the keyspace’s default byte length, or 16 if the keyspace doesn’t set one.
string
JSON object with remaining and an optional refill of interval (daily or monthly), amount, and refillDay. refillDay is a day of the month from 1 to 31. It’s required for monthly, and a monthly refill without it fails with 400. It’s ignored for daily.
boolean
default:"true"
Whether the key can be used. Create it disabled to turn it on later.
integer
Unix timestamp in milliseconds after which the key stops verifying.
string
Your identifier for the user or tenant, up to 255 characters. Links the key to the identity with this external id, and creates the identity if needed.
string
JSON object stored on the key and returned by every verification. At most 100 top-level properties.
string
Name shown in the dashboard, up to 255 characters.
string[]
Comma-separated permission slugs to grant directly, at most 1000 of them. A slug that doesn’t exist yet is created.
string
Prefix added to the start of the key so users can tell keys apart, for example prod. Up to 16 characters of letters, digits, and underscores. If you leave it off, the keyspace’s default prefix is used, if it has one.
string
JSON array of rate limits, each with name, limit, duration in milliseconds, and autoApply.
boolean
default:"false"
Store the plaintext encrypted so unkey keys get --decrypt can return it later. Uses the same write permission as a non-recoverable key. Fails with 412 unless the keyspace has key encryption turned on, which only we can do, through a support request.
string[]
Comma-separated role names to assign, at most 100 of them. Unlike permissions, each role must already exist. An unknown name fails the whole call.

Shared flags

Every resource command takes these. See CLI output and shared flags.
string
Root key used for the request. Falls back to UNKEY_ROOT_KEY, then stored credentials, including a CLI session. See CLI authentication for the full precedence order.
string
default:"https://api.unkey.com"
Base URL of the API. Falls back to UNKEY_API_BASE_URL. You don’t normally need to set it.
string
default:"~/.unkey/config.toml"
Path of the TOML config file. Falls back to UNKEY_CONFIG. An explicit --config takes precedence over a stored CLI session. Browser login stores a session, not a root key in this file. See CLI authentication.
enum
default:"human"
Use human (default) for name-first summary tables and single-response trees, or json for the unchanged full response envelope, including all fields and pagination. Trees wrap long values without truncation. Terminal tables use relative timestamps and may shorten display names and descriptions, but never identifiers, slugs, or credentials. Redirected human output keeps complete values and uses RFC3339 UTC timestamps. Falls back to UNKEY_OUTPUT; other values are rejected. --json also selects JSON output. Add --debug to print the request ID to stderr. See Output formats.
boolean
Print the successful response’s request ID to stderr, separate from stdout.
boolean
Print the full response as JSON. Takes precedence over a valid --output or UNKEY_OUTPUT value.
string
Send this JSON as the whole request body instead of using the command’s flags. You can’t combine it with them.

Required permissions

The root key needs unkey:v1:<workspace_id>:projects/<project_id>/keyspaces/<keyspace_id>/keys/*#write for the target keyspace. Use the keyspace’s project ID. --recoverable uses the same write permission and requires the keyspace to support key encryption. Without write permission, you get a 404, so the response doesn’t reveal whether the API exists. If your key can read the API’s keyspace, you get a 403 that names the missing write permission instead. See Root key permissions.

Examples

Plain key
Key for a user with roles
Key with credits and a rate limit
Or send the whole request as JSON:
Raw body
Last modified on November 11, 2026