Google Gemini API integration for ComfyUI - Generate images and text using Google's latest AI models, plus a dynamic batch images utility node.
- π¨ Image Generation - Create images using Gemini's flash-image-preview model
- π Text Generation - Generate text responses with optional image context
- πΌοΈ Multimodal Support - Use images as input context for both text and image generation
- π Concurrent Batch Processing - Generate 1-4 images concurrently with progress tracking
- π Dynamic Batch Images - Combine multiple images into a single batch with automatic resizing
- π Secure API Key Handling - Password field masking with smart export behavior
- β‘ Smart Model Detection - Automatically uses the right generation method based on model
Watch the Comfy Nano Banana custom node in action:
- Install ComfyUI
- Install ComfyUI-Manager
- Search for "Nano Banana" in ComfyUI-Manager and install
- Restart ComfyUI
cd ComfyUI/custom_nodes
git clone https://github.com/darkamenosa/comfy_nanobanana.git
cd comfy_nanobanana
pip install -r requirements.txt- Get a Gemini API key from Google AI Studio
- Set your API key:
- Option 1: Set environment variable
GEMINI_API_KEY - Option 2: Enter directly in the node's API key field
- Option 1: Set environment variable
This node implements intelligent API key handling for different export scenarios:
- API keys are automatically removed when saving workflows
- Safe for sharing workflows publicly without exposing sensitive credentials
- Recipients must enter their own API key or use environment variables
- Prevents accidental API key exposure when sharing on forums, GitHub, etc.
- API keys are preserved in the exported JSON
- Designed for developers deploying workflows programmatically
- Convenient for production deployments and automation
β οΈ Developer Warning: Only share API format exports with trusted parties or systems
- Use environment variable
GEMINI_API_KEYfor production deployments - Always review exported files before sharing publicly
- For public workflow sharing, use regular "Save Workflow" option
- For private/automated use, API format export maintains convenience
The extension adds two nodes to ComfyUI:
Located under the "Nano Banana" category, this node interfaces with Google's Gemini API.
- prompt (required): Text prompt for generation
- model: Gemini model to use (default:
gemini-2.5-flash-image-preview) - batch_size: Number of images to generate concurrently (1-4)
- seed: For reproducible outputs (0-2147483647)
- system_prompt (optional): Instructions to guide the model's behavior
- images (optional): Input images for context
- api_key (optional): Override environment variable
- top_p (optional): Nucleus sampling for text generation (0.0-1.0, default: 0.95)
- max_tokens (optional): Maximum tokens for text output (1-8192, default: 2048)
- images: Generated images or placeholder for text-only models
- text: Text response from the model
gemini-2.5-flash-image-preview- Image and text generationgemini-2.5-pro- Text generation onlygemini-2.5-flash- Text generation only
Located under the "image" category, this utility node dynamically combines multiple images into a single batch.
- Dynamic Inputs: Automatically adds/removes image inputs as you connect/disconnect
- Auto-resize: Mismatched images are automatically resized to match the first image's dimensions
- Clean Interface: Unused inputs are automatically removed
- Flexible: Connect any number of images from different sources
- Add "Batch Images" node from the image category
- Connect your first image - the node automatically creates a new input
- Connect additional images - each connection creates a new input slot
- Disconnecting removes the unused input automatically
- All images are resized to match the first image's dimensions and combined into a batch
- Add "Nano Banana Gemini" node
- Enter a prompt like "A cat wearing a wizard hat"
- Connect output to Preview Image node
- Add "Nano Banana Gemini" node
- Set batch_size to 4
- Enter your prompt
- Get 4 variations generated concurrently with progress tracking
- Load an image
- Connect to "images" input of Gemini node
- Add prompt describing desired changes
- Model will use the image as context
- Add "Batch Images" node
- Connect images from different sources
- The node automatically creates new inputs as you connect
- All images are resized and combined into a single batch
- Use the batch for further processing or saving
comfy_nanobanana/
βββ src/comfy_nanobanana/
β βββ __init__.py
β βββ nodes.py # ComfyUI node implementations
β βββ gemini_api.py # Gemini API client with async support
βββ web/
β βββ index.js # Extension entry point
β βββ node/
β βββ batch_images_dynamic.js # Dynamic input handling for Batch Images
β βββ gemini_api_key_mask.js # API key masking and secure export handling
βββ requirements.txt
βββ pyproject.toml
cd comfy_nanobanana
pip install -e .[dev]
pre-commit installThe node implements a dual-mode export system:
- UI Masking: API keys are visually masked in the interface (showing only first 4 and last 2 characters)
- Workflow Export: Automatically strips API keys for safe sharing
- API Export: Preserves API keys for programmatic use (requires Developer Mode)
This design balances security with developer convenience, ensuring users don't accidentally expose credentials while maintaining ease of deployment for production systems.
"No API key provided"
- Ensure
GEMINI_API_KEYis set or enter key in node
"Seed must be between 0 and 2147483647"
- Gemini API requires 32-bit integer seeds
Empty image output with text models
- Normal behavior - text-only models return placeholder image
Pull requests welcome! Please:
- Follow existing code style
- Add tests for new features
- Update documentation
MIT License - see LICENSE file
Created with ComfyUI Extension Template
