Set key roles
Changed onReplace all roles on a key with the specified set in a single atomic operation.
Use this to synchronize with external systems, reset roles to a known state, or apply standardized role templates. Direct permissions are never affected.
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
- Base URLhttps://api.unkey.com
- URLhttps://api.unkey.com/v2/keys.setRoles
- AuthHTTP bearer
Request body
Example request
{
"keyId": "key_2cGKbMxRyIzhCxo1Idjz8q"
}Response
Roles set successfully. Returns all roles currently assigned to the key.
Example response
{
"meta": {
"requestId": "req_123"
},
"data": [
{
"id": "role_1234567890abcdef",
"name": "support.readonly",
"description": "Provides read-only access for customer support representatives to view user accounts and support tickets",
"permissions": [
{
"id": "perm_1234567890abcdef",
"name": "users.read",
"slug": "users-read",
"description": "Allows reading user profile information and account details"
}
]
}
]
}Changes
- breaking
the
/request property's maxLength was decreased to128 - info
the
/request property's minLength was decreased from3to1 - info
removed the pattern
^[a-zA-Z0-9_:\-\.\*]+$from the request property/
- breaking
- info
the endpoint scheme security
dashboardwas removed from the API - info
the endpoint scheme security
rootKeywas removed from the API
- info