{"record":{"id":"dd60a85d295c94f8","repo":"Comfy-Org/ComfyUI","slug":"custom-width-and-height-must-be-multiples-of-16-g","errorCode":null,"errorMessage":"Custom width and height must be multiples of 16, got {custom_width}x{custom_height}","messagePattern":"Custom width and height must be multiples of 16, got (.+?)x(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_openai.py","lineNumber":542,"sourceCode":"        background: str = \"opaque\",\n        image: Input.Image | None = None,\n        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\":","sourceCodeStart":524,"sourceCodeEnd":560,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_openai.py#L524-L560","documentation":"Client-side ValueError: with size='Custom' on gpt-image-2, custom_width or custom_height is not a multiple of 16. The GPT Image 2 API requires dimensions aligned to 16px, and the node validates this (custom_width % 16 or custom_height % 16) before building the size string.","triggerScenarios":"size='Custom' with dimensions like 1000x1000, 1279x720, or any value not divisible by 16.","commonSituations":"Typing round decimal sizes (e.g. 1000) out of habit; computing width from an aspect ratio without rounding to 16px; copying dimensions from another model's allowed sizes.","solutions":["Round each dimension to the nearest multiple of 16 (e.g. 1000 -> 1008, 1279 -> 1280)","Compute sizes as (value // 16) * 16 wherever the workflow is generated programmatically","Use known-good pairs like 1024x1024, 1280x768, 1536x1024"],"exampleFix":"// before\ncustom_width, custom_height = 1000, 620\n// after\nsnap = lambda v: round(v / 16) * 16\ncustom_width, custom_height = snap(1000), snap(620)  # 1008x624","handlingStrategy":"validation","validationCode":"snap16 = lambda v: (v + 8) // 16 * 16\ncustom_width, custom_height = snap16(custom_width), snap16(custom_height)\nassert custom_width % 16 == 0 and custom_height % 16 == 0","typeGuard":"def is_valid_custom_dims(w: int, h: int) -> bool:\n    return w % 16 == 0 and h % 16 == 0","tryCatchPattern":null,"preventionTips":["Snap any computed dimension to 16px before use","Keep a list of known-good 16-aligned sizes (1024x1024, 1280x768, 1536x1024)","Never hand-type sizes like 1000 - always multiples of 16"],"tags":["openai","gpt-image","resolution","validation","alignment"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}