{"record":{"id":"901d66c7b1d65f64","repo":"open-webui/open-webui","slug":"error-failed-to-connect-to-the-image-generation","errorCode":null,"errorMessage":"[ERROR: Failed to connect to the image generation engine]","messagePattern":"\\[ERROR: Failed to connect to the image generation engine\\]","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"backend/open_webui/routers/images.py","lineNumber":222,"sourceCode":"    if image_config.IMAGE_GENERATION_ENGINE == 'openai':\n        return image_config.IMAGE_GENERATION_MODEL if image_config.IMAGE_GENERATION_MODEL else 'dall-e-2'\n    elif image_config.IMAGE_GENERATION_ENGINE == 'gemini':\n        return image_config.IMAGE_GENERATION_MODEL if image_config.IMAGE_GENERATION_MODEL else 'imagen-3.0-generate-002'\n    elif image_config.IMAGE_GENERATION_ENGINE == 'comfyui':\n        return image_config.IMAGE_GENERATION_MODEL if image_config.IMAGE_GENERATION_MODEL else ''\n    elif image_config.IMAGE_GENERATION_ENGINE == 'automatic1111' or image_config.IMAGE_GENERATION_ENGINE == '':\n        try:\n            session = await get_session()\n            async with session.get(\n                url=f'{image_config.AUTOMATIC1111_BASE_URL}/sdapi/v1/options',\n                headers={'authorization': get_automatic1111_api_auth(image_config)},\n                ssl=AIOHTTP_CLIENT_SESSION_SSL,\n            ) as r:\n                options = await r.json()\n            return options['sd_model_checkpoint']\n        except Exception as e:\n            log.exception(f'Failed to get default model from automatic1111: {e}')\n            raise HTTPException(\n                status_code=400,\n                detail=ERROR_MESSAGES.DEFAULT(e, 'Failed to connect to the image generation engine'),\n            )\n\n\nclass ImagesConfig(BaseModel):\n    ENABLE_IMAGE_GENERATION: bool\n    ENABLE_IMAGE_PROMPT_GENERATION: bool\n\n    IMAGE_GENERATION_ENGINE: str\n    IMAGE_GENERATION_MODEL: str\n    IMAGE_SIZE: str | None\n    IMAGE_STEPS: int | None\n\n    IMAGES_OPENAI_API_BASE_URL: str\n    IMAGES_OPENAI_API_KEY: str\n    IMAGES_OPENAI_API_VERSION: str\n    IMAGES_OPENAI_API_PARAMS: dict | str | None","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/open-webui/open-webui/blob/01f4282f1ffe0d6212f58d3afbeae21fffd0c4be/backend/open_webui/routers/images.py#L204-L240","documentation":"Raised while resolving the default model when IMAGE_GENERATION_ENGINE is 'automatic1111' (or empty): the code GETs {AUTOMATIC1111_BASE_URL}/sdapi/v1/options and any exception — connection refused, timeout, bad JSON, missing 'sd_model_checkpoint' key — becomes HTTP 400 'Failed to connect to the image generation engine' (images.py:214-222).","triggerScenarios":"Any admin config/image-model request that resolves the A1111 checkpoint while the Automatic1111 (stable-diffusion-webui) API is down, AUTOMATIC1111_BASE_URL is wrong (missing http://, wrong port, or pointing at the UI instead of the --api endpoint), TLS verification fails, or the response lacks sd_model_checkpoint because the API version is old.","commonSituations":"A1111 launched without the --api flag; base URL left at default after moving the service; self-signed HTTPS with AIOHTTP_CLIENT_SESSION_SSL rejecting it; A1111 updated and changed its options schema.","solutions":["curl {AUTOMATIC1111_BASE_URL}/sdapi/v1/options from the Open WebUI host — it must return JSON containing sd_model_checkpoint","Restart Automatic1111 with --api (and --listen if remote) and fix AUTOMATIC1111_BASE_URL in Admin Settings > Images","For HTTPS with self-signed certs, configure the trusted CA via AIOHTTP_CLIENT_SESSION_SSL / persistent_config rather than disabling checks broadly","If the key is missing, upgrade the A1111 API version or pin an engine/model explicitly so the checkpoint lookup is skipped"],"exampleFix":"# before: wrong base URL\nAUTOMATIC1111_BASE_URL=http://localhost:7860/\n# A1111 actually listening on 0.0.0.0:7861 with --api\n# after\nAUTOMATIC1111_BASE_URL=http://a1111-host:7861/\n# launch: python launch.py --api --listen --port 7861","handlingStrategy":"try-catch","validationCode":"import httpx, os\n\nasync def a1111_alive(base_url: str) -> bool:\n    try:\n        r = await httpx.get(f'{base_url}/sdapi/v1/options', timeout=5)\n        return r.status_code == 200 and 'sd_model_checkpoint' in r.json()\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    model = await client.get('/api/v1/images/config')  # any path resolving the A1111 checkpoint\nexcept httpx.HTTPStatusError as e:\n    if 'Failed to connect to the image generation engine' in e.response.text:\n        raise RuntimeError('Automatic1111 unreachable: check AUTOMATIC1111_BASE_URL and --api flag')\n    raise","preventionTips":["Start A1111 with --api and verify /sdapi/v1/options before saving image config","Health-check the engine URL from the Open WebUI host/container, not your browser","Keep AUTOMATIC1111_BASE_URL in sync when the engine moves (host, port, TLS)"],"tags":["images","automatic1111","network","config","http-400"],"backgroundTag":null,"analyzedSha":"01f4282f1ffe0d6212f58d3afbeae21fffd0c4be","analyzedAt":"2026-08-14T18:25:22.715Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}