{"record":{"id":"b67ed6ad02f702ee","repo":"xtekky/gpt4free","slug":"create-images-failed-code-response-status","errorCode":null,"errorMessage":"Create images failed. Code: {response.status}","messagePattern":"Create images failed\\. Code: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/bing/create_images.py","lineNumber":110,"sourceCode":"    async with session.post(\n        url, allow_redirects=False, data=payload, timeout=timeout\n    ) as response:\n        response.raise_for_status()\n        text = (await response.text()).lower()\n        if \"0 coins available\" in text:\n            raise RateLimitError(\n                \"No coins left. Log in with a different account or wait a while\"\n            )\n        for error in ERRORS:\n            if error in text:\n                raise RuntimeError(f\"Create images failed: {error}\")\n    if response.status != 302:\n        url = f\"{BING_URL}/images/create?q={url_encoded_prompt}&rt=3&FORM=GENCRE\"\n        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()","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/bing/create_images.py#L92-L128","documentation":"Raised as RuntimeError by Bing image creation when neither the rt=4 nor the retry rt=3 submission returns the expected 302 redirect. Without the redirect the provider cannot obtain the request id needed to poll results, so it fails with the last HTTP status code received.","triggerScenarios":"Bing responds 200 (form re-render), 4xx (auth/CSRF cookie problems), or 5xx instead of redirecting after the create POST.","commonSituations":"Expired or missing _U cookie so Bing re-renders the page instead of accepting, Bing A/B changes in the create flow, temporary server errors.","solutions":["Refresh the Bing cookies (log in again) — a 200 instead of 302 usually means unauthenticated","Retry after a short delay for transient 5xx responses","Check the returned status code in the message to distinguish auth (401/403) from server issues (5xx)"],"exampleFix":"# before\nimages = create_images(session, prompt, cookies)  # Create images failed. Code: 200\n\n# after\n# refresh cookies then retry\ncookies = load_fresh_bing_cookies()\ntry:\n    images = create_images(session, prompt, cookies)\nexcept RuntimeError as e:\n    logging.warning('Bing create failed: %s', e)\n    images = fallback_image_provider(prompt)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    images = create_images(session, prompt, cookies)\nexcept RuntimeError as e:\n    if 'Code: 5' in str(e) or 'Code: 429' in str(e):\n        time.sleep(10)\n        images = create_images(session, prompt, cookies)\n    elif 'Code: 200' in str(e) or 'Code: 40' in str(e):\n        refresh_bing_cookies()  # auth issue: re-login then retry\n    else:\n        raise","preventionTips":["A 200 instead of 302 usually means cookies are stale — refresh them on this signal","Keep Bing session cookies current; rotate before they expire"],"tags":["http","redirect","cookies","bing","image-generation","g4f"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}