Skip to content

Error Handling ​

All API errors are returned as JSON with a consistent structure.

Error Response Format ​

json
{
  "error": "error_type",
  "message": "Human-readable description of what went wrong",
  "requestId": "req_01H..."
}

Some endpoints include additional detail:

json
{
  "error": "Invalid prompt data",
  "details": [
    { "path": ["temperature"], "message": "Number must be less than or equal to 2" }
  ]
}

HTTP Status Codes ​

StatusMeaningWhen It Occurs
400Bad RequestInvalid payload, missing required fields, validation failure
401UnauthorizedMissing or invalid API key, expired session
403ForbiddenKey scope insufficient (e.g., read-only key attempting write)
404Not FoundResource does not exist or is not accessible
405Method Not AllowedHTTP method not supported on this endpoint
409ConflictDuplicate resource (e.g., prompt with identical content hash)
429Too Many RequestsRate limit exceeded - see Rate Limits
500Internal Server ErrorUnexpected server error - retry with backoff

Validation Errors (400) ​

When creating or updating resources, validation rules apply:

Prompt Validation ​

FieldRule
nameRequired, 1-100 characters
userPromptRequired, minimum 1 character
temperatureOptional, range 0.0 - 2.0 (default: 0.7)
maxTokensOptional, range 1 - 8000 (default: 1000)
visibilityOptional, one of: PRIVATE, SHARED, PUBLIC

Webhook Validation ​

FieldRule
nameRequired
urlRequired, must be a valid HTTPS URL
eventsRequired, array of event type strings
secretOptional, minimum 16 characters if provided

Retry Strategy ​

javascript
async function apiCallWithRetry(fn, maxRetries = 3) {
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
    const response = await fn();

    if (response.ok) return response;

    // Don't retry client errors (except 429)
    if (response.status >= 400 && response.status < 500 && response.status !== 429) {
      throw new Error(`Client error: ${response.status}`);
    }

    // Retry 429 and 5xx with exponential backoff
    if (attempt < maxRetries) {
      const retryAfter = response.headers.get('Retry-After');
      const delay = retryAfter
        ? parseInt(retryAfter) * 1000
        : Math.min(1000 * Math.pow(2, attempt), 30000);
      await new Promise(r => setTimeout(r, delay));
    }
  }
  throw new Error('Max retries exceeded');
}

Troubleshooting Tips ​

  • Always log the requestId from error responses for support inquiries.
  • For 401 errors, verify your API key is correctly formatted with the Bearer prefix.
  • For 500 errors, retry with exponential backoff. If persistent, check the Status Page.
  • For validation errors, check the details array for field-specific messages.