Set key permissions
Replace all permissions on a key with the specified set in a single atomic operation.
Use this to synchronize with external systems, reset permissions to a known state, or apply standardized permission templates. Permissions granted through roles remain unchanged.
Important: Changes take effect immediately with up to 30-second edge propagation.
Required Permissions
Your root key must have write on the target key:
unkey:v1:{workspace_id}:projects/{project_id}/keyspaces/{keyspace_id}/keys/{key_id}#write
When any requested permission slug does not exist in the key’s project, your root key must also have:
unkey:v1:{workspace_id}:projects/{project_id}/rbac/permissions/*#write
Use the keyspace ID, not the API ID. You can use wildcard resource IDs to grant access to multiple resources.
Side Effects
Invalidates the key cache for immediate effect, and makes permission changes available for verification within 30 seconds across all regions.
Authorizations
Unkey uses bearer tokens for authentication. Public integrations use root keys, while the dashboard proxy uses short-lived JWTs. To authenticate, include the token in the Authorization header of each request:
Root keys have specific permissions attached to them, controlling what operations they can perform. Resource permissions use Unkey Resource Names plus actions, like unkey:v1:ws_123:projects/*/keyspaces/*/keys/*#write.
Security best practices:
- Keep root keys secure and never expose them in client-side code
- Use different root keys for different environments
- Rotate keys periodically, especially after team member departures
- Create keys with minimal necessary permissions following least privilege principle
- Monitor key usage with audit logs.
Body
Specifies which key receives the additional permissions using the database identifier returned from keys.createKey.
Do not confuse this with the actual API key string that users include in requests.
3 - 255^[a-zA-Z0-9_]+$"key_2cGKbMxRyIzhCxo1Idjz8q"
The permissions to set for this key.
This is a complete replacement operation - it overwrites all existing direct permissions with this new set.
Key behaviors:
- Providing an empty array removes all direct permissions from the key
- This only affects direct permissions - permissions granted through roles are not affected
- All existing direct permissions not included in this list will be removed
To create missing permission slugs in the key's project, your root key must also have unkey:v1:{workspace_id}:projects/{project_id}/rbac/permissions/*#write. Without this grant, the operation returns HTTP 403. Setting existing permissions does not require this additional grant.
Specify the permission by its slug.
1 - 128^[a-zA-Z0-9_:\-\.\*]+$Response
Permissions set successfully. Returns all permissions currently assigned to the key.
Complete list of all permissions now directly assigned to the key after the set operation has completed.
The response includes:
- The comprehensive, updated set of direct permissions (reflecting the complete replacement)
- Both ID and name for each permission for easy reference
Important notes:
- This only shows direct permissions, not those granted through roles
- An empty array means the key has no direct permissions assigned
- For a complete permission picture including roles, use keys.getKey instead