Comfy-Org/ComfyUI · error · ValueError

The current maximum number of supported images is 8.

Error message

The current maximum number of supported images is 8.

What it means

The FLUX 2 (Kontext-style) node enforces BFL's limit of 8 reference images per generation. Because inputs arrive as Autogrow slots that may each hold a batched tensor, the node flattens and counts every frame via get_number_of_images before building input_image_N base64 fields.

Source

Thrown at comfy_api_nodes/nodes_bfl.py:970

        )

    @classmethod
    async def execute(
        cls,
        prompt: str,
        model: dict,
        seed: int,
    ) -> IO.NodeOutput:
        model_choice = model["model"]
        endpoint = _FLUX2_MODEL_ENDPOINTS[model_choice]
        width = model["width"]
        height = model["height"]
        images_dict = model.get("images") or {}

        image_tensors: list[Input.Image] = [t for t in images_dict.values() if t is not None]
        n_images = sum(get_number_of_images(t) for t in image_tensors)
        if n_images > 8:
            raise ValueError("The current maximum number of supported images is 8.")

        flat_tensors: list[torch.Tensor] = []
        for tensor in image_tensors:
            if len(tensor.shape) == 4:
                flat_tensors.extend(tensor[i] for i in range(tensor.shape[0]))
            else:
                flat_tensors.append(tensor)

        reference_images: dict[str, str] = {}
        for idx, tensor in enumerate(flat_tensors):
            key_name = f"input_image_{idx + 1}" if idx else "input_image"
            reference_images[key_name] = tensor_to_base64_string(tensor, total_pixels=2048 * 2048)

        initial_response = await sync_op(
            cls,
            ApiEndpoint(path=endpoint, method="POST"),
            response_model=BFLFluxProGenerateResponse,
            data=Flux2ProGenerateRequest(

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Trim total images (across all slots) to 8 or fewer before the call.
  2. Flatten your tensors first and keep only the ones you actually need.
  3. Split into two node invocations if you have more than 8 references.

Example fix

# before
flat = [t for batch in image_tensors for t in batch]  # 12 images -> ValueError

# after
flat = [t for batch in image_tensors for t in batch][:8]
Defensive patterns

Strategy: validation

Validate before calling

image_tensors = [t for t in (model.get("images") or {}).values() if t is not None]
n = sum(get_number_of_images(t) for t in image_tensors)
assert n <= 8, f"FLUX 2 accepts max 8 images, got {n}"

Type guard

def flux2_refs_ok(images_dict: dict) -> bool:
    return sum(get_number_of_images(t) for t in (images_dict or {}).values() if t is not None) <= 8

Prevention

When it happens

Trigger: Calling a FLUX 2 model node where the sum of image counts across all non-None entries in the images dict exceeds 8 — e.g. two slots of 4-frame batches.

Common situations: Multiple Autogrow image inputs each carrying batches; forgetting that per-slot batches sum toward one shared limit; mixing grids and singletons.

Related errors


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