sgl-project/sglang · error · ValueError

No image data in response

Error message

No image data in response

What it means

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.

Source

Thrown at python/sglang/multimodal_gen/apps/ComfyUI_SGLDiffusion/core/server_api.py:433

            ".webp": "image/webp",
        }
        return content_types.get(ext, "image/png")

    def decode_image_from_response(
        self, response_data: Dict[str, Any], index: int = 0
    ) -> Image.Image:
        """
        Decode base64 image from API response.

        Args:
            response_data: API response dictionary
            index: Index of the image in the response (default: 0)

        Returns:
            PIL Image object
        """
        if "data" not in response_data or not response_data["data"]:
            raise ValueError("No image data in response")

        if index >= len(response_data["data"]):
            raise IndexError(f"Image index {index} out of range")

        image_data = response_data["data"][index]
        if "b64_json" not in image_data or not image_data["b64_json"]:
            raise ValueError("No base64 image data found")

        image_bytes = base64.b64decode(image_data["b64_json"])
        image = Image.open(io.BytesIO(image_bytes))

        # Convert to RGB if needed
        if image.mode != "RGB":
            image = image.convert("RGB")

        return image

    def set_lora(

View on GitHub (pinned to 0132848349)

Solutions

  1. Log the full response JSON before decoding to see its actual shape.
  2. Verify you passed the return value of generate_image, not another API response.
  3. Check server logs for why data is empty (generation may have failed silently).
  4. Guard with len(response.get('data', [])) > 0 before decoding.

Example fix

// before
img = decode_image_from_response(response)
// after
if not response.get("data"):
    raise RuntimeError(f"empty image payload: {response}")
img = decode_image_from_response(response)
Defensive patterns

Strategy: type-guard

Validate before calling

assert isinstance(response, dict) and len(response.get('data') or []) > 0, response

Type guard

def has_image_data(r: dict) -> bool:
    return isinstance(r, dict) and bool(r.get('data'))

Prevention

When it happens

Trigger: 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.

Common situations: Server bug returning 200 with empty data; calling decode with a video or status response instead of an image response; upstream filtered all images.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/ca155dc8833313ae. Report an issue: GitHub.