{"record":{"id":"ca155dc8833313ae","repo":"sgl-project/sglang","slug":"no-image-data-in-response","errorCode":null,"errorMessage":"No image data in response","messagePattern":"No image data in response","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py","lineNumber":433,"sourceCode":"            \".webp\": \"image/webp\",\n        }\n        return content_types.get(ext, \"image/png\")\n\n    def decode_image_from_response(\n        self, response_data: Dict[str, Any], index: int = 0\n    ) -> Image.Image:\n        \"\"\"\n        Decode base64 image from API response.\n\n        Args:\n            response_data: API response dictionary\n            index: Index of the image in the response (default: 0)\n\n        Returns:\n            PIL Image object\n        \"\"\"\n        if \"data\" not in response_data or not response_data[\"data\"]:\n            raise ValueError(\"No image data in response\")\n\n        if index >= len(response_data[\"data\"]):\n            raise IndexError(f\"Image index {index} out of range\")\n\n        image_data = response_data[\"data\"][index]\n        if \"b64_json\" not in image_data or not image_data[\"b64_json\"]:\n            raise ValueError(\"No base64 image data found\")\n\n        image_bytes = base64.b64decode(image_data[\"b64_json\"])\n        image = Image.open(io.BytesIO(image_bytes))\n\n        # Convert to RGB if needed\n        if image.mode != \"RGB\":\n            image = image.convert(\"RGB\")\n\n        return image\n\n    def set_lora(","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py#L415-L451","documentation":"ValueError from the static helper decode_image_from_response: the response dict has no 'data' key or it is empty. The server responded successfully but returned no image entries, so there is nothing to decode.","triggerScenarios":"Passing a generate_image response whose 'data' list is missing/empty — e.g. server returned an error-shaped 200, n=0, or a response from a different endpoint.","commonSituations":"Server bug returning 200 with empty data; calling decode with a video or status response instead of an image response; upstream filtered all images.","solutions":["Log the full response JSON before decoding to see its actual shape.","Verify you passed the return value of generate_image, not another API response.","Check server logs for why data is empty (generation may have failed silently).","Guard with len(response.get('data', [])) > 0 before decoding."],"exampleFix":"// before\nimg = decode_image_from_response(response)\n// after\nif not response.get(\"data\"):\n    raise RuntimeError(f\"empty image payload: {response}\")\nimg = decode_image_from_response(response)","handlingStrategy":"type-guard","validationCode":"assert isinstance(response, dict) and len(response.get('data') or []) > 0, response","typeGuard":"def has_image_data(r: dict) -> bool:\n    return isinstance(r, dict) and bool(r.get('data'))","tryCatchPattern":null,"preventionTips":["Always shape-check responses before decoding.","Log full payload on unexpected shape.","Keep client and server versions in lockstep."],"tags":["validation","empty-response","image-decoding","sgldiffusion"],"backgroundTag":"empty-response-body","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}