π Gemini API (nhk)
Gemini Inside ComfyUI β Generate, Edit, and Analyze Images Without Leaving the Graph
- image_1
- image_2
- image_3
- image_4
- image
- text
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_1throughimage_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.
Inputs (12)
| Name | Type | Default | Description |
|---|---|---|---|
| system_prompt | STRING | System instructions to guide model behavior | |
| user_prompt | STRING | Main prompt for generation or image analysis | |
| modelopt | COMBO | gemini-3.1-flash-image | Gemini model (Image models generate/edit images; 3.5 Flash analyzes images and returns text) |
| image_1opt | IMAGE | First optional input image | |
| image_2opt | IMAGE | Second optional input image | |
| image_3opt | IMAGE | Third optional input image | |
| image_4opt | IMAGE | Fourth optional input image | |
| aspect_ratioopt | COMBO | 3:4 | Aspect ratio for generated image |
| image_sizeopt | COMBO | 2K | Output image resolution (4K for higher quality) |
| output_modeopt | COMBO | text_and_image | What type of output to request from the model |
| temperatureopt | FLOAT | 1.000β2 | Temperature controls randomness (0=deterministic, 2=very random) |
| seedopt | INT | 00β2147483647 | Random seed for reproducibility (0=random) |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | β |
| text | STRING | β |