{"record":{"id":"ea784d1bebb9e782","repo":"Comfy-Org/ComfyUI","slug":"custom-resolution-max-edge-must-be-3840-got-c","errorCode":null,"errorMessage":"Custom resolution max edge must be <= 3840, got {custom_width}x{custom_height}","messagePattern":"Custom resolution max edge must be <= 3840, got (.+?)x(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_openai.py","lineNumber":544,"sourceCode":"        mask: Input.Image | None = None,\n        n: int = 1,\n        size: str = \"1024x1024\",\n        custom_width: int = 1024,\n        custom_height: int = 1024,\n        model: str = \"gpt-image-1\",\n    ) -> IO.NodeOutput:\n        validate_string(prompt, strip_whitespace=False)\n\n        if mask is not None and image is None:\n            raise ValueError(\"Cannot use a mask without an input image\")\n\n        if size == \"Custom\":\n            if model != \"gpt-image-2\":\n                raise ValueError(\"Custom resolution is only supported by GPT Image 2 model\")\n            if custom_width % 16 != 0 or custom_height % 16 != 0:\n                raise ValueError(f\"Custom width and height must be multiples of 16, got {custom_width}x{custom_height}\")\n            if max(custom_width, custom_height) > 3840:\n                raise ValueError(f\"Custom resolution max edge must be <= 3840, got {custom_width}x{custom_height}\")\n            ratio = max(custom_width, custom_height) / min(custom_width, custom_height)\n            if ratio > 3:\n                raise ValueError(\n                    f\"Custom resolution aspect ratio must not exceed 3:1, got {custom_width}x{custom_height}\"\n                )\n            total_pixels = custom_width * custom_height\n            if not 655_360 <= total_pixels <= 8_294_400:\n                raise ValueError(\n                    f\"Custom resolution total pixels must be between 655,360 and 8,294,400, got {total_pixels}\"\n                )\n            size = f\"{custom_width}x{custom_height}\"\n        elif model in (\"gpt-image-1\", \"gpt-image-1.5\"):\n            if size not in (\"auto\", \"1024x1024\", \"1024x1536\", \"1536x1024\"):\n                raise ValueError(f\"Resolution {size} is only supported by GPT Image 2 model\")\n\n        if model == \"gpt-image-2\":\n            if background == \"transparent\":\n                raise ValueError(\"Transparent background is not supported for GPT Image 2 model\")","sourceCodeStart":526,"sourceCodeEnd":562,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_openai.py#L526-L562","documentation":"Client-side ValueError: a Custom resolution dimension exceeds the 3840px cap (max(custom_width, custom_height) > 3840). GPT Image 2 rejects edges over 3840, so the node checks it up front, before the aspect-ratio and total-pixel checks that follow.","triggerScenarios":"size='Custom' with values like 4096x2160 or 3841x2160 on gpt-image-2.","commonSituations":"Requesting 4K-class generation (4096) which the API does not support; upscaling workflows assuming arbitrary dimensions are accepted.","solutions":["Cap the longer edge at 3840 (e.g. 3840x2160, 2160x3840)","Upscale locally after generation if you need larger output","Re-check that both dimensions are still multiples of 16 after clamping"],"exampleFix":"// before\ncustom_width, custom_height = 4096, 2160\n// after\ncustom_width, custom_height = 3840, 2160","handlingStrategy":"validation","validationCode":"if max(custom_width, custom_height) > 3840:\n    scale = 3840 / max(custom_width, custom_height)\n    custom_width = round(custom_width * scale / 16) * 16\n    custom_height = round(custom_height * scale / 16) * 16","typeGuard":"def within_max_edge(w: int, h: int) -> bool:\n    return max(w, h) <= 3840","tryCatchPattern":null,"preventionTips":["Treat 3840 as a hard ceiling on the long edge","Upscale locally after generation for 4K+ outputs","Re-check 16-alignment after any clamping"],"tags":["openai","gpt-image","resolution","validation","limits"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}