Nodes/X-FluxAgent/OpenAI Chat Node
ComfyUI Node

OpenAI Chat Node

The bare-bones OpenAI call that powers the pack's 'agent'

By X-School-Academy·Created about a year ago·Updated about a year ago· 37
OpenAI Chat Node
    • string
    modelgpt-4.1
    user
    system

    OpenAI Chat Node is the one node in X-FluxAgent that actually talks to an AI, and it's exactly as simple as the name suggests: you give it a user message (and optionally a system prompt), it calls OpenAI's chat completions API, and it hands you back the assistant's reply as a string. That's it. No tool calling, no memory, no agent loop - the "agent" framing from the pack's README is a story about what's coming, not what this node does today.

    So when do you want it? When you need a real LLM's judgment inside a workflow: summarize the prompt you just built, rewrite a caption, fix a string before it gets saved, or feed a generated idea into the next stage of your graph. The classic pairing is this node → the pack's Save Text To File node, which turns a one-off chat response into something you can actually keep.

    How it works

    The node is a thin requests.post to https://api.openai.com/v1/chat/completions. Your user message goes in as the user role, the optional system prompt goes in as the system role, and the API key comes from an environment variable. No streaming, no retry logic, no parameters beyond the model name - this is the minimal possible wrapper, and it shows.

    Here's the part that trips people up: the key is read from OPENAI_API_KEY, and the pack loads a .env file from its own directory when it starts. That means you don't put the key in your shell profile or ComfyUI's env - you create a file at ComfyUI/custom_nodes/X-FluxAgent/.env:

    cd ComfyUI/custom_nodes/X-FluxAgent
    echo "OPENAI_API_KEY=sk-..." > .env
    

    Then restart ComfyUI. If the key is missing when you run the node, you'll get an exception telling you exactly that. It's a private key, so make sure that .env stays out of git if you ever clone your setup around.

    The inputs that matter

    • user (required) - the user message. It's forceInput, so wire it from a text node, the pack's Rich Text Node, or anything else that outputs a string. This is what the model actually answers.
    • system (optional) - also forceInput. Use it to set behavior: "you are a prompt engineer" beats hoping the model guesses.
    • model - defaults to gpt-4.1. Want something cheaper or older? Type it in. There's no dropdown, no temperature, no max-tokens - you get what the API defaults give you, and if you need fine control you're better off elsewhere.

    Output: STRING - the assistant's reply. It's an ordinary string, so it plugs into save-to-file, text display, or any downstream consumer.

    Where it gets weird

    Two behaviors to know about. First, failures are returned as strings, not raised in most cases: an HTTP error or network failure comes back as text beginning "HTTP Error:" or "Request Error:" flowing out of the node, so your workflow keeps running and you have to look at the output to notice something went wrong. Check the text, don't trust the green light. Second, it costs real money and needs the internet - this is a paid OpenAI call, not a local model, and there's no fallback if you're offline.

    Honest bottom line: for a raw, single-shot OpenAI call in a ComfyUI graph this works fine and keeps your graph tidy. Just don't mistake it for an agent. And keep in mind the pack itself is brand-new and barely community-tested (one unanswered "is this safe?" thread on Reddit), so skim the source if you're wiring real work through it - it's short enough to read in a couple of minutes.

    CategoryX-FluxAgent

    Inputs (3)

    NameTypeDefaultDescription
    modelSTRINGgpt-4.1
    userSTRING
    systemoptSTRING

    Outputs (1)

    NameTypeDescription
    stringSTRING