Comfy-Org/ComfyUI · error · ValueError

No images returned from API endpoint

Error message

No images returned from API endpoint

What it means

Thrown by the OpenAI image-response helper (nodes_openai.py) when the decoded generation response contains an empty data array. The API returned HTTP success but zero image entries, so there is nothing to convert to tensors. It is a ValueError raised before any image decoding begins.

Source

Thrown at comfy_api_nodes/nodes_openai.py:78

async def validate_and_cast_response(response, timeout: int = None) -> torch.Tensor:
    """Validates and casts a response to a torch.Tensor.

    Args:
        response: The response to validate and cast.
        timeout: Request timeout in seconds. Defaults to None (no timeout).

    Returns:
        A torch.Tensor of shape (N, H, W, C) with all returned images; images whose
        dimensions differ from the first image's are resized to match it.

    Raises:
        ValueError: If the response is not valid.
    """
    # validate raw JSON response
    data = response.data
    if not data or len(data) == 0:
        raise ValueError("No images returned from API endpoint")

    # Initialize list to store image tensors
    image_tensors: list[torch.Tensor] = []

    # Process each image in the data array
    for img_data in data:
        if img_data.b64_json:
            img_io = BytesIO(base64.b64decode(img_data.b64_json))
        elif img_data.url:
            img_io = BytesIO()
            await download_url_to_bytesio(img_data.url, img_io, timeout=timeout)
        else:
            raise ValueError("Invalid image payload – neither URL nor base64 data present.")

        pil_img = Image.open(img_io).convert("RGBA")
        arr = np.asarray(pil_img).astype(np.float32) / 255.0
        image_tensors.append(torch.from_numpy(arr))

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Retry the generation - intermittent empty responses often succeed on retry
  2. Inspect the raw response JSON (log it before the helper runs) to confirm data is empty and check for a moderation/error field
  3. Adjust the prompt to avoid moderated content if the emptiness is consistent
  4. Check API-node/proxy configuration and OpenAI service status if all generations return empty

Example fix

// before
resp = await sync_op(cls, endpoint, response_model=OpenAIImageGenerationResponse, ...)
tensors = await openai_images_to_tensor(resp)  # raises on empty data
// after
if not resp.data:
    resp = await sync_op(cls, endpoint, response_model=OpenAIImageGenerationResponse, ...)  # one retry
tensors = await openai_images_to_tensor(resp)
Defensive patterns

Strategy: try-catch

Validate before calling

if not getattr(response, "data", None):
    raise ValueError("empty image data - retry or check moderation")

Type guard

def has_images(resp) -> bool:
    return bool(resp.data) and len(resp.data) > 0

Try / catch

try:
    tensors = await openai_images_to_tensor(resp)
except ValueError as e:
    if "No images" in str(e):
        resp = await regenerate()  # retry once
        tensors = await openai_images_to_tensor(resp)
    else:
        raise

Prevention

When it happens

Trigger: Calling the OpenAI image generation path where the JSON response body has data: [] or data: null (content-filtered generation, an intermediary mishandling n, or a proxy stripping the array).

Common situations: Prompts that trip OpenAI content moderation returning an empty result set; misrouted responses from the /proxy/openai endpoint; API schema changes where images arrive under a different key.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/9f7b58d1aa242435. Report an issue: GitHub.