Error Handling
The Bizora API uses standard HTTP status codes and returns errors in a simple JSON format.
Common Errors
401 - Invalid API Key
Your API key is missing or incorrect.
try:
response = client.chat.completions.create(
model="bizora",
messages=[{"role": "human", "content": "Hello"}]
)
except openai.AuthenticationError as e:
print("Check your API key")
402 - Insufficient Balance
Add credits to your account to continue.
{
"error": {
"type": "insufficient_balance",
"message": "Please add credits to your account"
}
}
429 - Rate Limit
You're making requests too quickly. Add a small delay between requests.
import time
try:
response = client.chat.completions.create(...)
except openai.RateLimitError:
time.sleep(1) # Wait 1 second
# Retry request
Handling Errors in Streaming
Errors appear in the stream just like regular messages:
stream = client.chat.completions.create(
model="bizora",
messages=[{"role": "human", "content": "Hello"}],
stream=True
)
for chunk in stream:
if hasattr(chunk, 'error'):
print(f"Error: {chunk.error.get('message')}")
break
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
Best Practices
- Wrap API calls in try-catch - Always handle potential errors
- Check your balance - Monitor your account balance in the dashboard
- Add retry logic - Retry failed requests with exponential backoff
- Log errors - Keep track of errors for debugging
That's it! The OpenAI SDK handles most error cases automatically.