Nodes/ComfyUI-Gemini-3/Gemini 3 使用缓存
ComfyUI Node

Gemini 3 使用缓存

Ask questions against a stored context

By xuchenxu168·Created 10 months ago·Updated 10 months ago· 4
Gemini 3 使用缓存
    • response
    • usage_metadata
    prompt基于缓存的内容回答问题...
    cache_name
    api_providergoogle
    api_key
    modelgemini-3-pro-preview

    This node is deliberately thin, and that's the point. Gemini3UseCachedContent takes a question, a cache name, and - without resending the big document - asks Gemini to answer as if the cached content were sitting in the prompt. It's the consumer half of the pack's caching pair; Gemini3ContextCache creates the cache, this node spends it.

    You wire the cache_name output of a Gemini3ContextCache node into this node's cache_name input, add your question, and the response comes back grounded in that stored context. The win shows up in usage_metadata: it reports cachedContentTokens, the number of input tokens served from cache at the discounted rate instead of full price. For any workflow that re-asks a long fixed context (spec sheets, lore docs, reference material), this is where the cost savings actually land.

    How it works

    The node builds a normal generateContent request with your prompt and adds cachedContent to the payload - the server then treats the named cache as the beginning of the conversation context. No content is re-sent; that's the entire trick. The request goes through the same client as every other node in the pack, with the same API-key resolution (field → config.jsonGEMINI_API_KEY).

    Note what it does not do: there's no thinking-level control, no temperature, no system instruction, no media. It's a minimal query node by design - your prior questions set the tone, so the knobs aren't needed here.

    Inputs and outputs that matter

    Required: prompt (your question), cache_name (the server reference - wire it from the create-cache node's cache_name output, not the label you typed), plus the four standard auth/model fields.

    Outputs: response (the answer) and usage_metadata (JSON including cachedContentTokens - check it once to confirm the cache is actually being hit; if that number is 0, you're paying full price without realizing it).

    Install

    Same pack as everything here. ComfyUI Manager (search "ComfyUI-Gemini-3") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/xuchenxu168/ComfyUI-Gemini-3
    cd ComfyUI-Gemini-3
    pip install -r requirements.txt
    

    No downloads. Google AI Studio key via api_key field, config.json, or GEMINI_API_KEY.

    Common issues

    • "Error: 404" or "cache not found" - the cache expired (TTL passed) or the name is wrong. The server cache name is cachedContents/xxxx, not the friendly label; if you typed the label, nothing matches. Re-run the create node.
    • cachedContentTokens: 0 - the cache reference isn't being applied. Usually means the name wasn't wired correctly or the cache was created against a different model; the cache is model-bound.
    • Cache must exist before this node runs - ComfyUI doesn't guarantee execution order unless you wire the dependency, so make sure the create node's output actually feeds this node's cache_name. Without that wire, it's a lottery which one runs first.
    • It's a thin wrapper, not a debugger - if the answer feels wrong, the problem is almost always in what you cached (or didn't), not in this node. Check cache_info.expireTime from the create side.
    CategoryGemini3/优化

    Inputs (5)

    NameTypeDefaultDescription
    promptSTRING基于缓存的内容回答问题...
    cache_nameSTRING
    api_providerCOMBOgoogle1 options: google
    api_keySTRING
    modelCOMBOgemini-3-pro-preview1 options: gemini-3-pro-preview

    Outputs (2)

    NameTypeDescription
    responseSTRING
    usage_metadataSTRING