Nodes/Divergent Nodes/Gemini Batch Process
ComfyUI Node

Gemini Batch Process

Caption a whole batch in one node

By thedivergentai·Created 2 years ago·Updated 9 months ago· 1
Gemini Batch Process
  • images
  • texts
  • errors
modelgemini-1.5-flash
prompts
temperature0.90
max_output_tokens2048
safety_harassmentBlock Medium & Above
safety_hate_speechBlock Medium & Above
safety_sexually_explicitBlock Medium & Above
safety_dangerous_contentBlock Medium & Above
api_key_override
max_retries3

Captioning one image is fun. Captioning fifty is a job. GeminiBatchProcess is the version of the Divergent Gemini node built for the job: give it a list of prompts (one per image), optionally a batch of images, and it fires off an API call for each one, collecting results and errors separately.

This is the node you reach for when you're prepping a training set or tagging a batch of generations for organization. It's the sibling of the single DivergentGeminiNode, with the same API-key plumbing, but it trades fine-grained controls for throughput - no thinking budget, no top-p/top-k, a shorter model list. It's built for "run this prompt against every image in the batch and give me the captions."

How it works

It loops over your list of prompts and calls the Gemini API once per prompt, converting each image in the images batch to JPEG bytes and attaching it to its matching prompt. There's a small mismatch guard built in: if you feed more prompts than images, the image list gets padded so every prompt still runs; if you feed more images than prompts, the extras get dropped. Each call runs with the shared retry settings, and per-item failures land in the errors output instead of killing the whole batch. One honest caveat from the source: there's no deduplication or shared-batch API - it's N sequential API calls, so cost and time scale linearly with your list.

Inputs that matter

  • prompts - the list, one per line, one per image. This is the field that makes or breaks the batch.
  • model - a shorter list than the single node: gemini-2.0-flash, gemini-1.5-flash, gemini-1.5-pro. Flash is the sensible default for captioning; it's fast and cheap.
  • images (optional) - the IMAGE batch to caption.
  • temperature and max_output_tokens - same semantics as the single node.
  • api_key_override and max_retries - optional; the key resolution order (override → config.json → env var) is identical to the single Gemini node.

Outputs

  • texts (STRING, list) - one generated result per prompt, in order.
  • errors (STRING, list) - per-item error messages, empty string where a call succeeded.

Wire texts into a batch text handler or a text display; the pairing between texts[i] and prompts[i] is positional, which is fine as long as you remember batches don't rearrange themselves.

Installing it

Same pack, same dance as every other Divergent Nodes node:

cd ComfyUI/custom_nodes
git clone https://github.com/thedivergentai/divergent_nodes.git divergent_nodes
cd divergent_nodes
pip install -r requirements.txt

Or via ComfyUI Manager ("Divergent Nodes"). And the same API key setup: a config.json in the pack folder with GOOGLE_API_KEY, or a .env / environment variable.

Where people get burned

Two gotchas. First, watch your prompt list length against your batch size - padding means a prompt can run image-less without you noticing until you read the captions. Second, remember each item is its own paid API call; a long list at flash pricing is cheap, but the node will happily run a thousand calls if your list says so. The separate errors output is there for a reason: if some captions come back empty, that's where the explanation lives.

CategoryDivergent Nodes 👽/Gemini

Inputs (11)

NameTypeDefaultDescription
modelCOMBOgemini-1.5-flash3 options: gemini-2.0-flash, gemini-1.5-flash, gemini-1.5-pro
promptsSTRINGList of prompts (one per image)
temperatureFLOAT0.900–2
max_output_tokensINT20481–8192
safety_harassmentCOMBOBlock Medium & Above5 options: Default (Unspecified), Block Low & Above, Block Medium & Above, Block High Only, Block None
safety_hate_speechCOMBOBlock Medium & Above5 options: Default (Unspecified), Block Low & Above, Block Medium & Above, Block High Only, Block None
safety_sexually_explicitCOMBOBlock Medium & Above5 options: Default (Unspecified), Block Low & Above, Block Medium & Above, Block High Only, Block None
safety_dangerous_contentCOMBOBlock Medium & Above5 options: Default (Unspecified), Block Low & Above, Block Medium & Above, Block High Only, Block None
imagesoptIMAGEOptional list of images
api_key_overrideoptSTRING
max_retriesoptINT30–10

Outputs (2)

NameTypeDescription
textsSTRING
errorsSTRING