Nodes/ComfyUI-nhknodes/🍌 Gemini API (nhk)
ComfyUI Node

🍌 Gemini API (nhk)

Gemini Inside ComfyUI β€” Generate, Edit, and Analyze Images Without Leaving the Graph

By EnashkaΒ·Created 12 months agoΒ·Updated 28 days agoΒ· 23
🍌 Gemini API (nhk)
  • image_1
  • image_2
  • image_3
  • image_4
  • image
  • text
β—„system_promptβ–Ί
β—„user_promptβ–Ί
β—„modelgemini-3.1-flash-imageβ–Ί
β—„aspect_ratio3:4β–Ί
β—„image_size2Kβ–Ί
β—„output_modetext_and_imageβ–Ί
β—„temperature1.00β–Ί
β—„seed0β–Ί

Gemini API (nhk) is a node that phones Google's Gemini models directly from your graph - the flashy name in the pack's AI section. Give it a prompt and it either generates an image (the -image models), or takes up to four of your images plus a text prompt and analyzes them, returning text (the vision model). Both come back as ComfyUI-native outputs: an IMAGE tensor and a STRING.

The name is honest about the important part: this is not a local model. It's an API call, so it needs a Google key, sends your images to Google's servers, and costs money per request. It's the opposite of the pack's local Ollama node, and it exists because sometimes the hosted Gemini image models are flat-out better at instruction-following image editing than what you can run in 13GB of VRAM.

How it works

Under the hood it uses the google-genai Python client. You pick a model from the dropdown:

  • gemini-3.1-flash-image, gemini-3-pro-image, gemini-2.5-flash-image - image generation/edit models.
  • gemini-3.5-flash - vision + text analysis only; it takes images as input and returns text, no image output.

The node builds a request from your system_prompt, user_prompt, and any of the four image_1..image_4 inputs (converted from tensors), plus the config knobs. aspect_ratio (ten options, default 3:4) and image_size (1K/2K/4K, default 2K) shape generated images; output_mode chooses text_and_image, text_only, or image_only. temperature (0–2) and seed (0 = random) are passed through when the model supports them - Gemini's support for seed-based reproducibility is looser than a local sampler's, so don't expect pixel-perfect reruns.

The key is read from a .env file in the nhknodes directory (GOOGLE_API_KEY=...), loaded via python-dotenv. No key, and you get a clean error string back on the text output instead of a crash.

Inputs and outputs

  • system_prompt / user_prompt - the text that drives the request.
  • model, aspect_ratio, image_size, output_mode, temperature, seed - as above.
  • image_1 through image_4 - optional input images for editing or analysis.

Outputs:

  • image - the generated/edited image as an IMAGE tensor (empty if you asked for text only).
  • text - the model's text response (empty for image-only runs).

Installing it

This is the one node in the pack with a real extra dependency, so pay attention:

cd ComfyUI/custom_nodes && git clone https://github.com/Enashka/ComfyUI-nhknodes
pip install google-genai

Then create a .env file inside the ComfyUI-nhknodes folder with GOOGLE_API_KEY=your_key_here and restart ComfyUI. Manager's "NHK Nodes" install handles the pip side for you; the .env is still on you. Note that requirements.txt also pulls openai and python-dotenv - the dotenv is needed here, the openai one is for the pack's other API node.

Where people get burned

The .env file location trips everyone up - it must live inside the nhknodes custom node folder, not your ComfyUI root, because that's where the code looks (os.path.dirname(__file__)). And be honest about what this node is: every request leaves your machine and hits Google's API. If you're doing 100-image batch evaluation you're going to eat quota fast, and "4K" output on a hosted model is not free. For one-off edits and reference-consistency checks it's great; for local, unlimited iteration, the pack's Ollama node is the saner default.

Categorynhk/ai

Inputs (12)

NameTypeDefaultDescription
system_promptSTRINGSystem instructions to guide model behavior
user_promptSTRINGMain prompt for generation or image analysis
modeloptCOMBOgemini-3.1-flash-imageGemini model (Image models generate/edit images; 3.5 Flash analyzes images and returns text)
image_1optIMAGEFirst optional input image
image_2optIMAGESecond optional input image
image_3optIMAGEThird optional input image
image_4optIMAGEFourth optional input image
aspect_ratiooptCOMBO3:4Aspect ratio for generated image
image_sizeoptCOMBO2KOutput image resolution (4K for higher quality)
output_modeoptCOMBOtext_and_imageWhat type of output to request from the model
temperatureoptFLOAT1.000–2Temperature controls randomness (0=deterministic, 2=very random)
seedoptINT00–2147483647Random seed for reproducibility (0=random)

Outputs (2)

NameTypeDescription
imageIMAGEβ€”
textSTRINGβ€”