Nodes/Comfpod OpenAI API/OpenAI API - Chat Completion
ComfyUI Node

OpenAI API - Chat Completion

Put an LLM or VLM Inside the Graph and Actually Use It

By lany42·Created 23 days ago·Updated 16 days ago· 1
OpenAI API - Chat Completion
  • client
  • history
  • options
  • images
  • Response
  • History
◄model—►
◄force_regenfalse►
◄prompt—►
◄system_prompt—►

What this node actually is

There are two kinds of language model in ComfyUI and people mix them up constantly. One is the text encoder baked into your checkpoint - T5 on Flux, Qwen on the newer bases - the frozen thing that turns your prompt into conditioning during the forward pass. You don't install it and can't swap it. The other is an LLM you bolt onto the graph as a node, doing a job that isn't diffusion: writing a structured prompt from your rough idea, captioning a reference image, classifying a batch of images so you can branch on the result. This node is the second kind.

Chat Completion is the workhorse of the pack. Give it a client, a model name, and text and/or images, and it hands back the reply as a plain STRING plus a history you can feed back in. It's an HTTP client wearing a node costume. On provenance: this is lany42/comfyui-openai-api, a fork of hekmon's comfyui-openai-api, and it's obscure - assume you're an early adopter. It's also arbitrary Python that holds your API key and calls the network by design, so read the source before you run it.

How it works

The node builds an OpenAI-style messages array and sends it. If you set system_prompt, that becomes the first message. If you wire a history payload back in, its messages come first instead - and if you also set a system prompt, the node replaces the existing first system/developer message if there is one, otherwise it inserts a new one at the top. Then your prompt goes on as a user message, or, when images are attached, as a multi-modal content array: every image becomes a base64 PNG data URL, the text appended after them, one user message with several image parts. They go at full resolution, and vision models bill per image - that's where the surprise costs live, not in your prompt. The reply is appended to the messages list and handed out as History.

The node also caches. It fingerprints its inputs, so re-queueing with nothing upstream changed returns the same reply without a second API call. Usually what you want - you're iterating on the sampler, not the caption - and occasionally maddening. force_regen is the escape hatch, and it means every run is fresh money. Token counts come back printed in the console and as a text preview on the node.

Inputs and outputs that matter

  • API Client (client) - required, and it comes from the Client node in the same pack. Nothing works without it.
  • Model (model) - a plain string, whatever your endpoint serves: gpt-4o, gpt-5-mini, a local qwen3-vl:8b in Ollama, an LM Studio model id. If you're sending images, this has to be a vision-language model or you'll get a refusal or garbage.
  • Prompt (prompt) - multiline, and it can be empty if you're sending images (a bare "describe this" is optional then).
  • System Prompt (system_prompt) - how you constrain the output. Say "reply with a comma-separated booru prompt, nothing else", or you'll get preambles and markdown - chat scaffolding that lands in your conditioning as literal text.
  • History (history) - wire History back into this and the conversation continues; leave it out and every request is independent.
  • Options (options) - the socket every OpenAI API - <option> node plugs into.
  • image(s) (images) - an IMAGE batch. All images in the batch go into the one request.
  • Force Regen (force_regen) - boolean, default false.

Outputs: Response (STRING) and History (OAIAPI_HISTORY). Response goes into a CLIP Text Encode, a Show Text, a save-text node, or straight into a sampler's prompt if your workflow has a string input.

Install

Search OpenAI API or Comfpod in ComfyUI Manager and install the pack, or do it by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/lany42/comfyui-openai-api
cd comfyui-openai-api
/path/to/ComfyUI/.venv/bin/python -m pip install -r requirements.txt
# restart ComfyUI

That pulls three runtime dependencies: the openai SDK v2 (pinned >=2.7.1,<3), numpy and Pillow. No model downloads. The README's canonical home for the repo is a self-hosted Forgejo at git.colorized.life; the GitHub repo is the same code.

Where people get burned

You changed the model name and got the old answer. You didn't - the cache did. force_regen off plus unchanged inputs means no request at all. Turn it on while you're tuning the prompt, off when you're done.

Empty prompt and no images is a hard error at run time ("a user prompt or at least one image must be supplied"), as is a blank model name - before any API call.

It works locally and fails on your server. api_key defaults to the literal - placeholder, and an empty key makes the OpenAI SDK throw a connection error rather than a tidy auth error. If your endpoint needs no key, leave - alone.

A system prompt that gets rejected on o-series and newer OpenAI models: those want the developer role. That's the Developer Role node's entire job.

Python version. The pack requires Python 3.13+ (requires-python = ">=3.13", and the source uses that-era syntax). On an older ComfyUI venv the import fails and the nodes never appear in the menu.

CategoryOpenAI API

Inputs (8)

NameTypeDefaultDescription
clientOAIAPI_CLIENTThe OpenAI API client to use to perform the request
modelSTRINGThe model to use for generating text
force_regenBOOLEANfalseSet to true to always request a new text generation even if no widget input values have changed (no cache)
promptSTRINGThe user prompt to use for generating text; may be empty when images are supplied
system_promptoptSTRINGThe system prompt to send along with the user prompt
historyoptOAIAPI_HISTORYPrevious conversation history
optionsoptOAIAPI_OPTIONSAdditional options to pass with the request
imagesoptIMAGEImage(s) to include in the request

Outputs (2)

NameTypeDescription
ResponseSTRINGGenerated text response
HistoryOAIAPI_HISTORYConversation history