Skip to content

Conversation

@ryanrapp
Copy link

Description:

It's currently not possible to pass request_timeout to Image.create, which prevents setting request timeouts.

Reference:

@raiyanyahya has raised this as a concern in #221

According to requests#Timeouts

Nearly all production code should use this parameter in nearly all requests. Failure to do so can cause your program to hang indefinitely.

However, this library has set the default as 600 seconds, which is not practical for many use cases.

User impact:

Occasionally the Image.create API call can stall for 600s, which could be a long time to a user to wait before retrying. By allowing the user to set a reasonable request_timeout, we can retry sooner.

Usage:

Example usage:

import openai
prompt="A picture of a soda can"
n=1
size="512x512"
# Timeout in seconds
request_timeout=30
openai.Image.create(prompt=prompt, n=n, size=size, request_timeout=request_timeout)

Example connect/read timeout usage:

connect_timeout = 3.0 # Timeout to establish connection
read_timeout = 30.0 # Timeout to receive response
request_timeout = (connect_timeout, read_timeout)
openai.Image.create(prompt=prompt, n=n, size=size, request_timeout=request_timeout)

Example async usage:

import asyncio
# ...
asyncio.run(openai.Image.acreate(prompt=prompt, n=n, size=size, request_timeout=request_timeout))

@ryanrapp ryanrapp changed the title Ryanrapp image create request timeout Image create request timeout Sep 19, 2023
@rattrayalex rattrayalex added the fixed in v1 Issues addressed by the v1 beta label Nov 10, 2023
@rattrayalex
Copy link
Collaborator

The new v1 of this library has support for adding timeout=… to each request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixed in v1 Issues addressed by the v1 beta

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants