Comfy-Org/ComfyUI · error · ValueError
Custom width and height must be multiples of 16, got {custom
Error message
Custom width and height must be multiples of 16, got {custom_width}x{custom_height} What it means
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.
Source
Thrown at comfy_api_nodes/nodes_openai.py:542
background: str = "opaque",
image: Input.Image | None = None,
mask: Input.Image | None = None,
n: int = 1,
size: str = "1024x1024",
custom_width: int = 1024,
custom_height: int = 1024,
model: str = "gpt-image-1",
) -> IO.NodeOutput:
validate_string(prompt, strip_whitespace=False)
if mask is not None and image is None:
raise ValueError("Cannot use a mask without an input image")
if size == "Custom":
if model != "gpt-image-2":
raise ValueError("Custom resolution is only supported by GPT Image 2 model")
if custom_width % 16 != 0 or custom_height % 16 != 0:
raise ValueError(f"Custom width and height must be multiples of 16, got {custom_width}x{custom_height}")
if max(custom_width, custom_height) > 3840:
raise ValueError(f"Custom resolution max edge must be <= 3840, got {custom_width}x{custom_height}")
ratio = max(custom_width, custom_height) / min(custom_width, custom_height)
if ratio > 3:
raise ValueError(
f"Custom resolution aspect ratio must not exceed 3:1, got {custom_width}x{custom_height}"
)
total_pixels = custom_width * custom_height
if not 655_360 <= total_pixels <= 8_294_400:
raise ValueError(
f"Custom resolution total pixels must be between 655,360 and 8,294,400, got {total_pixels}"
)
size = f"{custom_width}x{custom_height}"
elif model in ("gpt-image-1", "gpt-image-1.5"):
if size not in ("auto", "1024x1024", "1024x1536", "1536x1024"):
raise ValueError(f"Resolution {size} is only supported by GPT Image 2 model")
if model == "gpt-image-2":View on GitHub (pinned to 1c6d8d45b3)
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
Example fix
// before custom_width, custom_height = 1000, 620 // after snap = lambda v: round(v / 16) * 16 custom_width, custom_height = snap(1000), snap(620) # 1008x624
Defensive patterns
Strategy: validation
Validate before calling
snap16 = lambda v: (v + 8) // 16 * 16 custom_width, custom_height = snap16(custom_width), snap16(custom_height) assert custom_width % 16 == 0 and custom_height % 16 == 0
Type guard
def is_valid_custom_dims(w: int, h: int) -> bool:
return w % 16 == 0 and h % 16 == 0 Prevention
- 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
When it happens
Trigger: size='Custom' with dimensions like 1000x1000, 1279x720, or any value not divisible by 16.
Common situations: 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.
Related errors
- Custom resolution is only supported by GPT Image 2 model
- Custom resolution max edge must be <= 3840, got {custom_widt
- Custom resolution aspect ratio must not exceed 3:1, got {cus
- Custom resolution total pixels must be between 655,360 and 8
- Resolution {size} is only supported by GPT Image 2 model
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/dd60a85d295c94f8.
Report an issue: GitHub.