Error Response Format
All error responses follow this structure:Operational metadata
Error details
HTTP Status Codes
The Unkey API uses these HTTP status codes:Success Codes
Request succeeded. The response includes the requested data.Note: Key verification always returns 200, even when validation fails. Check the
valid field in the response data.Client Error Codes
Request cannot be processed due to client error. This occurs when:
- Required parameters are missing
- Parameters are malformed or invalid
- Request fails validation rules
errors array with specific validation failures.Authentication failed or credentials are missing. This occurs when:
- No
Authorizationheader is provided - The provided root key is invalid, expired, or malformed
- The token format doesn’t match expected patterns
Credentials are valid but lack sufficient permissions. This occurs when:
- The root key doesn’t have required permissions for this endpoint
- The operation requires elevated privileges
- Access is restricted based on workspace settings
The requested resource doesn’t exist. This occurs when:
- The resource ID is incorrect
- The resource has been deleted
- You lack permissions to access the resource
Request conflicts with current state. This occurs when:
- Creating a resource that already exists
- Modifying a resource with stale data
- Operation violates uniqueness constraints
Request preconditions were not met. This occurs when:
- Conditional request headers don’t match
- Resource state doesn’t match expectations
Request is well-formed but semantically invalid. This occurs when:
- Business logic rules are violated
- Resource constraints prevent the operation
- Invalid state transitions
Rate limit exceeded. This occurs when:
- Too many requests in a given time period
- Workspace quota exceeded
Server Error Codes
Unexpected server error occurred. This indicates an issue on Unkey’s side.Resolution: Retry the request with exponential backoff. If the issue persists, contact support with the
requestId.Service is temporarily unavailable. This occurs during:
- Planned maintenance
- Temporary outages
- System overload
Common Error Scenarios
Validation Errors
400 Bad Request responses include detailed validation errors:- Check the
errorsarray for specific validation failures - Use the
locationfield to identify the problematic parameter - Read the
messagefor details about what’s wrong - Follow the
fixsuggestion (when provided) to resolve the issue
Permission Errors
When your root key lacks required permissions:- Verify your root key has the required permissions listed in the endpoint documentation
- Check if you’re accessing resources outside your permitted scope
- Create a new root key with appropriate permissions if needed
- Contact your workspace administrator if you need elevated access
Rate Limiting
When you exceed rate limits:- Implement exponential backoff in your retry logic
- Cache responses where appropriate to reduce request frequency
- Spread requests over time instead of bursting
- Contact support if you consistently hit limits
Error Handling Best Practices
Check Status Codes
Always check HTTP status codes before processing responses:Parse Validation Errors
For 400 responses, iterate through validation errors:Implement Retry Logic
Retry failed requests with exponential backoff:Log Request IDs
Always log request IDs for debugging:Handle Special Cases
Some endpoints have unique error behavior: Key Verification: Always returns 200, check thevalid field:
Troubleshooting Guide
Issue: Getting 401 Unauthorized
Issue: Getting 403 Forbidden
Verify root key permissions
Go to Settings > Root Keys in your dashboard and check the key’s permissions.
Issue: Getting 400 Bad Request
Issue: Getting 429 Too Many Requests
Getting Help
If you encounter persistent errors:- Check the error type URL: Visit the URL in the
typefield for detailed documentation - Review this documentation: Search for your specific error code or scenario
- Include request ID: When contacting support, always include the
requestIdfrom the error response - Join our Discord: Get help from the community and Unkey team
- Contact support: Reach out at [email protected] with:
- Request ID
- Error response
- What you were trying to accomplish
- Steps to reproduce