{"record":{"id":"d054209f2a40df38","repo":"xtekky/gpt4free","slug":"timeout-error-after-timeout-sec","errorCode":null,"errorMessage":"Timeout error after {timeout} sec","messagePattern":"Timeout error after (.+?) sec","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"warning","filePath":"g4f/Provider/needs_auth/bing/create_images.py","lineNumber":124,"sourceCode":"        async with session.post(\n            url, allow_redirects=False, timeout=timeout\n        ) as response:\n            if response.status != 302:\n                raise RuntimeError(f\"Create images failed. Code: {response.status}\")\n\n    redirect_url = response.headers[\"Location\"].replace(\"&nfy=1\", \"\")\n    redirect_url = f\"{BING_URL}{redirect_url}\"\n    request_id = redirect_url.split(\"id=\")[-1]\n    async with session.get(redirect_url) as response:\n        response.raise_for_status()\n\n    polling_url = (\n        f\"{BING_URL}/images/create/async/results/{request_id}?q={url_encoded_prompt}\"\n    )\n    start_time = time.time()\n    while True:\n        if time.time() - start_time > timeout:\n            raise RuntimeError(f\"Timeout error after {timeout} sec\")\n        async with session.get(polling_url) as response:\n            if response.status != 200:\n                raise RuntimeError(f\"Polling images faild. Code: {response.status}\")\n            text = await response.text()\n            if not text or \"GenerativeImagesStatusPage\" in text:\n                await asyncio.sleep(1)\n            else:\n                break\n    error = None\n    try:\n        error = json.loads(text).get(\"errorMessage\")\n    except Exception:\n        pass\n    if error == \"Pending\":\n        raise RuntimeError(\"Prompt is been blocked\")\n    elif error:\n        raise RuntimeError(error)\n    return read_images(text)","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/bing/create_images.py#L106-L142","documentation":"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.","triggerScenarios":"Beng image generation is slow or stuck: the polling endpoint keeps returning the GenerativeImagesStatusPage (or empty body) past the configured timeout value.","commonSituations":"Long/complex prompts taking longer than the default timeout, Bing under heavy load, an aggressive low timeout passed by the caller.","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"],"exampleFix":"# before\nimages = create_images(session, prompt, cookies, timeout=20)\n\n# after\nimages = create_images(session, prompt, cookies, timeout=120)  # allow more time","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    images = create_images(session, prompt, cookies, timeout=60)\nexcept RuntimeError as e:\n    if 'Timeout' in str(e):\n        images = create_images(session, prompt, cookies, timeout=180)\n    else:\n        raise","preventionTips":["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"],"tags":["timeout","polling","bing","image-generation","g4f"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}