Error Handling
Understand error codes and how to handle them gracefully.
Error Response Format
All errors return a consistent JSON structure:
{ "error": { "message": "Human-readable error description", "type": "error_type", "code": "specific_error_code" }}Error Codes
The request body is malformed or missing required fields.
Examples: Invalid JSON, missing 'messages' field, invalid parameters
The API key is missing, invalid, or revoked.
Examples: Missing Authorization header, malformed key, disabled key
Account has insufficient credits or no active subscription.
Examples: Zero balance, expired subscription
Your plan doesn't have access to the requested resource.
Examples: Free tier attempting to use infe-titan model
The requested model does not exist.
Examples: Typo in model name, deprecated model
You've exceeded your rate limit for requests or tokens.
Examples: Too many requests per minute
An unexpected error occurred on our servers.
Examples: Internal server error, temporary outage
The upstream inference provider returned an error.
Examples: Provider timeout, service unavailable
Handling Errors
Best practices for error handling:
from openai import OpenAI, APIError, RateLimitError, AuthenticationErrorclient = OpenAI( api_key="your-infe-api-key", base_url="https://api.infe.io/v1")try: response = client.chat.completions.create( model="infe-pulse", messages=[{"role": "user", "content": "Hello!"}] )except AuthenticationError: print("Invalid API key. Check your credentials.")except RateLimitError: print("Rate limit exceeded. Wait and retry.")except APIError as e: print(f"API error: {e.message}")Retry Strategy
For transient errors (429, 500, 502), implement exponential backoff:
| Code | Should Retry? | Recommendation |
|---|---|---|
| 400 | No | Fix the request |
| 401 | No | Check API key |
| 402 | No | Top up credits |
| 403 | No | Upgrade plan |
| 429 | Yes | Wait 1s, then 2s, then 4s... |
| 500 | Yes | Retry up to 3 times |
| 502 | Yes | Retry with backoff |
Troubleshooting
"Invalid API key"
- Ensure the Authorization header is
Bearer YOUR_KEY - Check for extra spaces or newlines in the key
- Verify the key hasn't been revoked in your dashboard
"Insufficient credits"
- Check your balance in the dashboard
- Top up or upgrade your plan
- Reduce token usage with shorter prompts
"Model not found"
- Use exact model IDs:
infe-pulse,infe-titan - Check available models with
GET /v1/models - Some models require higher tiers
Need Help?
If you're encountering persistent errors, include the x-request-id header from the response when contacting support.