Gemini API (Google)
Ask Google Gemini from inside your workflow
- image
- ui_widget
- text
- clean
- raw_json
- json
- image
Sometimes the right tool for a job inside ComfyUI isn't a diffusion model at all - it's a frontier LLM that reads your rough idea, writes a structured prompt, captions an image, or outputs SVG/JSON. LF_GeminiAPI is LF Nodes' chat with Google's Gemini, and the design is the interesting part: the node never touches an API key. It calls a proxy endpoint on your local ComfyUI server, and the server forwards to Google using a key stored server-side. Your key never ends up in the workflow JSON you share with someone.
That's a genuinely good call in a category with a rough security history. The LLM-in-the-graph playbook is blunt about it: an LLM/VLM node is expected to reach the network and load things, so it's exactly the shape an attacker would target. Keeping the key server-side and proxying the request through your own ComfyUI instance is the design you want to see.
How it works
Required: prompt (the text you send). Optional: model (default gemini-2.5-image, a multimodal generation model - swap it for gemini-2.5-flash or another ID when you want plain chat), timeout (default 60s), and image (a reference image, for the multimodal models). Wire an image in and you can ask Gemini about it - captioning, describing, extracting.
On execution the node builds the request, posts it to the local proxy route, and unpacks the response into five outputs:
text- the primary response text (may still contain markdown code fences).clean- the same text with code fences stripped - the "plain SVG or plain text" output, ideal for feeding directly into a save or prompt node.raw_json- the full JSON response as a string, for anything you want to inspect.json- the response parsed as JSON when it's valid, empty otherwise. This is the "make Gemini write JSON and read it structurally" output.image- a generated or processed image, when the model returns one.
Installing it and the key
lf-nodes is one pack:
cd ComfyUI/custom_nodes
git clone https://github.com/lucafoscili/lf-nodes
restart ComfyUI, or ComfyUI Manager → "LF Nodes". Then set the key where the server can read it - an environment variable GEMINI_API_KEY (or the file variant GEMINI_API_KEY_FILE pointing at a file containing the key) before starting ComfyUI:
export GEMINI_API_KEY="your-key-here"
No key in the node, no key in the workflow. If the node complains it can't find the proxy, your ComfyUI server didn't start with the environment set.
Troubleshooting
- "No proxy URL configured" - the node couldn't reach its local proxy; make sure ComfyUI is running with the key env var set, and that you restarted it after setting the variable.
- HTTP errors from Google - invalid or missing key, or the model ID doesn't exist for your account.
raw_jsonwill show you the actual error. - Output is JSON you can't use - feed it through the
cleanoutput for code-fence stripping, and usejsonwhen you asked for structured output.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| prompt | STRING | Text prompt to send to Gemini. | |
| modelopt | STRING | gemini-2.5-image | Gemini model to call. |
| timeoutopt | INT | 60 | Request timeout in seconds. |
| imageopt | IMAGE | Optional reference image for multimodal models. | |
| ui_widgetopt | LF_CODE | — |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| text | STRING | Primary text output extracted from Gemini response (may include code fences). |
| clean | STRING | Cleaned text output with code fences removed (plain SVG or text). |
| raw_json | JSON | Full Gemini JSON response as string. |
| json | JSON | Parsed JSON string when the output is valid JSON, otherwise empty. |
| image | IMAGE | Generated or processed image from multimodal models. |