Nodes/lf-nodes/OpenAI API (Chat)
ComfyUI Node

OpenAI API (Chat)

Drop a GPT call into your ComfyUI graph

By lucafoscili·Created 2 years ago·Updated 6 days ago· 35
OpenAI API (Chat)
  • image
  • text
  • clean
  • raw_json
  • json
  • image
prompt
modelgpt-4
system_messageYou are a helpful assistant.
temperature0.7
max_tokens1000
timeout60

An OpenAI chat call as a graph node: give LF_OpenAIAPI a prompt, get back text - plus a cleaned, fence-stripped variant and a parsed-JSON variant, all ready to feed other nodes. It's the LF Nodes take on "LLM as a tool in the graph," for when you want GPT-class writing quality on a prompt, a caption, or some structured output without running a local model.

Same security-minded design as the pack's Gemini node: the node doesn't hold an API key. It posts to a proxy route on your own ComfyUI server, and the server forwards to OpenAI using a key it reads from its environment. Your key stays server-side and out of the workflow JSON you might share - which is worth more than it sounds in the wake of the ecosystem's LLM-node malware incident. Read the node's source before you trust it, but this pattern is the good one.

How it works

Required: prompt. Optional controls: model (default gpt-4 - point it at any model your OpenAI-compatible account allows), system_message (default "You are a helpful assistant."), temperature (0–2, default 0.7), max_tokens (default 1000), timeout (default 60s), and image (an optional reference image for multimodal models - wire in a render and ask GPT about it).

Outputs:

  • text - the response text.
  • clean - same text with code fences removed; the output to use when you asked for plain SVG or a bare prompt and don't want markdown scaffolding around it.
  • raw_json - the full API response as JSON.
  • json - parsed JSON when the response is valid JSON, else empty.
  • image - the input image passed through, for multimodal flows.

The two "JSON" outputs matter more than they look: ask for JSON in the prompt, read it structurally via the json output, and you've got a mini-pipeline for structured generation.

Installing it and the key

One pack:

cd ComfyUI/custom_nodes
git clone https://github.com/lucafoscili/lf-nodes

restart ComfyUI, or ComfyUI Manager → "LF Nodes". The key goes to the server, not the node - set OPENAI_API_KEY (or OPENAI_API_KEY_FILE) in the environment before starting ComfyUI:

export OPENAI_API_KEY="sk-..."

Troubleshooting

  • "No proxy URL configured" - the local proxy isn't reachable; restart ComfyUI with the key env var set.
  • 401 / auth errors - the key is wrong or missing server-side. Check raw_json for the real message.
  • Model not found - your OpenAI-compatible endpoint doesn't serve gpt-4. Point model at an ID your provider actually has. (The pack's README notes its LLM nodes were tested against KoboldCpp's OpenAI-compatible endpoint, so this pattern generalizes to local LLMs too.)
Category✨ LF Nodes/LLM

Inputs (7)

NameTypeDefaultDescription
promptSTRINGText prompt to send to OpenAI.
modeloptSTRINGgpt-4OpenAI model to call.
system_messageoptSTRINGYou are a helpful assistant.System message to set context.
temperatureoptFLOAT0.70–2Controls randomness (0.0-2.0).
max_tokensoptINT10001–4096Maximum tokens to generate.
timeoutoptINT60Request timeout in seconds.
imageoptIMAGEOptional reference image for multimodal models.

Outputs (5)

NameTypeDescription
textSTRINGPrimary text output extracted from OpenAI response.
cleanSTRINGCleaned text output with code fences removed.
raw_jsonJSONFull OpenAI JSON response as string.
jsonJSONParsed JSON string when the output is valid JSON, otherwise empty.
imageIMAGEInput image for multimodal models.