if isinstance(e, openai.error.RateLimitError):
raise Exception("Rate limit exceeded too many times.") from e
elif isinstance(e, openai.error.ServiceUnavailableError):
raise Exception("Service unavailable too many times.") from e
else:
raise e
However, openai.error no longer exists (contradicting this page).
Now, it looks like I can do openai.RateLimit instead of openai.error.RateLimitError, but openai.ServiceUnavailableError does not exist. Where did it go?
How can I find out where to import each error type?
Following up, the example from the Python README is:
import openai
from openai import OpenAI
client = OpenAI()
try:
client.fine_tunes.create(
training_file="file-XGinujblHPwGLSztz8cPS8XY",
)
except openai.APIConnectionError as e:
print("The server could not be reached")
print(e.__cause__) # an underlying Exception, likely raised within httpx.
except openai.RateLimitError as e:
print("A 429 status code was received; we should back off a bit.")
except openai.APIStatusError as e:
print("Another non-200-range status code was received")
print(e.status_code)
print(e.response)