Nodes/ComfyUI Gemini Expanded API/Get API Key from JSON
ComfyUI Node

Get API Key from JSON

Keep your Gemini key out of your workflow file

By silveroxides·Created about a year ago·Updated 14 days ago· 5
Get API Key from JSON
    • API_KEY
    json_path./input/apikeys.json
    key_id_methodcustom
    rotation_interval0
    key_idplaceholder

    ComfyUI saves every workflow you touch as a .json file. Type a Gemini API key into a config node and that key now lives in plain text inside the workflow - which means it's in your ComfyUI history, in every backup, and in anything you export or share. There are regular PSAs in the community about how easy it is to leak things this way. GetKeyAPI is the pack's answer to that: a tiny file-reading node that hands you a key from an external JSON file, so the secret never sits in the graph.

    It's a deliberately boring utility, and that's the point. The node opens a JSON file on disk, looks up an entry by name, and outputs the value as a string. Nothing fancy - no API calls, no networking, no dependencies beyond Python's json module. You feed its output into the api_key input of the Configure Gemini API Key node (SSL_GeminiAPIKeyConfig), and you're done.

    The three inputs that actually matter:

    • json_path - path to your keys file. The default is ./input/apikeys.json, but absolute paths work fine too.
    • key_id_method - custom (pick one key by name), random_rotate (pick a random key each run), or increment_rotate (cycle through in order).
    • key_id - the name of the key to grab when key_id_method is custom.

    The file format is a flat dictionary with the key name as the JSON key and the API key as the value, exactly like the GEMINI_API.json example shipped in the repo:

    {
      "key_id_1": "put_key_here",
      "key_id_2": "put_key_here"
    }
    

    Set json_path to that file, key_id to key_id_1, and the API_KEY output carries the value through to your Gemini config node.

    Where the rotation modes earn their keep: Google's free tier throttles per key, and if you're batch-processing a big queue, rotating between a few keys spreads the rate-limit pain. increment_rotate walks the list in order and rotation_interval controls how many entries it jumps each run; random_rotate just shuffles. If you only have one key, custom is all you need.

    Worth knowing before you're confused later: if the file is missing, not valid JSON, or your key_id isn't in it, the node raises a hard error - ComfyUI will show you the message on the node. Also, if key_id is left at the default placeholder with custom selected, you get a warning and likely a "key not found" failure. Set it explicitly.

    Install it the same way as the rest of the pack:

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

    Then restart ComfyUI (or just search "ComfyUI Gemini Expanded API" in ComfyUI Manager and let it handle everything). The pack does need the google-genai dependency, but this node in isolation only needs Python's stdlib - it's the sibling nodes that pull in the API client. No model downloads, because nothing here runs locally; it's all about not leaking a key.

    Categoryutils/api_keys

    Inputs (4)

    NameTypeDefaultDescription
    json_pathSTRING./input/apikeys.jsonPath to a .json file with simple top level structure with name as key and api-key as value. See example in custom node folder.
    key_id_methodCOMBOcustomcustom sets api-key to the api-key with the name set in the key_id widget. random_rotate randomly switches between keys if multiple in the .json and increment_rotate does it in order from first to last, then repeats.
    rotation_intervalINT0how many steps to jump when doing rotate.
    key_idoptSTRINGplaceholderPut name of key in the .json here if using custom in key_id_method.

    Outputs (1)

    NameTypeDescription
    API_KEYSTRING