xtekky/gpt4free · warning · RuntimeError
Timeout error after {timeout} sec
Error message
Timeout error after {timeout} sec What it means
Raised as RuntimeError by Bing image creation when the async-results polling loop exceeds the timeout: the code polls polling_url once per second and, if time.time() - start_time > timeout before a completed page appears, it aborts. Bing's async generation did not finish in the allotted window.
Source
Thrown at g4f/Provider/needs_auth/bing/create_images.py:124
async with session.post(
url, allow_redirects=False, timeout=timeout
) as response:
if response.status != 302:
raise RuntimeError(f"Create images failed. Code: {response.status}")
redirect_url = response.headers["Location"].replace("&nfy=1", "")
redirect_url = f"{BING_URL}{redirect_url}"
request_id = redirect_url.split("id=")[-1]
async with session.get(redirect_url) as response:
response.raise_for_status()
polling_url = (
f"{BING_URL}/images/create/async/results/{request_id}?q={url_encoded_prompt}"
)
start_time = time.time()
while True:
if time.time() - start_time > timeout:
raise RuntimeError(f"Timeout error after {timeout} sec")
async with session.get(polling_url) as response:
if response.status != 200:
raise RuntimeError(f"Polling images faild. Code: {response.status}")
text = await response.text()
if not text or "GenerativeImagesStatusPage" in text:
await asyncio.sleep(1)
else:
break
error = None
try:
error = json.loads(text).get("errorMessage")
except Exception:
pass
if error == "Pending":
raise RuntimeError("Prompt is been blocked")
elif error:
raise RuntimeError(error)
return read_images(text)View on GitHub (pinned to 973504e177)
Solutions
- Increase the timeout argument passed to create_images / the image provider call
- Retry — slow generation is often transient load
- Shorten the prompt; simpler prompts usually generate faster
Example fix
# before images = create_images(session, prompt, cookies, timeout=20) # after images = create_images(session, prompt, cookies, timeout=120) # allow more time
Defensive patterns
Strategy: retry
Try / catch
try:
images = create_images(session, prompt, cookies, timeout=60)
except RuntimeError as e:
if 'Timeout' in str(e):
images = create_images(session, prompt, cookies, timeout=180)
else:
raise Prevention
- Pass a generous timeout (60s+) for complex prompts
- Treat image generation as slow I/O: run it in a worker with its own deadline budget
When it happens
Trigger: Beng image generation is slow or stuck: the polling endpoint keeps returning the GenerativeImagesStatusPage (or empty body) past the configured timeout value.
Common situations: Long/complex prompts taking longer than the default timeout, Bing under heavy load, an aggressive low timeout passed by the caller.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- Polling images faild. Code: {response.status}
- No coins left. Log in with a different account or wait a whi
- Create images failed: {error}
- Create images failed. Code: {response.status}
- Upload timeout for {file_id}
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/d054209f2a40df38.
Report an issue: GitHub.