{"record":{"id":"5dd7992aa30515da","repo":"Comfy-Org/ComfyUI","slug":"the-current-maximum-number-of-supported-images-is-5dd799","errorCode":null,"errorMessage":"The current maximum number of supported images is 8.","messagePattern":"The current maximum number of supported images is 8\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_bfl.py","lineNumber":970,"sourceCode":"        )\n\n    @classmethod\n    async def execute(\n        cls,\n        prompt: str,\n        model: dict,\n        seed: int,\n    ) -> IO.NodeOutput:\n        model_choice = model[\"model\"]\n        endpoint = _FLUX2_MODEL_ENDPOINTS[model_choice]\n        width = model[\"width\"]\n        height = model[\"height\"]\n        images_dict = model.get(\"images\") or {}\n\n        image_tensors: list[Input.Image] = [t for t in images_dict.values() if t is not None]\n        n_images = sum(get_number_of_images(t) for t in image_tensors)\n        if n_images > 8:\n            raise ValueError(\"The current maximum number of supported images is 8.\")\n\n        flat_tensors: list[torch.Tensor] = []\n        for tensor in image_tensors:\n            if len(tensor.shape) == 4:\n                flat_tensors.extend(tensor[i] for i in range(tensor.shape[0]))\n            else:\n                flat_tensors.append(tensor)\n\n        reference_images: dict[str, str] = {}\n        for idx, tensor in enumerate(flat_tensors):\n            key_name = f\"input_image_{idx + 1}\" if idx else \"input_image\"\n            reference_images[key_name] = tensor_to_base64_string(tensor, total_pixels=2048 * 2048)\n\n        initial_response = await sync_op(\n            cls,\n            ApiEndpoint(path=endpoint, method=\"POST\"),\n            response_model=BFLFluxProGenerateResponse,\n            data=Flux2ProGenerateRequest(","sourceCodeStart":952,"sourceCodeEnd":988,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_bfl.py#L952-L988","documentation":"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.","triggerScenarios":"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.","commonSituations":"Multiple Autogrow image inputs each carrying batches; forgetting that per-slot batches sum toward one shared limit; mixing grids and singletons.","solutions":["Trim total images (across all slots) to 8 or fewer before the call.","Flatten your tensors first and keep only the ones you actually need.","Split into two node invocations if you have more than 8 references."],"exampleFix":"# before\nflat = [t for batch in image_tensors for t in batch]  # 12 images -> ValueError\n\n# after\nflat = [t for batch in image_tensors for t in batch][:8]","handlingStrategy":"validation","validationCode":"image_tensors = [t for t in (model.get(\"images\") or {}).values() if t is not None]\nn = sum(get_number_of_images(t) for t in image_tensors)\nassert n <= 8, f\"FLUX 2 accepts max 8 images, got {n}\"","typeGuard":"def flux2_refs_ok(images_dict: dict) -> bool:\n    return sum(get_number_of_images(t) for t in (images_dict or {}).values() if t is not None) <= 8","tryCatchPattern":null,"preventionTips":["The 8-image budget is shared across all Autogrow slots.","Flatten and trim before the call.","Split oversized reference sets into sequential requests."],"tags":["bfl","flux2","reference-images","input-validation","autogrow"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}