Skip to main content
Migrate pre-hashed API keys from an existing provider into Unkey. Use this to move keys from another system without requiring users to rotate their credentials. You provide the already-hashed keys and Unkey stores them directly, so existing API keys continue to work after migration. The endpoint returns HTTP 200 even on partial success; hashes that could not be migrated are listed in the response. Important: You must obtain a migrationId from Unkey support before using this command. Keys that already exist in the system will appear in the failed array rather than causing the entire request to fail. Required permissions: Your root key must have one of the following permissions:
  • api.*.create_key (to migrate keys to any API)
  • api.<api_id>.create_key (to migrate keys to a specific API)
See the API reference for the full HTTP endpoint documentation.

Usage

unkey api keys migrate-keys [flags]

Flags

--migration-id
string
required
Identifier of the configured migration provider/strategy to use (e.g., “your_company”). You will receive this from Unkey’s support staff. Must be 3-255 characters.
--api-id
string
required
The ID of the API that the keys should be inserted into. Must be 3-255 characters.
--keys-json
string
required
JSON array of key migration objects. Each object describes a single key to migrate.

Global Flags

FlagTypeDescription
--root-keystringOverride root key ($UNKEY_ROOT_KEY)
--api-urlstringOverride API base URL (default: https://api.unkey.com)
--configstringPath to config file (default: ~/.unkey/config.toml)
--outputstringOutput format — use json for raw JSON

Examples

unkey api keys migrate-keys \
  --migration-id=your_company \
  --api-id=api_123456789 \
  --keys-json='[{"hash":"c4fbfe7c69a067cb0841dea343346a750a69908a08ea9656d2a8c19fb0823c64","enabled":true}]'

Output

Default output shows the request ID with latency, followed by the migration results:
req_2c9a0jf23l4k567 (took 120ms)

{
  "migrated": [
    {
      "hash": "c4fbfe7c69a067cb0841dea343346a750a69908a08ea9656d2a8c19fb0823c64",
      "keyId": "key_2cGKbMxRyIzhCxo1Idjz8q"
    }
  ],
  "failed": []
}
With --output=json, the full response envelope is returned:
{
  "meta": {
    "requestId": "req_2c9a0jf23l4k567"
  },
  "data": {
    "migrated": [
      {
        "hash": "c4fbfe7c69a067cb0841dea343346a750a69908a08ea9656d2a8c19fb0823c64",
        "keyId": "key_2cGKbMxRyIzhCxo1Idjz8q"
      }
    ],
    "failed": []
  }
}
Last modified on March 26, 2026