Skip to main content

Error Handling

Handle Unkey API errors with structured error codes, HTTP status codes, and actionable messages. Includes retry strategies and examples.
2 min read

Error responses maintain the same top-level structure as successful responses, but with an error object instead of data:

Error Format#

Our error format follows RFC7807 Problem Details standard within our consistent envelope structure, providing:

  • title: A short, human-readable summary of the problem
  • detail: A human-readable explanation specific to this occurrence
  • status: The HTTP status code (also returned in the HTTP response)
  • type: A URI reference that identifies the problem type and points to documentation
  • errors: (Optional) An array of specific validation errors when multiple issues occur

Common Error Types#

StatusError TypeDescription
400validation-errorThe request body failed validation
401unauthorizedMissing or invalid authorization
403forbiddenValid authorization but insufficient permissions
404not-foundThe requested resource was not found
409conflictThe request conflicts with the current state
429rate-limitedYou've exceeded your rate limit
500internal-server-errorAn unexpected error occurred on our servers

Validation Errors#

For validation errors, we provide detailed information about each failed validation:

  • location: Where in the request the error occurred (e.g., body.name, query.limit)
  • message: What went wrong with the specific field
  • fix: (When possible) A suggestion for how to fix the issue

Error Recovery#

Our error messages are designed to be actionable. Each error includes:

  1. A clear explanation of what went wrong
  2. Often, a suggestion for how to fix the issue
  3. For validation errors, the specific fields that failed validation

Using the Request ID for Support#

When reporting issues to our support team, always include the requestId from the error response. This unique identifier allows us to quickly locate the specific request in our logs and provide faster, more accurate assistance.

Error Handling Best Practices#

  1. Check for Status Codes: Always check HTTP status codes first to determine broad error categories
  2. Extract Error Details: Parse the error object for detailed information
  3. Implement Retries Carefully: Only retry on 5xx errors or when explicitly advised
  4. Log Complete Errors: Log the full error response for debugging purposes

Example error handling in JavaScript: