OpenAI API (Chat)
Drop a GPT call into your ComfyUI graph
- image
- text
- clean
- raw_json
- json
- image
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_jsonfor the real message. - Model not found - your OpenAI-compatible endpoint doesn't serve
gpt-4. Pointmodelat 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.)
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt | STRING | Text prompt to send to OpenAI. | |
| modelopt | STRING | gpt-4 | OpenAI model to call. |
| system_messageopt | STRING | You are a helpful assistant. | System message to set context. |
| temperatureopt | FLOAT | 0.70–2 | Controls randomness (0.0-2.0). |
| max_tokensopt | INT | 10001–4096 | Maximum tokens to generate. |
| timeoutopt | INT | 60 | Request timeout in seconds. |
| imageopt | IMAGE | Optional reference image for multimodal models. |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| text | STRING | Primary text output extracted from OpenAI response. |
| clean | STRING | Cleaned text output with code fences removed. |
| raw_json | JSON | Full OpenAI JSON response as string. |
| json | JSON | Parsed JSON string when the output is valid JSON, otherwise empty. |
| image | IMAGE | Input image for multimodal models. |