Skip to main content
Remove roles from a key without affecting direct permissions or other roles. Use this for privilege downgrades, removing temporary access, or subscription changes that revoke specific role-based capabilities. Direct permissions remain unchanged. Important: Changes take effect immediately with up to 30-second edge propagation. Required permissions:
  • api.*.update_key (to update keys in any API)
  • api.<api_id>.update_key (to update keys in a specific API)
Side effects: Invalidates the key cache for immediate effect, and makes role changes available for verification within 30 seconds across all regions.
See the API reference for the full HTTP endpoint documentation.

Usage

unkey api keys remove-roles [flags]

Flags

--key-id
string
required
The key ID to remove roles from. This is the database identifier returned from key creation — do not confuse it with the actual API key string that users include in requests. Removing roles only affects direct assignments, not permissions inherited from other sources. Role changes take effect immediately but may take up to 30 seconds to propagate across all regions.
--roles
string[]
required
Comma-separated list of role names to remove. Operations are idempotent — removing non-assigned roles has no effect and causes no errors. After removal, the key loses access to permissions that were only granted through these roles. Invalid role references cause the entire operation to fail atomically, ensuring consistent state.

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 remove-roles --key-id=key_1234abcd --roles=api_admin,billing_reader

Output

Default output shows the request ID with latency, followed by the remaining roles assigned to the key:
req_2c9a0jf23l4k567 (took 45ms)

[
  {
    "id": "role_5678efgh",
    "name": "billing_reader"
  }
]
With --output=json, the full response envelope is returned:
{
  "meta": {
    "requestId": "req_2c9a0jf23l4k567"
  },
  "data": [
    {
      "id": "role_5678efgh",
      "name": "billing_reader"
    }
  ]
}
Last modified on March 26, 2026