Nodes/lf-nodes/Gemini API (Google)
ComfyUI Node

Gemini API (Google)

Ask Google Gemini from inside your workflow

By lucafoscili·Created 2 years ago·Updated 7 days ago· 35
Gemini API (Google)
  • image
  • ui_widget
  • text
  • clean
  • raw_json
  • json
  • image
prompt
modelgemini-2.5-image
timeout60

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_json will show you the actual error.
  • Output is JSON you can't use - feed it through the clean output for code-fence stripping, and use json when you asked for structured output.
Category✨ LF Nodes/LLM

Inputs (5)

NameTypeDefaultDescription
promptSTRINGText prompt to send to Gemini.
modeloptSTRINGgemini-2.5-imageGemini model to call.
timeoutoptINT60Request timeout in seconds.
imageoptIMAGEOptional reference image for multimodal models.
ui_widgetoptLF_CODE

Outputs (5)

NameTypeDescription
textSTRINGPrimary text output extracted from Gemini response (may include code fences).
cleanSTRINGCleaned text output with code fences removed (plain SVG or text).
raw_jsonJSONFull Gemini JSON response as string.
jsonJSONParsed JSON string when the output is valid JSON, otherwise empty.
imageIMAGEGenerated or processed image from multimodal models.