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

LLM Chat Completion

Put a vision LLM anywhere in your graph

By bgreene2·Created 11 months ago·Updated 11 months ago· 2
LLM Chat Completion
  • image
  • Text
  • Reasoning
system_promptYou are an expert at expanding and refining text-to-image AI prompts.
pre_promptPlease enhance the following image prompt:
text_prompt
endpointhttp://localhost:8080/v1
api_key123456
modelprompt-enhancer-32b
sleep0
use_temperaturefalse
temperature1.00
use_seedtrue
seed0
use_max_tokenstrue
max_tokens2048
strip_reasoningtrue
reasoning_tag_open<think>
reasoning_tag_close</think>

This is the node the pack is actually named after. OpenAI Chat Completion takes a client object from OpenAI Client, a system prompt, a user prompt, and optionally one or more images - then returns the model's reply as plain text you can feed straight into the rest of your graph. That's a remarkably handy thing to have in a ComfyUI workflow, because it turns a chat/vision model into just another node: a prompt-rewriter, an image captioner, a description generator you can pipe into a Text Encode, a filename builder, whatever the graph needs.

People build real workflows around exactly this pattern - send a render to a vision model, get back a caption or a structured JSON prompt, feed it to the next pass. Point the client at a local Ollama or llama.cpp server and the whole loop stays on your machine, free and private. Point it at OpenAI and you get GPT-class reasoning at per-token prices, plus a reminder that everything you feed it just left your box.

How it works

Under the hood it's a thin wrapper over the OpenAI Python client's chat.completions.create(). It builds the standard message array - one system message, then a user message whose content is a list: your text, plus one image_url part per image you wire in. Each ComfyUI image tensor gets converted to a base64 PNG data URI on the fly, so the image is shipped inline with the request. It only sends the sampling parameters you actually set, and the reply text pops out the STRING output.

The model dropdown is a nice touch: the pack registers a POST /sg_openai_models endpoint on ComfyUI's server that queries {base_url}/models with your key, so the dropdown fills itself with whatever models that endpoint actually offers. No client connected, or a bad key, and the list is empty.

The inputs that matter

You're living in three fields most of the time:

  • system_prompt - the context/role the model plays.
  • user_prompt - what you're actually asking.
  • model - picked from the auto-filled dropdown.
  • images (optional) - wire in a single image or a batch from the Batch Images node for multi-image context.

Beyond those, the ones worth knowing: temperature (default 1.0, lower is more focused), max_tokens (default 1000, your output budget), and seed. That last one deserves attention: -1 means "don't send a seed at all"; any other value is a best-effort determinism hint to the API. Same key, same params, similar output - but don't bet your workflow on it, "best effort" is doing real work in that tooltip.

Two knobs deserve a warning label. top_k and min_p are marked in the author's own tooltips as unofficial parameters that the official OpenAI API may ignore - send them to api.openai.com and you can get rejected or silently dropped. They're there for Ollama, OpenRouter, vLLM, and other providers that actually support them. And extra_parameters is the escape hatch: a JSON string (like {"logit_bias": {...}}) that gets merged into the request after everything else, so it can pass through or even override params that aren't on the panel. Malformed JSON just prints a warning and continues without it.

Installing and running it

Ships in the comfyui-sg-openai-client pack - search that title in ComfyUI Manager, or clone it by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/sebagallo/comfyui-sg-openai-client
cd comfyui-sg-openai-client
pip install -r requirements.txt

Restart, and you're done. The only dependency is the openai pip package; there are no model downloads because the model runs on the server. The pack is built against ComfyUI's newer comfy_api.latest extension API, so keep ComfyUI reasonably current rather than a years-old build.

The issues that actually bite

The model dropdown showing "Error fetching models" means the /models call failed - stale or wrong key, an unreachable base_url, or an endpoint that doesn't implement that route. Images not being understood means your endpoint's model doesn't support vision; plenty of older local models don't. And there's a quiet cost trap: every image you wire in is base64'd and shipped with the request, with no token guard, so a big batch on a paid API is a bill you didn't plan. One more thing worth saying plainly, given the ecosystem's history with LLM-vision custom nodes going bad: this pack sends your prompts and images to whatever server you point it at, and it stores your key in the workflow file. The whole source is a few hundred readable lines - skim it before you wire real credentials into a workflow you share.

CategoryLLM

Inputs (17)

NameTypeDefaultDescription
system_promptSTRINGYou are an expert at expanding and refining text-to-image AI prompts.
pre_promptSTRINGPlease enhance the following image prompt:
text_promptSTRING
endpointSTRINGhttp://localhost:8080/v1
api_keySTRING123456
modelSTRINGprompt-enhancer-32b
sleepINT00–86400
use_temperatureBOOLEANfalse
temperatureFLOAT1.000–2
use_seedBOOLEANtrue
seedINT00–4294967295
use_max_tokensBOOLEANtrue
max_tokensINT20481–1048576
strip_reasoningBOOLEANtrue
reasoning_tag_openSTRING<think>
reasoning_tag_closeSTRING</think>
imageoptIMAGE

Outputs (2)

NameTypeDescription
TextSTRING
ReasoningSTRING