{"record":{"id":"9f7b58d1aa242435","repo":"Comfy-Org/ComfyUI","slug":"no-images-returned-from-api-endpoint","errorCode":null,"errorMessage":"No images returned from API endpoint","messagePattern":"No images returned from API endpoint","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_openai.py","lineNumber":78,"sourceCode":"\nasync def validate_and_cast_response(response, timeout: int = None) -> torch.Tensor:\n    \"\"\"Validates and casts a response to a torch.Tensor.\n\n    Args:\n        response: The response to validate and cast.\n        timeout: Request timeout in seconds. Defaults to None (no timeout).\n\n    Returns:\n        A torch.Tensor of shape (N, H, W, C) with all returned images; images whose\n        dimensions differ from the first image's are resized to match it.\n\n    Raises:\n        ValueError: If the response is not valid.\n    \"\"\"\n    # validate raw JSON response\n    data = response.data\n    if not data or len(data) == 0:\n        raise ValueError(\"No images returned from API endpoint\")\n\n    # Initialize list to store image tensors\n    image_tensors: list[torch.Tensor] = []\n\n    # Process each image in the data array\n    for img_data in data:\n        if img_data.b64_json:\n            img_io = BytesIO(base64.b64decode(img_data.b64_json))\n        elif img_data.url:\n            img_io = BytesIO()\n            await download_url_to_bytesio(img_data.url, img_io, timeout=timeout)\n        else:\n            raise ValueError(\"Invalid image payload – neither URL nor base64 data present.\")\n\n        pil_img = Image.open(img_io).convert(\"RGBA\")\n        arr = np.asarray(pil_img).astype(np.float32) / 255.0\n        image_tensors.append(torch.from_numpy(arr))\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_openai.py#L60-L96","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Retry the generation - intermittent empty responses often succeed on retry","Inspect the raw response JSON (log it before the helper runs) to confirm data is empty and check for a moderation/error field","Adjust the prompt to avoid moderated content if the emptiness is consistent","Check API-node/proxy configuration and OpenAI service status if all generations return empty"],"exampleFix":"// before\nresp = await sync_op(cls, endpoint, response_model=OpenAIImageGenerationResponse, ...)\ntensors = await openai_images_to_tensor(resp)  # raises on empty data\n// after\nif not resp.data:\n    resp = await sync_op(cls, endpoint, response_model=OpenAIImageGenerationResponse, ...)  # one retry\ntensors = await openai_images_to_tensor(resp)","handlingStrategy":"try-catch","validationCode":"if not getattr(response, \"data\", None):\n    raise ValueError(\"empty image data - retry or check moderation\")","typeGuard":"def has_images(resp) -> bool:\n    return bool(resp.data) and len(resp.data) > 0","tryCatchPattern":"try:\n    tensors = await openai_images_to_tensor(resp)\nexcept ValueError as e:\n    if \"No images\" in str(e):\n        resp = await regenerate()  # retry once\n        tensors = await openai_images_to_tensor(resp)\n    else:\n        raise","preventionTips":["Check resp.data immediately after the sync_op call","Retry once on empty data before investigating deeper","Avoid borderline prompt content that triggers moderation-driven empty results"],"tags":["openai","images","api-response","empty-result"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}