ComfyUI Extension: Comfy Nano Banana
Google Gemini API integration for ComfyUI - Generate images and text using Google's latest AI models. Provides nodes for Gemini API interactions and batch image processing.
Custom Nodes (0)
README
Comfy Nano Banana
Google Gemini API integration for ComfyUI - Generate images and text using Google's latest AI models, plus a dynamic batch images utility node.
Features
- šØ 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
Demo
Watch the Comfy Nano Banana custom node in action:
Installation
Via ComfyUI Manager (Recommended)
- Install ComfyUI
- Install ComfyUI-Manager
- Search for "Nano Banana" in ComfyUI-Manager and install
- Restart ComfyUI
Manual Installation
cd ComfyUI/custom_nodes
git clone https://github.com/darkamenosa/comfy_nanobanana.git
cd comfy_nanobanana
pip install -r requirements.txt
Setup
- 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
Security & API Key Handling
š Smart Export Behavior
This node implements intelligent API key handling for different export scenarios:
Regular Workflow Export (Save Workflow)
- 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 Format Export (Save as API - Developer Mode)
- 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
Best Practices
- Use environment variable
GEMINI_API_KEY
for 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
Usage
The extension adds two nodes to ComfyUI:
1. Nano Banana Gemini Node
Located under the "Nano Banana" category, this node interfaces with Google's Gemini API.
Inputs
- 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)
Outputs
- images: Generated images or placeholder for text-only models
- text: Text response from the model
Supported Models
gemini-2.5-flash-image-preview
- Image and text generationgemini-2.5-pro
- Text generation onlygemini-2.5-flash
- Text generation only
2. Batch Images Node
Located under the "image" category, this utility node dynamically combines multiple images into a single batch.
Features
- 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
How to Use
- 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
Examples
Image Generation
- Add "Nano Banana Gemini" node
- Enter a prompt like "A cat wearing a wizard hat"
- Connect output to Preview Image node
Batch Image Generation
- Add "Nano Banana Gemini" node
- Set batch_size to 4
- Enter your prompt
- Get 4 variations generated concurrently with progress tracking
Image-to-Image
- Load an image
- Connect to "images" input of Gemini node
- Add prompt describing desired changes
- Model will use the image as context
Combining Multiple Images
- 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
Development
Project Structure
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
Dev Setup
cd comfy_nanobanana
pip install -e .[dev]
pre-commit install
Developer Notes
API Key Security Implementation
The 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.
Troubleshooting
Common Issues
"No API key provided"
- Ensure
GEMINI_API_KEY
is 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
Contributing
Pull requests welcome! Please:
- Follow existing code style
- Add tests for new features
- Update documentation
License
MIT License - see LICENSE file
Credits
Created with ComfyUI Extension Template