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.
--recoverable. Calls POST /v2/keys.createKey. See Creating keys.
Usage
Flags
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.
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.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.
JSON object stored on the key and returned by every verification. At most 100 top-level properties.
Comma-separated permission slugs to grant directly, at most 1000 of them. A slug that doesn’t exist yet is created.
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.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.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.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.Base URL of the API. Falls back to
UNKEY_API_BASE_URL. You don’t normally need to set it.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.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.Print the full response as JSON. Takes precedence over a valid
--output or UNKEY_OUTPUT value.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 needsunkey: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
Raw body