Documentation

Error Codes

The Fikra API uses conventional HTTP response codes to indicate the success or failure of an API request. In general, codes in the 2xx range indicate success, codes in the 4xx range indicate an error that failed given the information provided (e.g., a required parameter was omitted), and codes in the 5xx range indicate an error with our servers.

Standard HTTP Status Codes

Error Payload Structure

When an error occurs, the Fikra API returns a standard OpenAI-compatible JSON payload so your existing parsers won't break:

{
  "error": {
    "message": "Insufficient balance. Please top up your Fikra account.",
    "type": "insufficient_quota",
    "param": null,
    "code": 402
  }
}

Handling Errors in Code

If you are using the official OpenAI SDK, these HTTP codes are automatically wrapped into exceptions that you can catch and handle gracefully. Pay special attention to catching the 402 status code for billing events.

import openai

try:
    response = client.chat.completions.create(
        model="llama3-70b-8192",
        messages=[{"role": "user", "content": "Hello"}]
    )
except openai.AuthenticationError:
    print("Your Fikra API key is invalid.")
except openai.RateLimitError:
    print("You are sending requests too quickly. Please slow down.")
except openai.APIStatusError as e:
    if e.status_code == 402:
        print("Out of credits! Time to top up your Fikra wallet.")
    else:
        print(f"Fikra API returned a status error: {e.status_code} - {e.message}")
except openai.APIError as e:
    print(f"Fikra API returned a general API Error: {e}")