Nodes/comfyui-aichat/OpenAI 图像编码器
ComfyUI Node

OpenAI 图像编码器

Give a vision model a look at your canvas

By spawner1145·Created about a year ago·Updated 11 days ago· 3
OpenAI 图像编码器
  • image
  • content_item
  • base64_string
detailauto
formatjpeg
quality85

The vision adapter for chat-completions

Same idea as the Gemini encoder, different wire format. OpenAIImageEncoder takes an IMAGE tensor and wraps it as a data URL in the shape OpenAI-compatible vision models expect - {"input_image": {"image_url": "data:...;base64,...", "detail": ...}}. Then OpenAIChat can ask the model to critique the composition, caption the render, or fix the prompt based on what's actually in the image. It's pure local encoding; nothing leaves your machine until the content item reaches the Chat node.

How it works

The node takes the first image of the input batch, converts it to PIL, encodes it to your chosen format at your chosen quality, base64-encodes the bytes, and builds a full data: URI. The detail setting rides along on the content item and gets passed through to the API. No network, no key, no cost at this stage.

The fields that matter

  • image - the IMAGE tensor. Only image[0] is encoded.
  • detail - auto, low, or high. This is the token lever: high tiles the image and costs a lot more tokens but reads fine detail; low is cheap and perfect for "what's the vibe" questions. auto lets the provider decide.
  • format - png, jpeg, webp. Default jpeg.
  • quality - 10–100, default 85, applies to jpeg/webp.

The practical defaults are solid: jpeg at 85 for photos and renders, PNG for text and line art where artifacts would mislead the model. high detail for anything where the model needs to read small text or judge fine detail; low everywhere else.

Outputs

content_item - the OAI_CONTENT_ITEM for OpenAIChat or a connector. base64_string - the full data: URI, and note the name: this is the URI, not raw base64. If you're expecting bare base64 for something else, you'll be surprised.

The trap: batches

Like its Gemini sibling, it encodes only the first frame of a batch, silently. A 16-frame batch means the model sees frame 1 and you'll never know. Split batches before encoding if you need per-frame analysis.

Other gotchas: RGBA gets flattened to RGB for jpeg (fine - jpeg has no alpha anyway). Large images produce large data URIs and proportionally more input tokens, so downscale before encoding to keep costs sane. And a missing key doesn't matter here - this node works before you've even configured a loader, because it does no API calls of its own.

Install

With the pack via ComfyUI Manager (search "comfyui-aichat") or:

cd ComfyUI/custom_nodes
git clone https://github.com/spawner1145/comfyui-aichat

Restart ComfyUI. Dependencies are just openai, httpx, and PyYAML; no model downloads.

CategoryOpenAI API/Content

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
detailCOMBOauto3 options: auto, low, high
formatCOMBOjpeg3 options: png, jpeg, webp
qualityINT8510–100

Outputs (2)

NameTypeDescription
content_itemOAI_CONTENT_ITEM
base64_stringSTRING