Generate a new API key while preserving the configuration from an existing key.
This operation creates a fresh key with a new token while maintaining all settings from the original key:
Key Generation:
Original Key Handling:
expirationexpiration to 0 to revoke immediatelyCommon use cases include:
Important: Analytics and usage metrics are tracked at both the key level AND identity level. If the original key has an identity, the new key will inherit it, allowing you to track usage across both individual keys and the overall identity.
Required Permissions
Your root key must have:
api.*.create_key or api.<api_id>.create_keyapi.*.encrypt_key or api.<api_id>.encrypt_key (only when the original key is recoverable)Unkey uses API keys (root keys) for authentication. These keys authorize access to management operations in the API. To authenticate, include your root key in the Authorization header of each request:
Authorization: Bearer unkey_123Root keys have specific permissions attached to them, controlling what operations they can perform. Key permissions follow a hierarchical structure with patterns like resource.resource_id.action (e.g., apis.*.create_key, apis.*.read_api).
Security best practices:
The database identifier of the key to reroll.
This is the unique ID returned when creating or listing keys, NOT the actual API key token. You can find this ID in:
keys.createKey3 - 255"key_2cGKbMxRyIzhCxo1Idjz8q"
Duration in milliseconds until the ORIGINAL key is revoked, starting from now.
This parameter controls the overlap period for key rotation:
0 to revoke the original key immediatelyCommon overlap periods:
0 <= x <= 410244480000086400000
Key rerolled successfully.