Skip to main content
When a request fails, the API returns an error response with an HTTP status code and a JSON body describing the problem.

Error response format

Most errors return both an error field and a message field:
{
  "error": "Unauthorized",
  "message": "Invalid API key"
}
The missing q parameter error returns only the error field with no message:
{
  "error": "Missing required parameter: q"
}

Status codes

CodeErrorMessageDescription
400VariesVariesMissing or invalid parameters. Check the error field for details.
401UnauthorizedInvalid API keyMissing or invalid API key. Verify your x-api-key header.
402Insufficient CreditsYour account has insufficient credits. Please add credits to continue.Account balance depleted. Add credits to continue.
429Too Many RequestsRate limit of N requests per second exceededToo many requests. Back off and retry after the period in the Retry-After header.
500Internal server errorSomething went wrong on our end. Retry with backoff.

Handling errors

Check the HTTP status code before parsing the response body:
import requests

response = requests.get(
    "https://search-api.andisearch.com/api/v1/search",
    params={"q": "test"},
    headers={"x-api-key": "YOUR_API_KEY"}
)

if response.status_code == 200:
    data = response.json()
elif response.status_code == 429:
    retry_after = response.headers.get("Retry-After", 1)
    print(f"Rate limited. Retry after {retry_after} seconds.")
elif response.status_code == 402:
    print("Out of credits. Add credits at console.andiai.com")
else:
    error = response.json()
    print(f"Error {response.status_code}: {error['error']}")

Retry strategy

For transient errors (429, 500), use exponential backoff:
  1. Wait 1 second after the first failure
  2. Double the wait time on each subsequent retry
  3. Cap at 60 seconds
  4. Stop after 5 retries
Do not retry 400, 401, or 402 errors — these indicate problems that won’t resolve by retrying. Fix the request or account issue first.
For 429 responses, prefer the Retry-After header value over your own backoff timer if it’s present.