{"record":{"id":"ec0b758906743055","repo":"Comfy-Org/ComfyUI","slug":"the-maximum-number-of-reference-images-allowed-is","errorCode":null,"errorMessage":"The maximum number of reference images allowed is 6.","messagePattern":"The maximum number of reference images allowed is 6\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_kling.py","lineNumber":936,"sourceCode":"        validate_image_aspect_ratio(first_frame, (1, 2.5), (2.5, 1))\n        image_list: list[OmniParamImage] = [\n            OmniParamImage(\n                image_url=(await upload_images_to_comfyapi(cls, first_frame, wait_label=\"Uploading first frame\"))[0],\n                type=\"first_frame\",\n            )\n        ]\n        if end_frame is not None:\n            validate_image_dimensions(end_frame, min_width=300, min_height=300)\n            validate_image_aspect_ratio(end_frame, (1, 2.5), (2.5, 1))\n            image_list.append(\n                OmniParamImage(\n                    image_url=(await upload_images_to_comfyapi(cls, end_frame, wait_label=\"Uploading end frame\"))[0],\n                    type=\"end_frame\",\n                )\n            )\n        if reference_images is not None:\n            if get_number_of_images(reference_images) > 6:\n                raise ValueError(\"The maximum number of reference images allowed is 6.\")\n            for i in reference_images:\n                validate_image_dimensions(i, min_width=300, min_height=300)\n                validate_image_aspect_ratio(i, (1, 2.5), (2.5, 1))\n            for i in await upload_images_to_comfyapi(cls, reference_images, wait_label=\"Uploading reference frame(s)\"):\n                image_list.append(OmniParamImage(image_url=i))\n        if resolution == \"4k\":\n            mode = \"4k\"\n        elif resolution == \"1080p\":\n            mode = \"pro\"\n        else:\n            mode = \"std\"\n        response = await sync_op(\n            cls,\n            ApiEndpoint(path=\"/proxy/kling/v1/videos/omni-video\", method=\"POST\"),\n            response_model=TaskStatusResponse,\n            data=OmniProFirstLastFrameRequest(\n                model_name=model_name,\n                prompt=prompt,","sourceCodeStart":918,"sourceCodeEnd":954,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_kling.py#L918-L954","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Trim the reference batch to at most 6 images (e.g. ImageConcatFromBatch / batch slice with count<=6)","Keep only the most representative reference frames; more references rarely help and cost upload time","If you need more references, run two generations and pick the better result"],"exampleFix":"# before\nreference_images = LoadImageBatch.from_folder(\"turnaround/*\").images  # 9 images\n\n# after\nreference_images = LoadImageBatch.from_folder(\"turnaround/*\").images[:6]  # <= 6","handlingStrategy":"validation","validationCode":"def reference_count_ok_first_last(reference_images) -> bool:\n    return reference_images is None or get_number_of_images(reference_images) <= 6","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cap reference batches at 6 for this node with an explicit slice","Log the batch size coming out of folder loaders; hidden files inflate counts"],"tags":["kling","video","reference-images","limit","validation","api-nodes"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}