Skip to content

API requests timeout after 60 seconds when generating via Colab #3047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
SarahPeterson2854 opened this issue May 13, 2025 · 0 comments
Open

Comments

@SarahPeterson2854
Copy link

Description:
When using the web UI via Colab, there's a 60-second timeout for POST requests. This causes failures when generating SDXL images or upscaling via API, even though the same operations work fine through the local web UI in Colab.

Steps to Reproduce:

Run the web UI in Colab

Attempt to generate SDXL or upscaled images via API with the following code:

python
import requests
import base64

url = "https://....gradio.live/"

payload = {
"prompt": "puppy dog",
"steps": 400,
}

try:
response = requests.post(url=f'{url}/sdapi/v1/txt2img', json=payload, timeout=600)
response.raise_for_status()
r = response.json()

with open("output.png", 'wb') as f:
    f.write(base64.b64decode(r['images'][0]))

except requests.exceptions.RequestException as e:
print(f"Request failed: {e}")
except KeyError:
print("Response format unexpected")
except Exception as e:
print(f"Unexpected error: {e}")
Expected Behavior:

API should complete image generation for SDXL/upscaling tasks that take longer than 60 seconds

Should return the generated image in the response

Actual Behavior:

Request times out after 60 seconds

Results in a KeyError for 'images' as no image data is returned

Additional Context:

The same image generation works fine through the web UI in Colab

The issue only occurs with longer-running tasks (SDXL, upscaling)

The timeout appears to be a hard limit on the Gradio side

Suggested Solution:
Either:

Increase the default timeout for API requests, or

Make the timeout configurable when launching the web UI

Error Log:

KeyError Traceback (most recent call last)
Cell In[24], line 29
27 # Decode and save the image.
28 with open("output.png", 'wb') as f:
---> 29 f.write(base64.b64decode(r['images'][0]))
31 r

KeyError: 'images'
Environment:

Platform: Google Colab

WebUI version: 71575ff

Model: SDXL/upscaling models

Tried already:
gradio que,
increasing timeout in post
timeout for requests library in python
localtunnel
cloudflare

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant