{"record":{"id":"5abfb1645dea4544","repo":"Comfy-Org/ComfyUI","slug":"custom-aspect-ratio-is-only-allowed-when-multiple","errorCode":null,"errorMessage":"Custom aspect ratio is only allowed when multiple images are connected to the image input.","messagePattern":"Custom aspect ratio is only allowed when multiple images are connected to the image input\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_grok.py","lineNumber":449,"sourceCode":"    @classmethod\n    async def execute(\n        cls,\n        model: str,\n        image: Input.Image,\n        prompt: str,\n        resolution: str,\n        number_of_images: int,\n        seed: int,\n        aspect_ratio: str = \"auto\",\n    ) -> IO.NodeOutput:\n        validate_string(prompt, strip_whitespace=True, min_length=1)\n        if model == \"grok-imagine-image-pro\":\n            if get_number_of_images(image) > 1:\n                raise ValueError(\"The pro model supports only 1 input image.\")\n        elif get_number_of_images(image) > 3:\n            raise ValueError(\"A maximum of 3 input images is supported.\")\n        if aspect_ratio != \"auto\" and get_number_of_images(image) == 1:\n            raise ValueError(\n                \"Custom aspect ratio is only allowed when multiple images are connected to the image input.\"\n            )\n        response = await sync_op(\n            cls,\n            ApiEndpoint(path=\"/proxy/xai/v1/images/edits\", method=\"POST\"),\n            data=ImageEditRequest(\n                model=model,\n                images=[InputUrlObject(url=f\"data:image/png;base64,{tensor_to_base64_string(i)}\") for i in image],\n                prompt=prompt,\n                resolution=resolution.lower(),\n                n=number_of_images,\n                seed=seed,\n                aspect_ratio=None if aspect_ratio == \"auto\" else aspect_ratio,\n            ),\n            response_model=ImageGenerationResponse,\n        )\n        if len(response.data) == 1:\n            return IO.NodeOutput(await download_url_to_image_tensor(response.data[0].url))","sourceCodeStart":431,"sourceCodeEnd":467,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_grok.py#L431-L467","documentation":"Grok image edit constraint: a custom (non-'auto') aspect_ratio is only accepted when multiple images are connected. With exactly one input image the API derives the output aspect from that image, so requesting a custom ratio with n==1 is rejected client-side. Note the interaction with the pro model: pro allows only 1 image, so pro + custom aspect ratio can never pass this check.","triggerScenarios":"aspect_ratio != 'auto' AND get_number_of_images(image) == 1 — e.g. single image plus aspect_ratio='16:9'.","commonSituations":"Users switching from multi-image to single-image edits and leaving the aspect ratio dropdown set; assuming the ratio control is always available; combining the pro model (1 image max) with a custom ratio.","solutions":["Set aspect_ratio back to 'auto' for single-image edits.","Connect additional images (up to the model's max) if you truly need a custom aspect ratio.","Pre-resize/crop the input image to the target aspect ratio instead of using the node parameter."],"exampleFix":"# before\nawait grok_image_edit(model='grok-imagine-image', image=img1, aspect_ratio='16:9')  # raises\n\n# after\nawait grok_image_edit(model='grok-imagine-image', image=img1, aspect_ratio='auto')","handlingStrategy":"validation","validationCode":"if aspect_ratio != \"auto\":\n    assert get_number_of_images(image) > 1, \"custom aspect ratio needs multiple input images\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reset aspect_ratio to 'auto' whenever you reduce edits to a single image.","Pre-crop the source image when you need a specific output ratio from one image.","Remember the pro model (1 image max) can never use a custom aspect ratio here."],"tags":["grok","xai","image-editing","aspect-ratio","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"}