Comfy-Org/ComfyUI · error · ValueError

The current maximum number of supported images is 14.

Error message

The current maximum number of supported images is 14.

What it means

Client-side validation in the Gemini image generation node (single-input variant): the connected image input batch contains more than 14 images, which is the API's current maximum number of reference images for image generation/editing. The count is computed with get_number_of_images, so a batched tensor of N images counts as N. It fails before any network call.

Solutions

  1. Split the input into batches of at most 14 images and run the node multiple times.
  2. Trim the source list/tensor to the 14 most relevant images before connecting it.
  3. If using a batched tensor, slice it: images[:14].

Example fix

# before
await generate(prompt, images=all_frames)  # all_frames has 20 images -> raises

# after
await generate(prompt, images=all_frames[:14])
Defensive patterns

Strategy: validation

Validate before calling

from comfy_api_nodes.nodes_gemini import get_number_of_images  # conceptually
n = get_number_of_images(images)
assert n <= 14, f"{n} images connected; Gemini allows at most 14"

Prevention

When it happens

Trigger: Executing GeminiImageGenerator-style node with an images input where get_number_of_images(images) > 14 — e.g. one batched tensor of 15+ frames or several tensors whose total exceeds 14.

Common situations: Feeding a video frame batch or image grid directly into the reference image input; chaining a load-image-folder node that emits 20 images; iterating workflows where batch size was tuned for a different model's higher limit.

Related errors


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

Appendix: source

Thrown at comfy_api_nodes/nodes_gemini.py:1125

        model: str,
        seed: int,
        aspect_ratio: str,
        resolution: str,
        response_modalities: str,
        images: Input.Image | None = None,
        files: list[GeminiPart] | None = None,
        system_prompt: str = "",
    ) -> IO.NodeOutput:
        validate_string(prompt, strip_whitespace=True, min_length=1)
        if model == "Nano Banana 2 (Gemini 3.1 Flash Image)":
            model = "gemini-3.1-flash-image"
        elif model == "gemini-3-pro-image-preview":
            model = "gemini-3-pro-image"

        parts: list[GeminiPart] = [GeminiPart(text=prompt)]
        if images is not None:
            if get_number_of_images(images) > 14:
                raise ValueError("The current maximum number of supported images is 14.")
            parts.extend(await create_image_parts(cls, images))
        if files is not None:
            parts.extend(files)

        image_config = GeminiImageConfig(imageSize=resolution)
        if aspect_ratio != "auto":
            image_config.aspectRatio = aspect_ratio

        gemini_system_prompt = None
        if system_prompt:
            gemini_system_prompt = GeminiSystemInstructionContent(parts=[GeminiTextPart(text=system_prompt)], role=None)

        response = await sync_op(
            cls,
            ApiEndpoint(path=f"/proxy/vertexai/gemini/{model}", method="POST"),
            data=GeminiImageGenerateContentRequest(
                contents=[
                    GeminiContent(role=GeminiRole.user, parts=parts),

View on GitHub (pinned to 1c6d8d45b3)