OpenAI API - Chat Completion
The node that actually talks to the language model
- client
- history
- options
- images
- Response
- History
This is the payoff node of the comfyui-openai-api pack. The Client node just holds the connection; OAIAPI_ChatCompletion is where you send a prompt - text, image, or both - and get a string back. Everything else in the pack exists to fine-tune what this one sends. If you're here, you probably want to rewrite or expand a prompt in-graph, classify a generated image with a vision model, or add an LLM "brain" to a workflow that branches on its answer.
How it works
It's a thin, honest wrapper around the chat completions call. You give it a client, a model name, and a prompt; it builds the messages array, fires the request, and returns the text. When you attach IMAGE inputs it gets cleverer: each image is converted to a base64 data:image/png URL and sent to the model as a vision-multimodal message. Multiple images are fine as long as they're fed in as a batch. It also returns usage stats - prompt tokens, completion tokens, cached and reasoning tokens - which land in the console and as preview text on the node. That's a genuinely useful touch for catching runaway token bills.
The inputs that matter
- client - the
OAIAPI_CLIENToutput from the Client node. Mandatory. - model - a string, and it must match exactly what your server calls it. Ollama is
llama3.2:latest, cloud isgpt-4o-mini, and so on. - prompt - the user message, multiline.
- system_prompt (optional) - the instructions message sent before the user prompt. The easiest place to set "rewrite this as a detailed prompt for SDXL" style guidance.
- images (optional) - wire in generated images for vision. And the author's own warning is worth repeating: you must name a vision language model if you attach images, or the call just fails.
- force_regen (default false) - this one trips people up. ComfyUI skips re-executing a node when nothing changed, so an unchanged chat node can silently reuse the previous answer. Flip
force_regento true when you want a fresh generation every run, even with identical inputs.
What comes out
Two outputs. Response is a plain STRING - wire it to a Show Text node, a text concat, or anything that eats strings. History is the OAIAPI_HISTORY type: feed it back into a second Chat Completion node's history input to continue the conversation with context. That's how you build a multi-turn chat loop entirely inside the graph - something most one-shot LLM nodes can't do.
Installing it
Same story as the whole pack: ComfyUI Manager, search "OpenAI API", or:
cd ComfyUI/custom_nodes
git clone https://github.com/hekmon/comfyui-openai-api
Then restart. Only new dependency is openai; no models to download (they live on your server). v2 uses ComfyUI's native extension API, so keep ComfyUI current.
Where people get burned
Wrong model name (silent 404s from Ollama), forgetting the VLM requirement for image inputs, and the cache behavior - if it feels like the node is "ignoring" your new prompt, that's ComfyUI deduping an unchanged node, and force_regen is the answer. The use case people actually land on: prompt rewriting for the modern LLM-encoded models, which want a chat-templated natural-language prompt rather than a tag soup. Drop an image in, ask the VLM "is there a person in this picture," and branch the graph on the answer - the workflow I've seen shared doing exactly this is the nicest demo of the pack.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| client | OAIAPI_CLIENT | The OpenAI API client to use to perform the request | |
| model | STRING | The model to use for generating text | |
| force_regen | BOOLEAN | false | Set to true to always request a new text generation even if no widget input values have changed (no cache) |
| prompt | STRING | The prompt to use for generating text | |
| system_promptopt | STRING | The system prompt to send along with the user prompt | |
| historyopt | OAIAPI_HISTORY | Previous conversation history | |
| optionsopt | OAIAPI_OPTIONS | Additional options to pass with the request | |
| imagesopt | IMAGE | Image(s) to include in the request |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| Response | STRING | Generated text response |
| History | OAIAPI_HISTORY | Conversation history |