Comfy-Org/ComfyUI · error · ValueError

Transparent background is not supported for GPT Image 2 mode

Error message

Transparent background is not supported for GPT Image 2 model

What it means

Client-side ValueError: background='transparent' was requested with model='gpt-image-2'. GPT Image 2 does not support transparent background output (unlike gpt-image-1), so the node rejects the combination instead of letting the API fail opaquely.

Source

Thrown at comfy_api_nodes/nodes_openai.py:562

                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")
        elif model not in ("gpt-image-1", "gpt-image-1.5"):
            raise ValueError(f"Unknown model: {model}")

        if image is not None:
            files = []
            batch_size = image.shape[0]
            for i in range(batch_size):
                single_image = image[i : i + 1]
                scaled_image = downscale_image_tensor(single_image, total_pixels=2048 * 2048).squeeze()

                image_np = (scaled_image.numpy() * 255).astype(np.uint8)
                img = Image.fromarray(image_np)
                img_byte_arr = BytesIO()
                img.save(img_byte_arr, format="PNG")
                img_byte_arr.seek(0)

                if batch_size == 1:
                    files.append(("image", (f"image_{i}.png", img_byte_arr, "image/png")))

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Set background to 'opaque' (or 'auto') for gpt-image-2
  2. If you need transparency, use gpt-image-1/1.5 which accept background='transparent'
  3. For GPT Image 2 results, remove the background in post (rembg or a matting node)

Example fix

// before
model="gpt-image-2", background="transparent"
// after
model="gpt-image-2", background="opaque"
// or switch model:
model="gpt-image-1", background="transparent"
Defensive patterns

Strategy: validation

Validate before calling

if model == "gpt-image-2":
    assert background != "transparent", "gpt-image-2 cannot output transparency"

Type guard

def background_valid(model: str, background: str) -> bool:
    return not (model == "gpt-image-2" and background == "transparent")

Prevention

When it happens

Trigger: model='gpt-image-2' with the background widget set to 'transparent' in the OpenAI image node.

Common situations: Copying gpt-image-1 workflows and only changing the model; compositing workflows that assume alpha output is always available.

Related errors


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