{"record":{"id":"4f5804592065b50e","repo":"sgl-project/sglang","slug":"no-base64-image-data-found","errorCode":null,"errorMessage":"No base64 image data found","messagePattern":"No base64 image data found","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py","lineNumber":440,"sourceCode":"        \"\"\"\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(\n        self,\n        lora_nickname: str,\n        lora_path: Optional[str] = None,\n        target: str = \"all\",\n    ) -> Dict[str, Any]:\n        \"\"\"\n        Set a LoRA adapter for the specified transformer(s).","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py#L422-L458","documentation":"ValueError from decode_image_from_response: the selected image entry exists but its 'b64_json' field is missing or empty, so the client cannot decode pixel data. Some servers return a URL instead of inline base64.","triggerScenarios":"Server returns images as 'url' references instead of 'b64_json', or returns an entry with an empty b64 string (failed per-image generation).","commonSituations":"Server configured for URL-response mode; partial failure where one of n images failed; API version mismatch changing the response schema.","solutions":["Log the image entry keys to see the actual schema (url vs b64_json).","If URLs are returned, download the image from the URL instead of decoding base64.","Ensure the request asked for response_format b64 (if supported).","Upgrade client and server to matching versions."],"exampleFix":"// before\nimage_data = response[\"data\"][0]  # then decode_image_from_response fails\n// after\nentry = response[\"data\"][0]\nif not entry.get(\"b64_json\") and entry.get(\"url\"):\n    import requests as rq, io\n    from PIL import Image\n    image = Image.open(io.BytesIO(rq.get(entry[\"url\"]).content))","handlingStrategy":"type-guard","validationCode":"entry = response['data'][index]\nassert entry.get('b64_json'), f'keys={list(entry)}'","typeGuard":"def has_b64(entry: dict) -> bool:\n    return bool(entry.get('b64_json'))","tryCatchPattern":"if not entry.get('b64_json'):\n    if entry.get('url'):\n        img = fetch(entry['url'])\n    else:\n        raise ValueError(f'no image payload: {entry}')","preventionTips":["Request b64_json response format when supported.","Handle both url and b64_json schemas defensively.","Log entry keys when the schema surprises you."],"tags":["validation","base64","image-decoding","response-schema","sgldiffusion"],"backgroundTag":"unexpected-response-schema","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}