{"record":{"id":"8a5e8b1fc2b1297b","repo":"xtekky/gpt4free","slug":"missing-u-cookie","errorCode":null,"errorMessage":"Missing \"_U\" cookie","messagePattern":"Missing \"_U\" cookie","errorType":"exception","errorClass":"MissingAuthError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/BingCreateImages.py","lineNumber":56,"sourceCode":"        proxy: str = None,\n        **kwargs,\n    ) -> AsyncResult:\n        session = BingCreateImages(cookies, proxy, api_key)\n        yield await session.generate(format_media_prompt(messages, prompt))\n\n    async def generate(self, prompt: str) -> ImageResponse:\n        \"\"\"\n        Asynchronously creates a markdown formatted string with images based on the prompt.\n\n        Args:\n            prompt (str): Prompt to generate images.\n\n        Returns:\n            str: Markdown formatted string with images.\n        \"\"\"\n        cookies = self.cookies or get_cookies(\".bing.com\", False)\n        if cookies is None or \"_U\" not in cookies:\n            raise MissingAuthError('Missing \"_U\" cookie')\n        async with create_session(cookies, self.proxy) as session:\n            images = await create_images(session, prompt)\n            return ImageResponse(\n                images,\n                prompt,\n                {\"preview\": \"{image}?w=200&h=200\"} if len(images) > 1 else {},\n            )\n","sourceCodeStart":38,"sourceCodeEnd":64,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/BingCreateImages.py#L38-L64","documentation":"Thrown by g4f/Provider/needs_auth/BingCreateImages.py when image generation cannot proceed because there is no Bing session: self.cookies is empty AND the cookie jar loaded from disk (get_cookies(\".bing.com\", False)) is either None or lacks the \"_U\" cookie. The \"_U\" cookie is Bing's authentication cookie; without it the create_images API call would be unauthorized, so the provider fails fast before making any request.","triggerScenarios":"Calling generate(prompt) on BingCreateImages without passing cookies while no .bing.com HAR/cookie file has been imported into g4f's har_and_cookies storage, or with a cookie file that does not contain the \"_U\" entry. Only the False (no-raise) variant of get_cookies is used, so a missing jar resolves to None and triggers the error.","commonSituations":"Fresh g4f install with no exported Bing cookies; expired cookie export where \"_U\" was not captured; user logged into bing.com in a different browser than the one used to export cookies/HAR.","solutions":["Log in to bing.com in your browser, export cookies (e.g. via a cookie-export extension or a HAR capture) and place the file in g4f's har_and_cookies directory so get_cookies finds a valid \"_U\" cookie.","Or pass the cookies explicitly: instantiate the provider and set cookies={\"_U\": \"...\"} before calling generate.","Re-export cookies if the existing file is stale; confirm the \"_U\" key is actually present in the file."],"exampleFix":"# before\nprovider = BingCreateImages()\nimages = await provider.generate(\"a cat\")  # raises Missing \"_U\" cookie\n\n# after\nprovider = BingCreateImages(cookies={\"_U\": \"<your bing _U cookie value>\"})\nimages = await provider.generate(\"a cat\")","handlingStrategy":"validation","validationCode":"from g4f.requests import get_cookies\n\ndef has_bing_auth(explicit_cookies=None):\n    cookies = explicit_cookies or get_cookies(\".bing.com\", False) or {}\n    return \"_U\" in cookies\n\nif not has_bing_auth(provider.cookies):\n    raise SystemExit(\"Export .bing.com cookies containing _U into har_and_cookies/ first\")","typeGuard":null,"tryCatchPattern":"try:\n    images = await provider.generate(prompt)\nexcept MissingAuthError as e:\n    if '_U' in str(e):\n        refresh_bing_cookies()","preventionTips":["Check for the _U cookie before calling generate.","Re-export Bing cookies on a schedule; they expire.","Pass cookies explicitly in automation instead of relying on the shared jar."],"tags":["authentication","cookies","bing","image-generation"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}