{"record":{"id":"a89ac8bfd2717706","repo":"Comfy-Org/ComfyUI","slug":"invalid-image-payload-neither-url-nor-base64-dat","errorCode":null,"errorMessage":"Invalid image payload – neither URL nor base64 data present.","messagePattern":"Invalid image payload – neither URL nor base64 data present\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_openai.py","lineNumber":91,"sourceCode":"        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\n    # With size=\"auto\" the API can return images whose dimensions differ by a few pixels within a single response\n    # resize them to the first image's dimensions so they can be stacked into one batch.\n    ref_h, ref_w = image_tensors[0].shape[:2]\n    for i, t in enumerate(image_tensors):\n        if t.shape[:2] != (ref_h, ref_w):\n            samples = t.unsqueeze(0).movedim(-1, 1)\n            samples = common_upscale(samples, ref_w, ref_h, \"bilinear\", \"center\")\n            image_tensors[i] = samples.movedim(1, -1).squeeze(0)\n    return torch.stack(image_tensors, dim=0)\n\n\nclass OpenAIDalle2(IO.ComfyNode):\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_openai.py#L73-L109","documentation":"Raised while iterating the OpenAI image response data array: an individual image entry has neither b64_json nor url populated. The helper cannot obtain bytes for that image, so it fails with this ValueError instead of silently skipping an element.","triggerScenarios":"An OpenAI (or compatible) image API response where a data[i] object exists but both b64_json and url fields are null/absent - often from third-party OpenAI-compatible endpoints with partial schema compliance or partial failures inside a multi-image (n>1) response.","commonSituations":"Using an OpenAI-compatible proxy or alternative provider behind /proxy/openai that returns placeholder data entries; partial failures inside a batch; API version drift where the field was renamed.","solutions":["Log the offending img_data object to see which fields the endpoint actually returned","If using a compatible/proxy endpoint, ensure it returns b64_json (set response_format='b64_json') or a valid url per entry","Retry with n=1 to isolate whether only some entries in a batch are malformed","Update or pin the api-node package if the endpoint schema changed and the node's pydantic model is stale"],"exampleFix":"// before\nfor img_data in data:\n    if img_data.b64_json: ...\n    elif img_data.url: ...\n    else:\n        raise ValueError(\"Invalid image payload ...\")\n// after (skip malformed entries, fail only if none decode)\nvalid = [d for d in data if d.b64_json or d.url]\nif not valid:\n    raise ValueError(\"No decodable images in API response\")","handlingStrategy":"type-guard","validationCode":"entries = [d for d in resp.data if getattr(d, \"b64_json\", None) or getattr(d, \"url\", None)]\nif not entries:\n    raise ValueError(\"no decodable image entries in response\")","typeGuard":"def is_valid_image_entry(d) -> bool:\n    return bool(getattr(d, \"b64_json\", None) or getattr(d, \"url\", None))","tryCatchPattern":"try:\n    tensors = await openai_images_to_tensor(resp)\nexcept ValueError as e:\n    if \"neither URL nor base64\" in str(e):\n        # endpoint schema issue: log the raw entry, switch response_format or provider\n        raise\n    raise","preventionTips":["Set response_format=b64_json when using OpenAI-compatible proxies","Validate each data entry has a payload before decoding","Pin known-good provider/API versions behind the proxy"],"tags":["openai","images","api-response","payload"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}