Error Response Format
Status Codes
Code | Error Type | Description |
---|---|---|
400 | Bad Request | Invalid parameters |
401 | Unauthorized | Invalid API key |
403 | Forbidden | Insufficient credits |
404 | Not Found | Model/endpoint doesn’t exist |
429 | Rate Limit | Too many requests |
500 | Server Error | Internal error |
503 | Unavailable | Service temporarily down |
Python Error Handling
Retry Logic
JavaScript Error Handling
Common Errors
invalid_api_key
invalid_api_key
Cause: API key is invalid or missingSolution:
- Check API key in dashboard
- Ensure “Bearer ” prefix in Authorization header
- Verify no extra spaces
insufficient_credits
insufficient_credits
Cause: Account has insufficient creditsSolution:
- Add credits in dashboard
- Check usage with
/v1/usage
endpoint
rate_limit_exceeded
rate_limit_exceeded
Cause: Too many requestsSolution:
- Implement exponential backoff
- Reduce request rate
- Upgrade account tier
model_not_found
model_not_found
Cause: Invalid model IDSolution:
- Check model ID spelling
- Use
/v1/models
to list available models
context_length_exceeded
context_length_exceeded
Cause: Input too long for modelSolution:
- Reduce prompt length
- Use model with larger context
- Split into multiple requests
Best Practices
- Always use try-catch
- Implement exponential backoff
- Log errors for debugging
- Monitor credit balance
- Handle rate limits gracefully