Nodes/GPT-Image (OpenAI-compatible)/GPT-Image 生成 (文生图)
ComfyUI Node

GPT-Image 生成 (文生图)

The node that calls OpenAI (or any compatible gateway) for you

By meomeo-dev·Created 2 months ago·Updated about a month ago· 1
GPT-Image 生成 (文生图)
  • 配置
  • 图像
提示词
模型gpt-image-2
0
0
数量0
质量default
背景default
输出格式default
压缩质量100
审核级别default
流式false
流式预览数2
超时秒数900
重试次数2
返回格式default

The node for the model you're not allowed to download

GPT Image 2 has no open weights. No checkpoint to drag into your models folder, no GGUF, nothing - the only door into it is an API call, and if you've been around since spring 2026 you know the community reaction: people posting gpt-image-2 results and asking flatly whether anything local can still do this. That's what this node is for. It takes a prompt on your canvas, calls an OpenAI-compatible image API, and drops the returned image back into the graph like a sampler that just finished. From the outside it looks like any generator node; underneath it's an HTTP client wearing your API key.

It's the display name "GPT-Image 生成 (文生图)" in the pack. Same pack also ships the edit, config, and size-snap nodes; this one is the text-to-image endpoint.

What it actually does

GPTImageGenerate POSTs to {base_url}/images/generations with your prompt, model, and size, reads the b64_json out of the response, and hands you an IMAGE tensor on the 「图像」 output. That output wires straight into Preview/Save Image or any local post-processing node - so you can run the closed model next to your local upscaler and masking without leaving the graph.

Two details explain how it behaves. First, it deliberately disables ComfyUI's output cache, so re-running an identical prompt calls the API again instead of replaying last time's image. That's not a bug - API generation is nondeterministic, and caching it would be wrong. Second, validation happens before the request leaves, keyed on the model name. Known official models get hard checks (gpt-image-2 needs 16-multiple dimensions, a long:short ratio under 3:1, longest edge ≤ 3840, and 655,360–8,294,400 total pixels). Unknown model names on your own gateway get a soft pass with a warning, so weird endpoints don't break.

The inputs that matter

You only really set four things. 「配置」 is the config output from the pack's ImageAPIConfig node - your base_url and key ride that wire. 「提示词」 is the prompt, multiline. 「模型」 defaults to gpt-image-2 and you can change it to whatever your gateway serves. 「宽」 and 「高」 both default to 0, and 0 = auto - the server picks the size. Fill in real values and they get sent as 宽x高; this is where the 16-multiple rule bites, and where the pack's GPTImageSizeSnap node earns its keep.

Everything else has a clever default: the enums (「质量」, 「背景」, 「输出格式」, 「审核级别」, 「返回格式」) and 「数量」 all use default/0 to mean don't send this field at all. Fewer fields means fewer ways a picky compatible gateway can 400 you. Two you'll actually touch: 「数量」 2–10 for a batch (sizes must match to merge), and 「返回格式」 → b64_json if your gateway only returns image URLs and downloads keep failing.

Install

Lightest dependency list you'll see from a cloud-calling pack: requests, Pillow, numpy. No model downloads, because there are no weights. ComfyUI Manager can grab it if you search the pack title, or the manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/meomeo-dev/custom-gpt-image-2-api.git
cd custom-gpt-image-2-api
# use ComfyUI's own python, not your system env
pip install -r requirements.txt

Restart ComfyUI, refresh the browser, and grep the startup log for custom-gpt-image-2-api to confirm there's no import failed.

Where people get burned

Mostly at the gateway, not the node. 401 means the key is wrong; 400 usually means a model name or parameter your server won't accept. The error message is the useful part: it gives you status code, a distilled reason pulled from the body, diagnostic headers (like cf-ray), and a printout of the exact fields it sent - so you can tell at a glance whether n went out as an integer or a string. The full response body lands in the ComfyUI console log.

Slow generations are the other trap. A single image can take minutes, and proxies idle-timeout connections that see no traffic. Raise 「超时秒数」 toward its 3600 cap if you must, but the real fix is 「流式」 (streaming), which keeps the connection alive with SSE partial-image events and falls back to plain JSON if your gateway doesn't stream. Retries cover 429, 5xx, and the 520–527 Cloudflare edge codes; 4xx never retry, because retrying a bad request is pointless.

One last note, because this category earned its suspicion: API-wrapper nodes are exactly the shape of the thing that shipped credential-stealing malware once in this ecosystem. This pack sends your prompt and key only to the base_url you typed, has no preset domains and no telemetry, and the key never gets serialized into your saved workflow. Still, it's a small, fast-moving pack by an author you won't find discussed anywhere - glance at the code before you paste a real key into it. That's not paranoia, that's the checklist for this whole category.

CategoryGPT-Image

Inputs (16)

NameTypeDefaultDescription
配置IMAGE_API_CONFIG
提示词STRING
模型STRINGgpt-image-2
INT00–3840
INT00–3840
数量optINT00–10一次生成几张。0 = 不发送 n 字段,由服务端定(通常 1),兼容性最好;要一次多张就填 2~10。若网关报 `n 必须是…整数` 之类的 400,保持 0。
质量optCOMBOdefault5 options: default, auto, high, medium, low
背景optCOMBOdefault4 options: default, auto, transparent, opaque
输出格式optCOMBOdefault4 options: default, png, jpeg, webp
压缩质量optINT1000–100仅对「输出格式」为 jpeg/webp 生效(png/default 会忽略)。数值=保留的画质百分比:越高画质越好、文件越大;越低压缩越强、文件越小、画质越差。默认 100=最高画质。注意它只影响文件编码,不影响生成画面(画面质量由「质量」控制)。
审核级别optCOMBOdefault3 options: default, auto, low
流式optBOOLEANfalse
流式预览数optINT20–3
超时秒数optINT90030–3600
重试次数optINT20–5遇到 429/5xx/超时/连接重置时的最大重试次数。0=不重试。总请求次数 = 重试次数 + 1。也用于「从网关图床下载成品图」那一步的重试。上游高峰不稳时建议 3~5。注意:4xx(参数错误/审核拦截)不会重试,重试也没用。
返回格式optCOMBOdefaultdefault=不发送该字段(官方接口必须用这个:官方 GPT-Image 恒返回 base64,发送此字段反而会 400)。 b64_json=要求图片以内联 base64 返回:仅用于「只回图片 url 的兼容网关」——可绕开网关图床,解决『图已生成但下载失败(504)』以及 数量>1 时更容易失败的问题。 url=要求返回链接(一般不需要)。

Outputs (1)

NameTypeDescription
图像IMAGE