How to set a timeout on an API function call using using the Python library

Setting request_timeout worked for me.
e.g.

openai.Completion.create(request_timeout=1)

I was able to get this exception message.

Request timed out: HTTPSConnectionPool(host=‘api.openai.com’, port=443): Read timed out. (read timeout=1)

4 Likes