Nodes/Comfyui_Gemini2/CXH_Gemini2_TX
ComfyUI Node

CXH_Gemini2_TX

A Gemini text brain for your workflow — no GPU, just a key

By StartHua·Created 2 years ago·Updated 2 years ago· 18
CXH_Gemini2_TX
    • out
    model
    prompt

    An LLM you can drop straight into a diffusion graph sounds like it needs a second GPU and a fight with a GGUF loader. It doesn't. CXH_Gemini2_TX is the text-only half of the Comfyui_Gemini2 pack: you type a prompt, it calls Google's Gemini API, and hands you back a plain string. No local model, no VRAM, no quantized-file shuffle - just a key in a text file and an internet connection.

    It's not a fancy node. It's one API call wrapped in a ComfyUI-friendly envelope, and that's exactly why it's useful. LLM-assisted prompting isn't a gimmick anymore; it's routine, and this is one of the least painful ways to get it into a graph. The standard move is to sit this node before your CLIP Text Encode, have it expand a short idea into a full prompt, and feed its out string into the positive prompt input. Run a batch and you get prompt variety per image without hand-writing twenty variations. It works on any machine - including the one where the GPU is already maxed out by the sampler.

    How it works is about as direct as code gets: the node reads your Google API key from key.txt in the pack folder, then calls genai.GenerativeModel(model).generate_content(prompt) and returns response.text. It also prints the reply to the ComfyUI console, which is handy when you're debugging a prompt. One thing to know up front: the key is loaded when the node is created, not when you queue it - write your key first, then restart ComfyUI (or delete and re-add the node).

    The inputs you actually touch are two. model is a dropdown of seven hardcoded Gemini ids, defaulting to gemini-2.0-flash-exp - fast, cheap, and plenty for prompt work, so start there. Several of the others are experimental ids (gemini-exp-1114, gemini-exp-1121, learnlm-1.5-pro-experimental); Google retires those with little notice, so if a model starts erroring with something like "model not found," that's the reason, and the fix is just picking another entry in the list. prompt is a multiline string - whatever you want Gemini to chew on. The single output, out, is a STRING: wire it into CLIP Text Encode's prompt, into a text node for review, or into another LLM node if you want chained thinking.

    Installation is the same for every node in this pack. Via Manager, search "Comfyui_Gemini2" and install; or manually:

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

    Then grab a (free-tier) key at aistudio.google.com, write it into custom_nodes/Comfyui_Gemini2/key.txt - nothing else, just the key, no quotes - and restart. One dependency the README never mentions: the code imports cv2, while requirements.txt only lists google-generativeai and requests. If the node errors with "No module named 'cv2'", fix it with pip install opencv-python-headless.

    Gotchas worth repeating: if you get "Gemini API key is required", the key file is empty or misplaced - fill it in before you load the workflow. And remember what you're signing up for: your prompts leave your machine and hit Google, and calls cost a little money past the free tier. That key sits in plaintext in the pack folder, so don't share the folder, and don't expose a bare ComfyUI to the internet - custom nodes and open ports have a rough history in this community.

    CategoryCXH/gemini

    Inputs (2)

    NameTypeDefaultDescription
    modelCOMBO7 options: gemini-2.0-flash-exp, gemini-1.5-pro, gemini-1.5-flash, gemini-1.5-flash-8b, learnlm-1.5-pro-experimental, gemini-exp-1114, +1
    promptSTRING

    Outputs (1)

    NameTypeDescription
    outSTRING