Comfy-Org/ComfyUI · error · ValueError
Invalid image payload – neither URL nor base64 data present.
Error message
Invalid image payload – neither URL nor base64 data present.
What it means
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.
Source
Thrown at comfy_api_nodes/nodes_openai.py:91
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))
# With size="auto" the API can return images whose dimensions differ by a few pixels within a single response
# resize them to the first image's dimensions so they can be stacked into one batch.
ref_h, ref_w = image_tensors[0].shape[:2]
for i, t in enumerate(image_tensors):
if t.shape[:2] != (ref_h, ref_w):
samples = t.unsqueeze(0).movedim(-1, 1)
samples = common_upscale(samples, ref_w, ref_h, "bilinear", "center")
image_tensors[i] = samples.movedim(1, -1).squeeze(0)
return torch.stack(image_tensors, dim=0)
class OpenAIDalle2(IO.ComfyNode):
View on GitHub (pinned to 1c6d8d45b3)
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
Example fix
// before
for img_data in data:
if img_data.b64_json: ...
elif img_data.url: ...
else:
raise ValueError("Invalid image payload ...")
// after (skip malformed entries, fail only if none decode)
valid = [d for d in data if d.b64_json or d.url]
if not valid:
raise ValueError("No decodable images in API response") Defensive patterns
Strategy: type-guard
Validate before calling
entries = [d for d in resp.data if getattr(d, "b64_json", None) or getattr(d, "url", None)]
if not entries:
raise ValueError("no decodable image entries in response") Type guard
def is_valid_image_entry(d) -> bool:
return bool(getattr(d, "b64_json", None) or getattr(d, "url", None)) Try / catch
try:
tensors = await openai_images_to_tensor(resp)
except ValueError as e:
if "neither URL nor base64" in str(e):
# endpoint schema issue: log the raw entry, switch response_format or provider
raise
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No images returned from API endpoint
- Mask and Image must be the same size
- Dall-E 2 image editing requires an image AND a mask
- Cannot use a mask without an input image
- Custom resolution is only supported by GPT Image 2 model
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/a89ac8bfd2717706.
Report an issue: GitHub.