Error Response Format
All error responses follow this structure:object
required
Operational metadata
object
required
Error details
HTTP Status Codes
The Unkey API uses these HTTP status codes:Success Codes
status
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
status
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.status
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
status
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
status
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
status
Request conflicts with current state. This occurs when:
- Creating a resource that already exists
- Modifying a resource with stale data
- Operation violates uniqueness constraints
status
Request preconditions were not met. This occurs when:
- Conditional request headers don’t match
- Resource state doesn’t match expectations
status
Request is well-formed but semantically invalid. This occurs when:
- Business logic rules are violated
- Resource constraints prevent the operation
- Invalid state transitions
status
Rate limit exceeded. This occurs when:
- Too many requests in a given time period
- Workspace quota exceeded
Server Error Codes
status
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
1
Check Authorization header
Ensure the
Authorization header is present and properly formatted:2
Verify root key
Confirm the root key hasn’t been revoked or expired in your dashboard.
3
Check for typos
Root keys are case-sensitive. Verify you’re using the exact key value.
Issue: Getting 403 Forbidden
1
Check endpoint permissions
Review the endpoint documentation for required permissions.
2
Verify root key permissions
Go to Settings > Root Keys in your dashboard and check the key’s permissions.
3
Update permissions
Create a new root key with the required permissions if needed.
Issue: Getting 400 Bad Request
1
Check validation errors
Read the
errors array in the response for specific validation failures.2
Verify request format
Ensure your request body matches the endpoint’s schema.
3
Check required fields
Confirm all required fields are present and correctly formatted.
Issue: Getting 429 Too Many Requests
1
Implement backoff
Add exponential backoff to your retry logic.
2
Reduce request frequency
Cache responses where possible to reduce API calls.
3
Contact support
If you consistently hit limits, reach out to discuss increasing your quota.
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 support@unkey.com with:
- Request ID
- Error response
- What you were trying to accomplish
- Steps to reproduce