{"record":{"id":"25488e9fab373135","repo":"sgl-project/sglang","slug":"failed-to-edit-image-str-e","errorCode":null,"errorMessage":"Failed to edit image: {str(e)}","messagePattern":"Failed to edit image: (.+?)","errorType":"error_code","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py","lineNumber":179,"sourceCode":"                )\n\n            # Prepare headers for multipart form data\n            headers = {\n                \"Authorization\": f\"Bearer {self.api_key}\",\n            }\n\n            try:\n                response = requests.post(\n                    f\"{self.base_url}/images/edits\",\n                    files=files,\n                    data=data,\n                    headers=headers,\n                    timeout=300,  # 5 minutes timeout for generation\n                )\n                response.raise_for_status()\n                return response.json()\n            except requests.exceptions.RequestException as e:\n                raise RuntimeError(f\"Failed to edit image: {str(e)}\")\n            finally:\n                # Close file handles\n                for file_tuple in files.values():\n                    if isinstance(file_tuple, tuple) and len(file_tuple) > 1:\n                        file_tuple[1].close()\n        else:\n            # Use generation endpoint - add generation-specific parameters\n            payload = common_params.copy()\n            if quality:\n                payload[\"quality\"] = quality\n            if style:\n                payload[\"style\"] = style\n\n            try:\n                response = requests.post(\n                    f\"{self.base_url}/images/generations\",\n                    json=payload,\n                    headers=self.headers,","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py#L161-L197","documentation":"Raised by SGLDiffusionServerAPI.generate_image when the multipart image-edit POST to the SGLang Diffusion server fails at the HTTP level (connection error, timeout after 300s, or a non-2xx status via raise_for_status). The original requests exception text is embedded in the RuntimeError.","triggerScenarios":"Calling generate_image() in edit mode (with input image files) when the server is unreachable, the edit endpoint returns 4xx/5xx, or generation takes longer than the hardcoded 300-second timeout.","commonSituations":"Server not started or wrong base_url; auth header rejected (401/403); large input images causing slow uploads; heavy edit workload exceeding the 5-minute timeout.","solutions":["Verify the SGLang Diffusion server is up and base_url is correct (curl the /v1 endpoints).","Check the wrapped message for HTTP status codes: 401/403 means bad api_key, 404 means wrong endpoint/path.","For timeouts, reduce image size/n or raise the client timeout in server_api.py.","Inspect server logs for stack traces during the edit request."],"exampleFix":"// before\nresp = api.generate_image(prompt=p, image_paths=[\"in.png\"])  # RuntimeError: Failed to edit image: ...\n// after\nimport requests\ntry:\n    resp = api.generate_image(prompt=p, image_paths=[\"in.png\"])\nexcept RuntimeError as e:\n    print(\"edit failed:\", e)  # inspect embedded status code / timeout","handlingStrategy":"try-catch","validationCode":"import requests\nrequests.get(base_url.rstrip('/') + '/models', headers=headers, timeout=5).raise_for_status()","typeGuard":null,"tryCatchPattern":"try:\n    resp = api.generate_image(prompt=p, image_paths=[\"in.png\"])\nexcept RuntimeError as e:\n    msg = str(e)\n    if 'timeout' in msg.lower(): retry_or_shrink()\n    else: log_and_surface(msg)","preventionTips":["Health-check the server before submitting edit jobs.","Keep input images reasonably sized to fit the 300s budget.","Store base_url/api_key in one validated config."],"tags":["network","http","image-edit","timeout","sgldiffusion"],"backgroundTag":"http-request-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}