{"record":{"id":"610abdc54089f11d","repo":"Comfy-Org/ComfyUI","slug":"the-model-id-model-supports-at-most-max-images","errorCode":null,"errorMessage":"The {model_id} model supports at most {max_images} input image{'s' if max_images > 1 else ''}; {n_images} are connected.","messagePattern":"The (.+?) model supports at most (.+?) input image(.+?); (.+?) are connected\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_grok.py","lineNumber":586,"sourceCode":"        cls,\n        prompt: str,\n        model: dict,\n        seed: int,\n    ) -> IO.NodeOutput:\n        validate_string(prompt, strip_whitespace=True, min_length=1)\n        model_id = model[\"model\"]\n        resolution = model[\"resolution\"]\n        number_of_images = model[\"number_of_images\"]\n        images_dict = model.get(\"images\") or {}\n        aspect_ratio = model.get(\"aspect_ratio\", \"auto\")\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        max_images = _GROK_IMAGE_EDIT_MAX_IMAGES.get(model_id, 3)\n        if n_images < 1:\n            raise ValueError(\"At least one image is required for editing.\")\n        if n_images > max_images:\n            raise ValueError(\n                f\"The {model_id} model supports at most {max_images} input \"\n                f\"image{'s' if max_images > 1 else ''}; {n_images} are connected.\"\n            )\n        if aspect_ratio != \"auto\" and model_id in _GROK_IMAGE_EDIT_ASPECT_RATIO_NEEDS_MULTIPLE and n_images == 1:\n            raise ValueError(\n                \"Custom aspect ratio is only allowed when multiple images are connected to the image input.\"\n            )\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        response = await sync_op(\n            cls,\n            ApiEndpoint(path=\"/proxy/xai/v1/images/edits\", method=\"POST\"),","sourceCodeStart":568,"sourceCodeEnd":604,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_grok.py#L568-L604","documentation":"Per-model input image cap in the dict-driven Grok image edit node. _GROK_IMAGE_EDIT_MAX_IMAGES maps grok-imagine-image-pro to 1 and the other grok image models to 3 (fallback 3). The summed image count across all connected tensors is compared against the selected model's cap, and exceeding it reports both the cap and the connected count.","triggerScenarios":"n_images = sum(get_number_of_images(t)) over connected tensors exceeds _GROK_IMAGE_EDIT_MAX_IMAGES[model_id] — e.g. 2 images with pro (cap 1) or 4 images with grok-imagine-image (cap 3).","commonSituations":"Changing the model dropdown to pro without trimming inputs; batched tensors whose batch dimension silently multiplies the count; workflows shared between models with different caps.","solutions":["Trim connected images to the model's cap (1 for pro, 3 for others).","Switch to a model whose cap fits your input count.","Slice batched tensors so the summed count fits."],"exampleFix":"# before: model_id='grok-imagine-image-pro', 2 images connected\nawait grok_edit_execute(model={'model': 'grok-imagine-image-pro', 'images': {'a': i1, 'b': i2}, ...}, seed=1)  # raises\n\n# after: keep only the primary reference\nawait grok_edit_execute(model={'model': 'grok-imagine-image-pro', 'images': {'a': i1}, ...}, seed=1)","handlingStrategy":"validation","validationCode":"CAPS = {\"grok-imagine-image-2.0\": 3, \"grok-imagine-image-pro\": 1,\n       \"grok-imagine-image-quality\": 3, \"grok-imagine-image\": 3}\nn = sum(get_number_of_images(t) for t in tensors if t is not None)\nassert n <= CAPS.get(model_id, 3), f\"{n} images > cap {CAPS.get(model_id, 3)} for {model_id}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Re-validate image count whenever the model dropdown changes.","Treat pro as a 1-image model in workflow validation logic.","Count the batch dimension of every tensor, not just the number of wires."],"tags":["grok","xai","image-editing","input-validation","limit","comfy-api-nodes"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}