Root Keys
Root keys are API credentials that authenticate your requests to the Unkey API. Unlike the API keys you create for your end users, root keys are used to manage your Unkey workspace programmatically.Creating a Root Key
Create root keys from your Unkey dashboard:- Navigate to Settings > Root Keys
- Click Create New Root Key
- Configure permissions for the key
- Copy and securely store the key - it won’t be shown again
Authentication Format
Include your root key in theAuthorization header of each request using the Bearer authentication scheme:
Example Request
Permissions
Root keys have specific permissions attached to them, controlling what operations they can perform. Permissions follow a hierarchical structure:Permission Patterns
The resource type (e.g.,
api, key, identity)Specific resource ID or
* for all resources of this typeThe action to perform (e.g.,
create_key, read_api, verify_key)Common Permission Examples
api.*.create_key- Create keys in any APIapi.api_123.create_key- Create keys only in API with IDapi_123api.*.verify_key- Verify keys in any APIapi.*.read_api- Read information about any API
Security Best Practices
Follow these guidelines to keep your root keys secure:Store Keys Securely
- Use environment variables or secure secret management services
- Never hardcode keys in source code
- Never commit keys to version control
- Never expose keys in client-side code or public repositories
Use Minimal Permissions
Create root keys with only the permissions needed for their specific use case:Rotate Keys Regularly
Establish a key rotation schedule:- Rotate keys after team member departures
- Rotate keys if you suspect compromise
- Consider periodic rotation (e.g., every 90 days)
- Create new keys before revoking old ones to avoid downtime
Use Different Keys per Environment
Create separate root keys for each environment:- Development environment: Limited permissions for testing
- Staging environment: Production-like permissions
- Production environment: Minimal required permissions
Monitor Key Usage
Track root key activity through audit logs:- Review logs regularly for unexpected activity
- Set up alerts for unusual patterns
- Monitor failed authentication attempts
- Track permission-denied events
Authentication Errors
When authentication fails, you’ll receive specific error responses:401 Unauthorized
Returned when authentication credentials are missing or invalid:- No
Authorizationheader provided - Invalid root key format
- Expired or revoked root key
- Malformed Bearer token
403 Forbidden
Returned when credentials are valid but lack sufficient permissions:- Root key lacks required permissions
- Attempting to access resources outside permitted scope
- Workspace-level restrictions