OpenAI Text (FlexAI)
Chat with your images, and let an LLM talk back to your graph
- image_1
- image_2
- image_3
- image_4
- STRING
Most ComfyUI nodes convert one tensor into another. This one converts your question - and optionally up to four images - into a remote LLM's answer, returned as a plain STRING. It's the sibling node to the pack's image generator, and the two are clearly designed to work together: the image node makes pictures, this one talks about them.
Why would you want that in a diffusion tool? Because ComfyUI is a graph that takes strings in and puts strings out everywhere - prompts, captions, metadata. With this node wired into the graph you can auto-caption a batch of renders, have a model describe what it sees so a text-to-image model can re-prompt it, or turn a rough idea into a finished prompt without ever leaving the editor. It's the kind of automation that a form-based UI never lets you build, and honestly the graph makes it feel natural.
How it works
The node builds a standard /v1/chat/completions request with your system_prompt and user_prompt, plus any attached images. Reference images are converted to JPEG data URLs and auto-scaled so the longest side never exceeds 1024px - keeps token cost down, at the cost of some fine detail. Streaming is on by default (with usage tracking), and the code aggregates the stream and hands you just the final text.
One thing worth knowing before you fall in love: max_tokens is hardcoded at 4096. There's no input for it, and no way to raise it. Fine for captions and prompts; a real ceiling if you're asking for long-form output.
The inputs that matter
- provider - pick which API channel from your
.envto talk through. Set up several and switch on the fly. - model / custom_model - the dropdown holds saved models; type anything into
custom_modelto call it once and have it remembered for next time. - system_prompt - the persona/instructions. Defaults to "You are a helpful assistant."
- user_prompt - the actual ask, multiline. Defaults to "Describe the following images.", which is exactly what you want for the vision use case.
- temperature - 0 to 2, default 0.5. Lower for deterministic captions, higher for creative re-prompts.
- image_1 … image_4 - the optional reference images. None attached? You get plain text chat. Attach one and it's vision mode; attach several and it's a hybrid analysis.
The optional seed, top_p, stream, include_usage, and debug toggles round it out. Note seed only does anything if it's greater than 0 - a seed of 0 means "no seed", which trips people up constantly.
The output is a single STRING containing the model's reply. Wire it into a text display node, a ShowText-style logger, or a prompt-prep/CLIP text encode step if you want the LLM to write the next image's prompt.
Installing it
Same pack as the image node, same steps:
# ComfyUI Manager: search "ComfyUI FlexAI" and install
# or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/Semonxue/Comfyui-flexai.git
cd Comfyui-flexai
pip install -r requirements.txt
Dependencies are just openai, Pillow, python-dotenv, and requests - no heavy downloads. Then drop a .env in the plugin folder with OPENAI_API_KEY=... (plus an optional OPENAI_API_BASE) or the multi-provider OPENAI_API_KEY_<name> form, and restart ComfyUI.
Troubleshooting
- "API key is not configured" - the
.env.exampleships placeholdersk_...keys that the node rejects on purpose. Fill in real ones, restart, and make sure the file is named.envin the plugin root. - Provider dropdown doesn't show your new provider - the provider list is read at node load. Restart ComfyUI after editing
.env; the dropdown refreshes with it. - Answer feels cut off - that's the 4096-token cap. Break the task into pieces instead of hunting for a setting that doesn't exist.
- Vision results are oddly low-detail - your images got resized to 1024px and JPEG'd. That's intentional; feed a tighter crop if fine detail matters.
- "API returned an empty response" - a genuinely empty reply. Usually a provider/model mismatch, and the
debugtoggle will show you the exact request indebug.log.
And the evergreen caveat: this node uploads whatever you attach to a third-party server. It's a great tool, but treat it like a stranger's upload box - don't attach anything you wouldn't email to the API provider, and remember every custom node runs its code with your permissions.
Inputs (15)
| Name | Type | Default | Description |
|---|---|---|---|
| provider | COMBO | default | 1 options: default |
| model | COMBO | gpt-4o | 3 options: gpt-4o, gpt-4-turbo, gpt-3.5-turbo |
| custom_model | STRING | — | |
| temperature | FLOAT | 0.50–2 | — |
| system_prompt | STRING | You are a helpful assistant. | — |
| user_prompt | STRING | Describe the following images. | — |
| image_1opt | IMAGE | — | |
| image_2opt | IMAGE | — | |
| image_3opt | IMAGE | — | |
| image_4opt | IMAGE | — | |
| seedopt | INT | 00–2147483647 | — |
| top_popt | FLOAT | 1.000–1 | — |
| include_usageopt | BOOLEAN | true | — |
| streamopt | BOOLEAN | true | — |
| debugopt | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |