Nodes/OpenAINode/OpenAINode
ComfyUI Node

OpenAINode

The 'OpenAI' node that never touches OpenAI

By Electrofried·Created 3 years ago·Updated 2 years ago· 29
OpenAINode
    • STRING
    promptA world without prompts
    api_urlhttp://127.0.0.1:5000/v1
    api_keyBadPanda
    temperature1.00
    sys_prefixYou are a prompt generation AI. your task is to take a user input for a stable difusion prompt and output and expand the supplied prompt in a stable difusion format to provide better output. Do not deviate from the format. Do not output anything other than a stable diffusion prompt.
    stop_token<|im_end|>
    max_tokens250
    seed0

    The "OpenAI" node that never touches OpenAI

    The name is a lie, and that's the whole point. OpenAINode doesn't call ChatGPT, won't accept your OpenAI key, and the author says flat-out he has no plans to support the real thing. What it does is let you hook ComfyUI up to any local server that speaks the OpenAI API dialect - LM Studio, Oobabooga's text-generation-webui, llama.cpp's server, whatever. You type a plain sentence, a local LLM rewrites it into a full stable-diffusion prompt, and that string feeds straight into your CLIP Text Encode. Prompt expansion with zero cloud dependency.

    The idea is older than it looks, and people keep re-inventing it because it works. Get the system prompt right and a small 7B model turns "a photo of a woman in a cyberpunk world" into something with lighting, atmosphere, and composition packed in - far more signal than the one-liner you'd have typed. That's the whole gap this node sits in: you think in sentences, most diffusion encoders were trained on tags, and an LLM in the middle is a bridge between the two.

    How it works

    There's not much to it, which is the appeal. The node makes one openai.ChatCompletion.create call against your api_url, sends sys_prefix as the system message and your prompt as the user message, and returns the model's reply as a single STRING. No model loading, no VRAM cost inside ComfyUI - your LLM runs in a separate server process. That's exactly why people reach for this over the llama.cpp-internal nodes when they already run a remote text-generation-webui; on r/comfyui that's the case that gets this specific node recommended.

    The inputs that matter

    You'll touch a handful, not all eight:

    • api_url - where your OpenAI-compatible server lives. The default http://127.0.0.1:5000/v1 matches text-generation-webui; LM Studio users must change the port to 1234.
    • api_key - any dummy string works, local servers ignore it. The shipped default is literally BadPanda.
    • sys_prefix - the system prompt that tells the LLM how to behave. The default is a reasonable prompt-expansion prompt; edit it to get your own style, and it's where all the quality lives.
    • stop_token - must match your model's chat template. <|im_end|> is Mistral-style; try </s> or <|endoftext|> if your output comes back cut off or run-together.
    • temperature and max_tokens - the usual knobs. Lower temperature for consistency, raise it when outputs get boring.
    • seed - the README is explicit: it does nothing to the LLM. Randomize it only to bust ComfyUI's cache so the node re-asks every run.

    The one output is a STRING. Right-click the prompt input on a CLIP Text Encode node, choose Convert to input, wire the output in, and you're done.

    Installing

    ComfyUI Manager: search "OpenAINode". Or by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Electrofried/ComfyUI-OpenAINode
    pip install -r requirements.txt
    

    One dependency: openai. And here's the trap, straight from the code: it uses the pre-1.0 SDK API (openai.api_base, openai.ChatCompletion), which modern versions of the package deleted. Install today's openai and the node quietly errors and - because everything sits in a try/except - hands you "Bad Panda" as your prompt. Pin the old one:

    pip install "openai<1.0"
    

    Common issues

    • You get "Bad Panda" out. Check the console for the printed error. Usually it's the SDK version above, or api_url pointing at a server that isn't running / isn't exposing /v1.
    • No LLM server at all. With text-generation-webui you must launch it with --api; LM Studio just needs its local server toggle on.
    • GPU screaming. The author's warning is blunt: an LLM and SD sharing one GPU is how you run out of memory. Run the LLM on CPU/RAM or host it on a second machine and point api_url at it.
    • Random NSFW in your prompts. If you try the author's own Promptmaster Mistral 7B, the README's all-caps warning is not a joke - it will cheerfully inject explicit content into "a baby panda". Use it with a filter, or bring a model you trust.
    CategoryOpenAIapi

    Inputs (8)

    NameTypeDefaultDescription
    promptSTRINGA world without prompts
    api_urlSTRINGhttp://127.0.0.1:5000/v1
    api_keySTRINGBadPanda
    temperatureFLOAT1.000–1
    sys_prefixSTRINGYou are a prompt generation AI. your task is to take a user input for a stable difusion prompt and output and expand the supplied prompt in a stable difusion format to provide better output. Do not deviate from the format. Do not output anything other than a stable diffusion prompt.
    stop_tokenSTRING<|im_end|>
    max_tokensINT250-1–2048
    seedINT00–18446744073709550000

    Outputs (1)

    NameTypeDescription
    STRINGSTRING