Nodes/ComfyUI-NanoBanana2/NanoBanana - Token Counter
ComfyUI Node

NanoBanana - Token Counter

See how big your prompt is before you pay for it

By IxMxAMAR·Created 6 months ago·Updated about a month ago· 4
NanoBanana - Token Counter
  • network
  • token_count
api_key
modelgemini-2.5-flash
text
custom_model

Gemini bills by the token, and prompts have a way of ballooning past what you expected - a long document pasted into a text node, a giant system instruction, a multi-part context. This node tells you exactly how many tokens a piece of text counts as, for the specific model you plan to use. That's it. One text in, one number out. It's the cheapest node in the pack because counting tokens doesn't consume any generation quota - count_tokens is a free API call.

You'd reach for it when you're on the edge of a context window or trying to budget a workflow that processes a lot of text. It's the natural companion to the pack's Cost Estimator node, which does exactly this count and then multiplies it by a price table.

How it works

Feed text into the node, pick a model (defaults to gemini-2.5-flash), and it calls Google's count_tokens endpoint for that exact model. Token counts differ between models - a tokenizer is per-model - so the model choice matters and you should match it to the model you'll actually generate with. The token_count output is an INT, so you can wire it into a display, feed it into a conditional, or use it to gate a workflow.

The custom_model field lets you count tokens for a model that isn't in the dropdown yet - previews, aliases, whatever Google shipped this week.

Installation

It's one of 29 nodes in the NanoBanana2 pack:

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

Or search NanoBanana2 in ComfyUI Manager. Requires an API key from aistudio.google.com - like every node in the pack, it can take it from the GEMINI_API_KEY env var if you leave the field blank.

Gotchas

The honest caveat: the count is for text. If your real prompt includes images or audio, those eat tokens too, and this node won't account for them - the Cost Estimator has the same limitation. And remember the pack re-runs every node on every execution, so a token count in your graph will recompute each time. That's fine here because it's free, but don't build logic that assumes a cached count.

CategoryNanoBanana2/Config

Inputs (5)

NameTypeDefaultDescription
api_keySTRING
modelCOMBOgemini-2.5-flash35 options: gemini-pro-latest, gemini-flash-latest, gemini-flash-lite-latest, gemini-3-pro-preview, gemini-3-flash-preview, gemini-3.1-pro-preview, +29
textSTRING
custom_modeloptSTRING
networkoptNB_NETWORKOptional. Wire a NanoBanana - Network Route node here to route this request through that proxy (e.g. US egress).

Outputs (1)

NameTypeDescription
token_countINT