ComfyUI Extension
Better-Gemini
A better node for using Google Gemini models, supporting the latest API endpoints with a v3 ComfyUI node interface.
ttulttul/Better-Gemini
Nodes2
On cloudLocal install
Categoryapi node/image/BetterGemini, api node/image/BetterGrok
Stars0
Updatedabout a month ago
Readme
ComfyUI Better Gemini
ComfyUI V3 nodes for generating images and text with Google Gemini and xAI Grok.
This repo provides two nodes:
Better Geminifor Gemini image and text generationBetter Grokfor Grok image generation, image editing, and text chat
Install
- Clone into your ComfyUI
custom_nodesdirectory:cd /path/to/ComfyUI/custom_nodesgit clone https://github.com/<you>/ComfyUI-Better-Gemini.git
- Install Python deps with
uv:uv syncuv pip install --python /path/to/ComfyUI/python/bin/python -e ./ComfyUI-Better-Gemini
- Set API keys as needed:
export GOOGLE_API_KEY="..."orexport GEMINI_API_KEY="..."export XAI_API_KEY="..."
- Restart ComfyUI.
Nodes
Better Gemini
- Inputs: prompt, model,
response_modalities(IMAGE,IMAGE+TEXT,TEXT), optional prompt images, aspect ratio, resolution or width+height, temperature, top_p, top_k, max tokens, thinking controls, seed, optional output caching - Outputs:
IMAGE,STRING - Use it when you want one node that can handle both Gemini image models and Gemini text-only models
Better Grok
- Inputs: prompt, model,
response_modalities(IMAGE,IMAGE+TEXT,TEXT), reasoning effort (none,low,medium,high), optional prompt images, aspect ratio, resolution,n, optional output caching - Outputs:
IMAGE,STRING - Use it when you want Grok image generation, image editing, or a text-only Grok call from the same node
Output Behavior
- In
TEXTmode, the usable model output is returned throughSTRING. - In
TEXTmode, theIMAGEoutput is a minimal blank1x1tensor so ComfyUI graphs can stay connected without allocating a large placeholder. - In
IMAGE+TEXTmode, image generation still runs and any returned notes or revised prompt text are placed inSTRING. - If Gemini or Grok returns no images when image output was requested, the node emits a blank placeholder image and includes a note in
STRING. - If
cache_outputsis enabled, model outputs are stored under.cache/and identical future requests reuse the cachedIMAGE/STRINGoutputs without calling Gemini or Grok.
Model Dropdowns
- Gemini model options are populated via
client.models.list()without action-based filtering, so both image-capable and text-only Gemini models can appear in the same dropdown. - Grok model options merge xAI
/v1/image-generation-modelsand/v1/language-models, so image and language models can appear in the same dropdown. - If an API key is unavailable or model listing fails, each node falls back to bundled default model names.
Bundled fallback models:
- Gemini:
gemini-3.1-flash-lite-image,gemini-3-flash-preview,gemini-3.1-flash-image-preview,gemini-3.1-flash-lite-preview,gemini-3-pro-image-preview,gemini-3.1-pro-preview,imagen-4.0-generate-001,imagen-4.0-ultra-generate-001 - Grok:
grok-imagine-image,grok-imagine-image-pro,grok-imagine-image-quality,grok-latest,grok-4,grok-4-fast-non-reasoning,grok-3-mini,grok-code-fast-1
Recommended text-only examples:
- Gemini:
gemini-3-flash-preview,gemini-3.1-flash-lite-preview,gemini-3.1-pro-preview - Grok:
grok-latest,grok-4,grok-4-fast-non-reasoning,grok-3-mini,grok-code-fast-1
Example Workflow

Implementation Notes
- The Gemini node imports
google-genailazily so ComfyUI can still boot even if dependencies are not installed yet; execution raises a clear error until installed. - This extension uses ComfyUI's V3 extension loader via
comfy_entrypoint. - Gemini requires
seedto fit in anint32; larger ComfyUI seeds are deterministically folded viaseed % 2**31. - When
response_modalities=TEXT, Gemini requests omit image-specific config. - Grok image generation is wired against xAI's documented image endpoints and requests
response_format="b64_json", so the node can return image tensors directly instead of downloading temporary URLs. - The Grok HTTP client sends an explicit application
User-Agentbecauseapi.x.aican reject the defaultPython-urllibsignature with Cloudflare 1010. - Grok image edits use xAI's JSON-based
/v1/images/editsAPI and send ComfyUIIMAGEinputs as PNG data URIs. Multiple prompt images are supported for edit and merge workflows. - Grok
TEXTmode uses xAI's/v1/responsesendpoint with configurable reasoning effort andstore=false, since node calls are not reused as xAI chat sessions. If prompt images are attached, the node sends them as response image inputs and returns the model's text throughSTRING. - Output caching uses the SHA-256 checksum of canonical Gemini or Grok request data as the manifest filename, with string and image payloads stored as separate content-addressed files.
resolutionandaspect_ratioare best-effort, model-dependent settings. The node logs a warning if the returned size does not match the request.
Dev
- Sync dev environment:
uv sync --dev - Run unit tests:
uv run python -m unittest discover -s tests -p 'test_*.py' -v