Skip to main content

Create role

Create a new role to group related permissions for easier management. Roles enable consistent permission assignment across multiple API keys. Permission slugs supplied in permissions are attached during creation. Missing permissions are created automatically.

Important: Role names must be unique within the workspace. Once created, roles are immediately available for assignment.

Required Permissions

Your root key must always have:

  • rbac.*.create_role

When permissions is not empty, it must also have:

  • rbac.*.add_permission_to_role

When any requested permission slug does not exist, it must also have:

  • rbac.*.create_permission
1 min read
post/v2/permissions.createRole
Request example
Response
post/v2/permissions.createRole

Authorization

Authorizationstringheaderrequired#

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. Legacy permissions use tuple strings like api.*.create_key; resource permissions use Unkey Resource Names plus actions, like unkey:v1:ws_123:keyspaces/*#create_key.
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

application/json
namestringrequired#

The unique name for this role. Must be unique within your workspace and clearly indicate the role's purpose. Use descriptive names like 'admin', 'editor', or 'Billing Manager'.

Examples: 'admin.billing', 'support.readonly', 'developer.api', 'Billing Manager'

Length: 1–128

descriptionstring#

Provides comprehensive documentation of what this role encompasses and what access it grants.
Include information about the intended use case, what permissions should be assigned, and any important considerations.
This internal documentation helps team members understand role boundaries and security implications.
Not visible to end users - designed for administration teams and access control audits.

Consider documenting:

  • The role's intended purpose and scope
  • What types of users should receive this role
  • What permissions are typically associated with it
  • Any security considerations or limitations
  • Related roles that might be used together

Length: max 512

permissionsstring[]#

Permission slugs to attach to the role. Existing permissions are reused. Missing permissions are created automatically when the root key has rbac.*.create_permission.

Omit this field or provide an empty array to create the role without permissions.

Responses

application/json
Role created successfully
metaobjectrequired#
Metadata object included in every API response. This provides context about the request and is essential for debugging, audit trails, and support inquiries. The requestId is particularly important when troubleshooting issues with the Unkey support team.
Show child attributes
requestIdstringrequired#
A unique id for this request. Always include this ID when contacting support about a specific API request. This identifier allows Unkey's support team to trace the exact request through logs and diagnostic systems to provide faster assistance.
dataobjectrequired#
Show child attributes
roleIdstringrequired#

The unique identifier assigned to the newly created role.
Use this ID to reference the role in permission assignments, key operations, and role management calls.
Always begins with 'role_' followed by a unique alphanumeric sequence.
Store this ID if you need to manage, modify, or assign this role in future operations.

Length: 3–255Pattern: ^[a-zA-Z0-9_]+$