Skip to content

Error Handling

Error Handling

Error formats, status codes, and how to handle failures.

Error Response Format

All errors follow a consistent JSON format:

json
{
  "success": false,
  "error": "Human-readable error message"
}

Queue Task Errors

When a queued task fails, the error is available in the status and result responses:

json
{
  "success": true,
  "data": {
    "queueId": "abc123-def456",
    "status": "error",
    "error": {
      "message": "Model rate limit exceeded",
      "code": "RATE_LIMIT"
    }
  }
}

HTTP Status Codes

CodeMeaningWhen
200OKRequest succeeded
202AcceptedTask still processing (poll again)
400Bad RequestInvalid request body or parameters
401UnauthorizedMissing or invalid API key
403ForbiddenInsufficient permissions
404Not FoundQueue task or resource not found
429Too Many RequestsRate limit exceeded
500Internal ErrorServer or provider error

Rate Limiting

When rate limits are exceeded, the API returns a 429 response:

json
{
  "success": false,
  "error": "Rate limit exceeded. Try again in 45 seconds."
}

Check the Retry-After header for the number of seconds to wait before retrying.

Handling 202 (Still Processing)

When polling /queue/result and the task isn't done yet:

json
// HTTP 202
{
  "success": false,
  "error": "Task still processing",
  "data": {
    "status": "processing",
    "position": 0
  }
}

Simply retry after a short delay (e.g. 500ms-2s). Use position to estimate wait time.

Finish Reasons

The finishReason field in completion results indicates why the model stopped:

ReasonDescription
stopModel completed naturally or hit a stop sequence
lengthOutput hit maxTokens limit — response may be truncated
content_filterContent was filtered by the provider's safety system
errorAn error occurred during generation

Best Practices

  • Always check success in the response body
  • Implement exponential backoff for 429 and 500 errors
  • Use the Retry-After header when available
  • Check finishReason for length to detect truncated responses
  • Use /queue/status to check task state before polling results