Comfy-Org/ComfyUI · error · ValueError

A maximum of 3 input images is supported.

Error message

A maximum of 3 input images is supported.

What it means

Grok image edit validation for non-pro models: at most 3 input images are supported. Applies to every model other than grok-imagine-image-pro in this execute path (which itself has the stricter 1-image rule). Counted via get_number_of_images, so batched tensors count per image.

Source

Thrown at comfy_api_nodes/nodes_grok.py:447

        )

    @classmethod
    async def execute(
        cls,
        model: str,
        image: Input.Image,
        prompt: str,
        resolution: str,
        number_of_images: int,
        seed: int,
        aspect_ratio: str = "auto",
    ) -> IO.NodeOutput:
        validate_string(prompt, strip_whitespace=True, min_length=1)
        if model == "grok-imagine-image-pro":
            if get_number_of_images(image) > 1:
                raise ValueError("The pro model supports only 1 input image.")
        elif get_number_of_images(image) > 3:
            raise ValueError("A maximum of 3 input images is supported.")
        if aspect_ratio != "auto" and get_number_of_images(image) == 1:
            raise ValueError(
                "Custom aspect ratio is only allowed when multiple images are connected to the image input."
            )
        response = await sync_op(
            cls,
            ApiEndpoint(path="/proxy/xai/v1/images/edits", method="POST"),
            data=ImageEditRequest(
                model=model,
                images=[InputUrlObject(url=f"data:image/png;base64,{tensor_to_base64_string(i)}") for i in image],
                prompt=prompt,
                resolution=resolution.lower(),
                n=number_of_images,
                seed=seed,
                aspect_ratio=None if aspect_ratio == "auto" else aspect_ratio,
            ),
            response_model=ImageGenerationResponse,
        )

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Trim inputs to at most 3 images (slice batched tensors).
  2. Choose the most relevant reference images and drop the rest.
  3. Run multiple edits and composite results downstream if more references are truly needed.

Example fix

# before
await grok_image_edit(model='grok-imagine-image', image=batch5)  # raises

# after
await grok_image_edit(model='grok-imagine-image', image=batch5[:3])
Defensive patterns

Strategy: validation

Validate before calling

assert get_number_of_images(image) <= 3, "grok image edit accepts at most 3 images"

Prevention

When it happens

Trigger: Calling grok image edit with a non-pro model and get_number_of_images(image) > 3 — e.g. a 4-frame batch tensor or 4 separate images combined into one input.

Common situations: Frame-grid or multi-reference workflows ported from other providers (e.g. Gemini's 14-image allowance); upscaled batches accidentally left connected; assuming the limit is per-run output count rather than input count.

Related errors


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