Comfy-Org/ComfyUI · error · ValueError

The maximum number of reference images allowed is 6.

Error message

The maximum number of reference images allowed is 6.

What it means

Raised by OmniProFirstLastFrameNode.execute when the reference_images batch contains more than 6 images. The Kling omni API caps omni reference images at 6 per request for this node; the count is checked with get_number_of_images before upload so no bandwidth is wasted.

Source

Thrown at comfy_api_nodes/nodes_kling.py:936

        validate_image_aspect_ratio(first_frame, (1, 2.5), (2.5, 1))
        image_list: list[OmniParamImage] = [
            OmniParamImage(
                image_url=(await upload_images_to_comfyapi(cls, first_frame, wait_label="Uploading first frame"))[0],
                type="first_frame",
            )
        ]
        if end_frame is not None:
            validate_image_dimensions(end_frame, min_width=300, min_height=300)
            validate_image_aspect_ratio(end_frame, (1, 2.5), (2.5, 1))
            image_list.append(
                OmniParamImage(
                    image_url=(await upload_images_to_comfyapi(cls, end_frame, wait_label="Uploading end frame"))[0],
                    type="end_frame",
                )
            )
        if reference_images is not None:
            if get_number_of_images(reference_images) > 6:
                raise ValueError("The maximum number of reference images allowed is 6.")
            for i in reference_images:
                validate_image_dimensions(i, min_width=300, min_height=300)
                validate_image_aspect_ratio(i, (1, 2.5), (2.5, 1))
            for i in await upload_images_to_comfyapi(cls, reference_images, wait_label="Uploading reference frame(s)"):
                image_list.append(OmniParamImage(image_url=i))
        if resolution == "4k":
            mode = "4k"
        elif resolution == "1080p":
            mode = "pro"
        else:
            mode = "std"
        response = await sync_op(
            cls,
            ApiEndpoint(path="/proxy/kling/v1/videos/omni-video", method="POST"),
            response_model=TaskStatusResponse,
            data=OmniProFirstLastFrameRequest(
                model_name=model_name,
                prompt=prompt,

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Trim the reference batch to at most 6 images (e.g. ImageConcatFromBatch / batch slice with count<=6)
  2. Keep only the most representative reference frames; more references rarely help and cost upload time
  3. If you need more references, run two generations and pick the better result

Example fix

# before
reference_images = LoadImageBatch.from_folder("turnaround/*").images  # 9 images

# after
reference_images = LoadImageBatch.from_folder("turnaround/*").images[:6]  # <= 6
Defensive patterns

Strategy: validation

Validate before calling

def reference_count_ok_first_last(reference_images) -> bool:
    return reference_images is None or get_number_of_images(reference_images) <= 6

Prevention

When it happens

Trigger: Connecting an image batch (folder-of-images load, ImageConcatFromBatch, etc.) with 7 or more frames to reference_images on the OmniPro first/last frame node.

Common situations: Loading a whole character turnaround folder or upscaling the batch size on an upstream node pushes the reference count over 6 without the user noticing the batch grew.

Related errors


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