Nodes/RUI-Nodes/OpenAI API 连接 / OpenAI API Connector
ComfyUI Node

OpenAI API 连接 / OpenAI API Connector

A chat-completions box that can also read your images

By rui40000·Created 3 years ago·Updated 13 days ago· 17
OpenAI API 连接 / OpenAI API Connector
  • image_1
  • image_2
  • image_3
  • image_4
  • image_5
  • image_6
  • text
protocolhttps
api_urlapi.openai.com/v1/chat/completions
api_key
modelgpt-4o
system_promptYou are a helpful assistant.
user_prompt
seed0
temperature0.3
max_tokens500
detailauto
image_max_size1024
proxy_url

The OpenAI API Connector is the workhorse of the RUI-Nodes pack's AI section: a node that sends text (and optionally up to six images) to any OpenAI-compatible chat-completions endpoint and returns the model's reply as a string. "Any compatible endpoint" is doing the heavy lifting here - the api_url and model fields are just strings, so besides OpenAI itself it works with DeepSeek, Moonshot, local Ollama servers, LM Studio, and every other API that speaks the OpenAI dialect. If you've got an LLM anywhere reachable by HTTP, this node can talk to it.

It earns its keep in ComfyUI workflows where you need a model to look at something: caption a generated image, compare two renders and pick the better one, summarize a prompt, or gate a step on a visual judgment. The image inputs are what make it interesting - this isn't just a text box, it's a vision-model client.

How it works

You give it a user_prompt (and optionally a system_prompt), and the node builds a chat request. The images are optional: plug image_1 through image_6 into whichever of the six inputs you have frames for. The detail here is thoughtful - each image is encoded separately and downscaled to a max long-edge of image_max_size (default 1024) before sending, which keeps token cost and payload size in check. And because each image is handled independently, they don't need to be the same resolution - a 512×512 and a 511×768 can be sent together, which standard batch-to-one-image nodes would choke on.

The inputs you'll actually set:

  • api_url + protocol (https/http) - the endpoint. Default is api.openai.com/v1/chat/completions.
  • api_key - your key. Saved in the workflow JSON, same as its sibling node - scrub before sharing.
  • model - anything the endpoint accepts; default gpt-4o.
  • user_prompt / system_prompt - what to ask.
  • temperature (default 0.3), max_tokens (default 500), detail (low/high/auto) - standard API sampling knobs.
  • proxy_url - for routing through a proxy, which the target audience for this pack will recognize as the difference between "works" and "connection refused."

Output is a single text string. Wire it into a text display, a save node, or back into a prompt.

Installing it

Part of RUI-Nodes ("Rui-Node🐶") - install once via ComfyUI Manager (search "RUI-Nodes") or:

cd ComfyUI/custom_nodes
git clone https://github.com/rui40000/RUI-Nodes
cd RUI-Nodes
pip install -r requirements.txt

Restart after. It needs requests and Pillow, both already in the pack's requirements.

Where people get burned

The usual cloud-API suspects: the key living in the workflow file, network egress needing a proxy in some regions, and cost on vision calls (images at high detail burn tokens fast - low or a smaller image_max_size helps). Also note the node deliberately clears proxy environment variables on load so a system-level proxy doesn't break requests - if your setup relies on an env proxy, use the proxy_url field instead of the environment. And one quiet behavior: if you leave user_prompt empty for pure text, some endpoints will just echo - give it a real prompt, the way you would any LLM.

CategoryRui-Node🐶/AI模型🤖

Inputs (18)

NameTypeDefaultDescription
protocolCOMBOhttps接口协议。之所以单独做成下拉而不写进地址栏: ComfyUI 前端会吞掉文本框里的 "://" 片段, 协议只能由后端拼接。
api_urlSTRINGapi.openai.com/v1/chat/completions接口地址,**不要带 http:// 或 https://**(协议见上方下拉)。 只填域名和路径,例如 api.openai.com/v1/chat/completions。 第三方中转填对应的域名即可。
api_keySTRINGAPI 密钥。 ⚠ 工作流会连同此值一起保存,分享 json 前记得清空。
modelSTRINGgpt-4o模型名,按服务商文档填写。 要传图就必须选支持视觉的型号,否则图会被忽略或直接报错。
system_promptSTRINGYou are a helpful assistant.系统提示词:设定模型的角色与总体行为准则。 输出格式要求(如「只返回 JSON」)写在这里比写在用户 提示词里更稳定。
user_promptSTRING用户提示词:这一次具体要模型做什么。 接了图像时,在这里描述针对图像的任务。
seedINT00–18446744073709550000随机种子。多数服务商并不真正支持复现, 这里主要用于强制节点重新执行(改了它就不会走缓存)。
image_1optIMAGE要一并发给模型的图像 1(需模型支持视觉)。 会按下方的最大边长压缩后转 base64 提交。
image_2optIMAGE图像 2。
image_3optIMAGE图像 3。
image_4optIMAGE图像 4。
image_5optIMAGE图像 5。
image_6optIMAGE图像 6。图越多越贵、越慢。
temperatureoptFLOAT0.30–2采样温度:越低越稳定保守,越高越发散。 要结构化/可解析的输出用 0~0.3; 要创意文案用 0.7~1.0。超过 1.2 常出现胡言乱语。
max_tokensoptINT5001–8192回复的最大长度上限。 设小了会把回答从中间截断,长文任务记得调大。
detailoptCOMBOauto图像细节级别(OpenAI 视觉参数): low 便宜快速,只看大致内容; high 会切块细看,认小字/细节更准但更贵; auto 由服务端决定。
image_max_sizeoptINT1024256–4096上传前把图缩放到的最大边长。 调小可显著省钱提速,但小字与细节会看不清。
proxy_urloptSTRINGHTTP 代理,**同样不要带协议前缀**,只填 IP:端口, 例如 127.0.0.1:7890。留空表示直连。

Outputs (1)

NameTypeDescription
textSTRING