Axerity Platform

Errors

API error codes and handling

When an API request fails, you'll receive an error response with a status code and message.

Error Response Format

{
  "error": {
    "code": "invalid_api_key",
    "message": "The API key provided is invalid."
  }
}

HTTP Status Codes

StatusDescription
400Bad Request — Invalid parameters
401Unauthorized — Invalid or missing API key
402Payment Required — Insufficient credits
403Forbidden — Access denied
404Not Found — Resource doesn't exist
429Too Many Requests — Rate limit exceeded
500Internal Server Error — Server error
503Service Unavailable — Temporary outage

Common Error Codes

CodeDescription
invalid_api_keyThe API key is invalid or revoked
insufficient_creditsNot enough credits to complete the request
rate_limit_exceededToo many requests in a short period
invalid_modelThe specified model doesn't exist
invalid_requestThe request body is malformed
context_length_exceededMessage array exceeds model's context limit

Handling Errors

Retry with Backoff

For 429 and 5xx errors, implement exponential backoff before retrying.

async function fetchWithRetry(url: string, options: RequestInit, retries = 3) {
  for (let i = 0; i < retries; i++) {
    const response = await fetch(url, options);

    if (response.ok) return response;

    if (response.status === 429 || response.status >= 500) {
      await new Promise((r) => setTimeout(r, Math.pow(2, i) * 1000));
      continue;
    }

    throw new Error(`API Error: ${response.status}`);
  }
  throw new Error("Max retries exceeded");
}

On this page