Nodes/ComfyUI-NanoBanana2/NanoBanana - API Key
ComfyUI Node

NanoBanana - API Key

The one node you wire into everything else first

By IxMxAMAR·Created 6 months ago·Updated about a month ago· 4
NanoBanana - API Key
    • api_key
    api_key

    Every generative node in the NanoBanana2 pack needs a Google Gemini API key, and this is the clean way to supply one. It's a boring node on purpose: a single password-masked text field and one output that hands the key to whatever you wire it into. Think of it as the pack's power cable - plug it into your ImageGen, your chat node, your music node, and they all share the same credential.

    You can skip it entirely if you want. Every action node has its own api_key input, and if you leave that blank it falls back to the GEMINI_API_KEY environment variable. The API Key node is for people who'd rather see and control the credential in the graph than fuss with env files - and for wiring one key into many nodes without pasting it everywhere.

    How it works

    The class is a tiny wrapper around an env-var check. Its input is api_key; if you type a key in, that's what's used. If you leave it blank, it reads GEMINI_API_KEY from the environment. Either way the output api_key is a plain STRING that plugs into any other NanoBanana node's api_key input.

    Two touches make it nicer than it sounds. The input is password-masked, so the key isn't plastered across your screen and your screenshots. And the env-var fallback strips surrounding quotes - the classic .env mistake of writing GEMINI_API_KEY="AIza..." with quotes included, which silently breaks auth. That's handled for you.

    The pack also redacts keys everywhere else: any error string that reaches the UI or logs gets run through a regex that blanks out AIza[...] keys and auth headers, so a leaked key in an exception message is a lot less likely.

    Getting the key

    Grab one at aistudio.google.com - hit "Get API Key", copy it, done. It's the only setup this pack needs; there are no model files, no local weights, nothing to download. The dependency is just the google-genai SDK.

    cd ComfyUI/custom_nodes
    git clone https://github.com/IxMxAMAR/ComfyUI-NanoBanana2
    pip install google-genai
    

    Or search NanoBanana2 in ComfyUI Manager. Restart, add the API Key node, paste, and feed the output into whatever you're running.

    Gotchas

    The big one is that keys are account-scoped and region-sensitive. A key from a free-tier account can't see preview models, and some models aren't available to every region - that's why this pack also ships List Available Models (to show what your key can actually access) and Network Route (for US-egress proxying). If a generative node 400s with a model error, the key is usually the first suspect - check the console, not just the node.

    Also worth knowing: the pack caches client connections per key (hashed, LRU-bounded), so rotating keys across workflows won't grow memory forever, but if you rotate a key mid-session and old connections misbehave, a ComfyUI restart clears the cache cleanly.

    CategoryNanoBanana2/Config

    Inputs (1)

    NameTypeDefaultDescription
    api_keySTRINGYour Google Gemini API key. Leave blank to use GEMINI_API_KEY environment variable.

    Outputs (1)

    NameTypeDescription
    api_keySTRING