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

Your root key must have one of the following 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.

Request

keyId
string
required
Specifies which key loses the roles using the database identifier returned from createKey.Do not confuse this 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.Pattern: ^[a-zA-Z0-9_]+$Example: key_2cGKbMxRyIzhCxo1Idjz8q
roles
array
required
Removes direct role assignments from the key without affecting other role sources or permissions.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.Pattern: ^[a-zA-Z0-9_:\-\.\*]+$Min items: 1Max items: 100Example: ["editor", "admin"]

Response

roles
array
required
Complete list of all roles remaining after the removal.This only shows direct role assignments.

Examples

curl -X POST https://api.unkey.com/v2/keys.removeRoles \
  -H "Authorization: Bearer <UNKEY_ROOT_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "keyId": "key_1234abcd",
    "roles": ["editor", "admin"]
  }'

Response Example

{
  "meta": {
    "requestId": "req_abc123def456"
  },
  "data": [
    {
      "id": "role_123",
      "name": "viewer"
    }
  ]
}

Build docs developers (and LLMs) love