ComfyUI Node

OpenAI

The OpenAI node that puts a GPT call inside your graph

By isekai-sh·Created 10 months ago·Updated about a month ago· 4
OpenAI
    • response
    ◄prompt►
    ◄model▾►
    ◄system_prompt►
    ◄api_key►
    ◄temperature0.7►
    ◄max_tokens1000►

    IsekaiOpenAI is the rare node in this pack that tells the truth about itself. Unlike the image effects, which are all local PIL math, this one really does phone home: it calls OpenAI's Chat Completions API and hands the reply back to your workflow as a STRING. If you've ever wanted a GPT step mid-graph - rewriting a prompt, generating a title, producing a caption you'll feed to a save node - this is the simplest way to get it without building your own API wrapper.

    How it works. The node POSTs to https://api.openai.com/v1/chat/completions with a standard messages array. Your prompt becomes the user message; system_prompt (optional) goes first as a system message if you provide one. temperature (default 0.7) and max_tokens (default 1000) map straight onto the API. Nothing fancy, no streaming, no vision - text in, text out.

    The one mechanism worth knowing is the API key handling. The node checks the OPENAI_API_KEY environment variable first, and only falls back to the api_key input field if the env var is missing. When you use the field, it prints a warning that keys typed into node inputs get saved in your workflow JSON. It's right - and it's worth remembering that any node you load executes arbitrary code on your machine, so a key sitting in a workflow you drag in from the internet is a key you just gave away.

    On failure, the node doesn't crash your graph. It returns an Error: ... string as the output. That's actually friendly for debugging, just don't wire it into a text encoder and then wonder why your prompt says "Error: Authentication failed."

    The inputs that matter. You'll touch four of these, max:

    • prompt - the actual thing you're asking. Multiline, so paste freely.
    • model - a hardcoded dropdown: gpt-4o, gpt-4-turbo, gpt-3.5-turbo, gpt-4o-mini. This is the node's biggest weakness: you can't type an arbitrary model name, so when OpenAI ships the next thing, you're stuck on this list until the pack updates.
    • system_prompt - set the persona ("you are a terse caption writer").
    • temperature / max_tokens - leave alone until the output is too boring or too short.

    The single output is response (STRING), which wires straight into a CLIP text encode, a text display node, or a save-text node. A natural setup: batch a bunch of images, pass a per-image description in, and get back captions you can write to disk.

    Install. Same as the rest of the pack: open ComfyUI Manager, search "isekai", install, restart. Or the manual route:

    cd ComfyUI/custom_nodes
    git clone https://github.com/isekai-sh/isekai-comfy-node
    cd isekai-comfy-node
    pip install -r requirements.txt
    

    Then restart ComfyUI. requirements.txt is just Pillow, requests, and the torch/numpy you already have - no model downloads, nothing heavy. Set OPENAI_API_KEY in your shell (or a .env you load before launching ComfyUI) rather than pasting it into the node.

    Common issues. Empty prompt returns an empty string rather than an error - it's a silent skip, so if you wired a possibly-empty value in, that's what's happening. A wrong or expired key returns an error string in the output (check the [Isekai] OpenAI lines in the console for the real message). Rate limits get retried three times by the shared client before failing, but on a busy account you can still eat an error - bump max_tokens down and batch less aggressively. And one more honest note: this pack has essentially no community footprint - a search for it turns up nothing on the usual forums - so you're the early adopter. The node works, but "works" here means "the README and the code agree," not "hundreds of threads complain when it breaks."

    CategoryIsekai/LLMs

    Inputs (6)

    NameTypeDefaultDescription
    promptSTRING—
    modelCOMBO4 options: gpt-4o, gpt-4-turbo, gpt-3.5-turbo, gpt-4o-mini
    system_promptoptSTRING—
    api_keyoptSTRING—
    temperatureoptFLOAT0.70–2—
    max_tokensoptINT10001–4096—

    Outputs (1)

    NameTypeDescription
    responseSTRING—