API Reference
Error Codes

Error Codes

Standard HTTP status codes and Xilos-specific error responses.

Error Response Format

All errors return a JSON response with the following structure:

{
  "detail": "Human-readable error message",
  "code": "XILOS_ERROR_CODE",
  "status": 400
}

HTTP Status Codes

StatusMeaningDescription
200OKRequest succeeded
201CreatedResource created successfully
400Bad RequestInvalid request body or parameters
401UnauthorizedMissing or invalid API key
403ForbiddenQuery blocked by restriction rule, or insufficient permissions
404Not FoundResource not found
429Rate LimitedRate limit or budget limit exceeded
500Internal Server ErrorUnexpected server error
502Bad GatewayUpstream LLM provider error
503Service UnavailableService temporarily unavailable

Xilos-Specific Errors

CodeStatusDescription
QUERY_BLOCKED403Query was blocked by a restriction rule
QUERY_FLAGGED200Query was processed but flagged for review
BUDGET_EXCEEDED429Virtual key budget has been exceeded
RATE_LIMIT_EXCEEDED429Rate limit for this key has been exceeded
MODEL_UNAVAILABLE502The selected LLM provider is unavailable
COMPRESSION_FAILED200Compression failed, query processed without compression
CACHE_MISS200No cache hit, query processed normally
ROUTING_FALLBACK200No routing rule matched, default model used

Handling Errors

Python

from openai import OpenAI, APIError, RateLimitError, APIStatusError
 
client = OpenAI(
    api_key="YOUR_XILOS_API_KEY",
    base_url="https://api.xilos.ai/api/v1"
)
 
try:
    response = client.chat.completions.create(
        model="xilos",
        messages=[{"role": "user", "content": "Hello"}]
    )
except RateLimitError:
    # Budget or rate limit exceeded — back off
    time.sleep(60)
except APIStatusError as e:
    if e.status_code == 403:
        # Query blocked by restriction rule
        print(f"Query blocked: {e}")
    else:
        print(f"API error: {e}")

JavaScript

try {
  const response = await client.chat.completions.create({
    model: "xilos",
    messages: [{ role: "user", content: "Hello" }],
  });
} catch (error) {
  if (error.status === 429) {
    // Rate limited — wait and retry
    await new Promise(resolve => setTimeout(resolve, 60000));
  } else if (error.status === 403) {
    // Query blocked
    console.error("Query blocked:", error.message);
  } else {
    console.error("API error:", error);
  }
}

Info: A 403 response means the query was blocked by a restriction rule — this is expected behavior, not a bug. Check your restriction rules if this happens unexpectedly.

Retry Strategy

For transient errors (429, 500, 502, 503), use exponential backoff:

  1. Wait 1 second, retry
  2. Wait 2 seconds, retry
  3. Wait 4 seconds, retry
  4. After 3 failed attempts, give up

Do not retry on 400, 401, or 403 errors — these are permanent failures.