{"record":{"id":"e2754bb0f21423c9","repo":"HKUDS/DeepTutor","slug":"image-generation-request-error-exc","errorCode":null,"errorMessage":"Image generation request error: {exc}","messagePattern":"Image generation request error: (.+?)","errorType":"http","errorClass":"GenerationProviderError","httpStatus":null,"severity":"error","filePath":"deeptutor/services/imagegen/adapters/chat_completions.py","lineNumber":64,"sourceCode":"            **build_auth_headers(config.auth_style, config.api_key),\n            **(config.extra_headers or {}),\n        }\n        payload: dict[str, Any] = {\n            \"model\": config.model,\n            \"messages\": [{\"role\": \"user\", \"content\": prompt}],\n            \"modalities\": [\"image\", \"text\"],\n        }\n\n        logger.debug(\"imagegen(chat) url=%s model=%s\", url, config.model)\n        try:\n            async with httpx.AsyncClient(timeout=config.request_timeout) as client:\n                resp = await client.post(url, headers=headers, json=payload)\n                raise_for_provider(resp, \"Image generation\")\n                images = [\n                    await self._materialize(client, src) for src in self._extract_sources(resp)\n                ]\n        except httpx.HTTPError as exc:\n            raise GenerationProviderError(f\"Image generation request error: {exc}\") from exc\n        if not images:\n            raise GenerationProviderError(\n                \"Chat model returned no image. Check the model supports image output \"\n                \"(its output modalities must include `image`).\"\n            )\n        return images\n\n    @staticmethod\n    def _extract_sources(resp: httpx.Response) -> list[str]:\n        \"\"\"Pull image URLs / data URIs out of the assistant message.\"\"\"\n        data = resp.json()\n        sources: list[str] = []\n        choices = data.get(\"choices\") if isinstance(data, dict) else None\n        for choice in choices or []:\n            message = (choice or {}).get(\"message\") or {}\n            for image in message.get(\"images\") or []:\n                if not isinstance(image, dict):\n                    continue","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/services/imagegen/adapters/chat_completions.py#L46-L82","documentation":"A httpx.HTTPError (connection failure, timeout, TLS error, etc.) occurred while POSTing the image-generation chat-completions request or downloading an image URL it returned. The adapter wraps the transport-level exception in GenerationProviderError, chaining the original exc.","triggerScenarios":"DNS resolution failure or refused connection to config.base_url; network timeout during the multimodal chat/completions call; TLS certificate error; a returned image URL that fails to download (the _materialize GET happens inside the same try block).","commonSituations":"Wrong/unreachable base_url, corporate proxy or firewall blocking the API host, ephemeral network outage, self-signed cert on a self-hosted OpenAI-compatible gateway, short timeout against a slow image-generating model.","solutions":["Verify the base_url host resolves and is reachable (curl a simple chat completion against it)","Retry with backoff — transient network/timeout failures are common for long-running image generation","If behind a proxy, set HTTP_PROXY/HTTPS_PROXY or configure httpx accordingly; if TLS fails on a self-hosted gateway, fix the certificate","Increase the client timeout passed to the adapter so slow image models aren't cut off"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"import socket\nsocket.gethostbyname(urlparse(config.base_url).hostname)  # raises early if DNS fails","typeGuard":null,"tryCatchPattern":"try:\n    images = await adapter.generate(prompt, config)\nexcept GenerationProviderError as exc:\n    if \"request error\" in str(exc):\n        # httpx.HTTPError underneath; safe to retry with backoff\n        await asyncio.sleep(backoff); retry()\n    raise","preventionTips":["Set generous httpx timeouts for image generation","Pre-flight check the host resolves before the request","Wrap generate() in a bounded retry with exponential backoff"],"tags":["network","httpx","imagegen","timeout"],"backgroundTag":"http-request-failed","analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}