{"record":{"id":"2bc6069b9e194f1d","repo":"Comfy-Org/ComfyUI","slug":"at-least-one-image-is-required-for-editing","errorCode":null,"errorMessage":"At least one image is required for editing.","messagePattern":"At least one image is required for editing\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_grok.py","lineNumber":584,"sourceCode":"    @classmethod\n    async def execute(\n        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(","sourceCodeStart":566,"sourceCodeEnd":602,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_grok.py#L566-L602","documentation":"Dict-driven Grok image edit node requires at least one connected image: it collects non-None tensors from model['images'], sums their image counts, and n_images < 1 raises. All image sockets empty (or explicitly None) means the edit request would have no source image, which the xAI edits endpoint cannot process.","triggerScenarios":"Executing the model-dict grok image edit with model['images'] empty or every value None — nothing wired into any image socket.","commonSituations":"Workflow saved with image inputs that reference missing files; upstream node silently produced an empty dict; users attempting prompt-only generation through an edit node instead of a generation node.","solutions":["Connect at least one image to the node's image input(s).","Verify the upstream image node actually produced output (not None/empty).","Use a text-to-image Grok node if no source image is intended."],"exampleFix":"# before\nmodel['images'] = {}  # nothing connected -> raises\nawait grok_edit_execute(model, seed=1)\n\n# after\nmodel['images'] = {'image_1': load_image('src.png')}\nawait grok_edit_execute(model, seed=1)","handlingStrategy":"validation","validationCode":"n = sum(get_number_of_images(t) for t in (model.get(\"images\") or {}).values() if t is not None)\nassert n >= 1, \"connect at least one image to the edit node\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check upstream image nodes produce non-None output before running the edit.","Use a generation (not edit) node when no source image is intended.","Fail workflows early when the images dict is empty."],"tags":["grok","xai","image-editing","input-validation","comfy-api-nodes"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}