π€ OpenAI API (nhk)
Chat with GPT-4o or GPT-5 inside your workflow β vision included
- image
- response
Sometimes the most useful node in a workflow isn't a model - it's a brain. LLMChat ("OpenAI API") drops an actual GPT call into your graph: you type a message (and optionally connect an image), it returns a text response. That unlocks the whole "LLM as a workflow brain" pattern - generate a prompt, evaluate a result, describe what changed - without leaving ComfyUI. This is the OpenAI-powered member of the pack's AI trio (the others being Ollama and Gemini).
It's straightforward in the best way, but it has one design quirk you need to know before you wire it into a batch: it re-runs on every execution. The node deliberately forces a fresh API call each time, which is what you want for a live prompt generator and exactly what you don't want if you accidentally leave it in a loop.
How it works
The node calls the OpenAI API and returns the model's text as the single response output. Under the hood it splits by model family:
- GPT-4 models (
gpt-4o,gpt-4o-mini,chatgpt-4o-latest) use the Chat Completions API. - GPT-5 models (
gpt-5,gpt-5-mini,gpt-5-nano) use the newer Responses API, with reasoning effort pinned to "minimal" and low verbosity - snappier replies, fewer tokens burned on thinking.
The optional image input converts your ComfyUI tensor to a base64 PNG and sends it along, which gives you vision on the models that support it. This is the same trick the pack's ImageEvaluator uses, except here it's a direct paid-API call rather than local Ollama.
Key inputs: model (drop-down, default gpt-4o), system_message (set the assistant's behavior - this is where you give it a role, e.g. "you are a prompt engineer who rewrites prompts to be more cinematic"), and user_message (the actual request, can be wired from other nodes). Output: response STRING.
The requirements that aren't obvious
- An API key. The node reads
OPENAI_API_KEYfrom the environment. The README says to put it in a.envfile - and the pack loads that.envfrom its owncustom_nodes/nhknodesdirectory when it starts (the Gemini node does thepython-dotenvloading at import time, which makes the key visible to the whole pack). So drop a file atComfyUI/custom_nodes/nhknodes/.envcontainingOPENAI_API_KEY=sk-..., then restart ComfyUI. - The OpenAI Python package.
openai>=1.101.0is in the pack's requirements. ComfyUI Manager installs dependencies automatically; if you cloned manually, run:
cd ComfyUI/custom_nodes/nhknodes
pip install -r requirements.txt
- It costs money. Every execution is a real API call. IS_CHANGED forces a fresh one each run, so a 50-image batch with this node wired in is 50 API calls. Budget accordingly, or gate it with something like the pack's IntervalGate.
Installing
Standard pack install (Manager β search "NHK Nodes", or git clone https://github.com/Enashka/ComfyUI-nhknodes into custom_nodes), then the .env step above. It lives under nhk/ai.
Where people get burned
- "Error: OPENAI_API_KEY not found." The
.envisn't in the right place or you didn't restart after creating it. It must be inside the nhknodes folder. - Billing shock. The forced re-execution is the #1 surprise. If you want one call per queue rather than one per run, restructure so the node only executes when you actually need a new response.
- "The response is empty." It requires a non-empty
user_message- leaving it blank returns an error string, not a call. And remember: stateless. It's one call per run with no conversation memory, so don't expect multi-turn chat - feed context intosystem_messageif you need the model to know what came before.
For building smarter workflows - prompt generation, image captioning, output critique that feeds a loop - LLMChat is the easiest "give my workflow a brain" button in this pack. Just keep one eye on the API bill.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| model | COMBO | gpt-4o | OpenAI model to use (GPT-4o supports vision) |
| system_message | STRING | System message to set assistant behavior and context | |
| user_message | STRING | User message/prompt to send to the model | |
| imageopt | IMAGE | Optional image for vision-enabled models (GPT-4o, GPT-5) |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| response | STRING | β |