Comfy-Org/ComfyUI · error · ValueError

Custom resolution max edge must be <= 3840, got {custom_widt

Error message

Custom resolution max edge must be <= 3840, got {custom_width}x{custom_height}

What it means

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.

Source

Thrown at comfy_api_nodes/nodes_openai.py:544

        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":
            if background == "transparent":
                raise ValueError("Transparent background is not supported for GPT Image 2 model")

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Cap the longer edge at 3840 (e.g. 3840x2160, 2160x3840)
  2. Upscale locally after generation if you need larger output
  3. Re-check that both dimensions are still multiples of 16 after clamping

Example fix

// before
custom_width, custom_height = 4096, 2160
// after
custom_width, custom_height = 3840, 2160
Defensive patterns

Strategy: validation

Validate before calling

if max(custom_width, custom_height) > 3840:
    scale = 3840 / max(custom_width, custom_height)
    custom_width = round(custom_width * scale / 16) * 16
    custom_height = round(custom_height * scale / 16) * 16

Type guard

def within_max_edge(w: int, h: int) -> bool:
    return max(w, h) <= 3840

Prevention

When it happens

Trigger: size='Custom' with values like 4096x2160 or 3841x2160 on gpt-image-2.

Common situations: Requesting 4K-class generation (4096) which the API does not support; upscaling workflows assuming arbitrary dimensions are accepted.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/ea784d1bebb9e782. Report an issue: GitHub.