ComfyUI Node

Token Counter

Token Counter counts words, not tokens — know what you're buying

By NMWave·Created 2 years ago·Updated 6 months ago· 6
Token Counter
    • Token_COUNT_INT
    input_string

    Let's get the honest disclaimer out of the way first: the name is a lie. Token Counter doesn't count model tokens - it splits your string on whitespace and counts the pieces. That's a word count. A real CLIP or T5 tokenizer breaks text into subword pieces, so 1girl, long hair, looking at viewer reads as six words here while a tokenizer might chew it into eight or ten tokens. If your goal is to know exactly how many tokens a specific text encoder will burn, use a real tokenizer node. If your goal is a quick sanity check that your prompt isn't spiraling out of control, this is perfect.

    What it's actually good for

    Prompt hygiene in a visual form. ComfyUI gives you almost no feedback about prompt length while you're building, and it's easy to glue together a monster. Wire the output of your prompt assembly into Token Counter and you get a live number on the graph that updates every run - an easy way to compare "does dropping these five style tags actually change the length meaningfully?"

    It also plays nice with the rest of the Nader pack. Run Token Counter on a tag string to see how long it is, then use Split Tags to carve it into chunks if it's too long for what you're feeding.

    The mechanics

    One input - input_string - one output, Token_COUNT_INT, an INT that the node displays directly (it's marked as an output node, so it shows its value without needing a display widget). The count is just len(input_string.split()).

    Two quirks fall out of that:

    • Whitespace is the only separator. foo, bar counts as two, but foo,bar (no space) counts as one. Commas don't split anything.
    • Collapsed whitespace is free. Multiple spaces between words don't inflate the count, because split() swallows them. That's actually a feature - it's forgiving of messy prompt text.

    For languages written without spaces, or scripts where tokenization gets weird, the number will be misleadingly small. Keep it to sanity-checking your English/Danbooru-tag prompts and you're fine.

    Install

    Same as the rest of this pack. In ComfyUI Manager, search "Nader Tagging", install, restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/NMWave/ComfyUI-Nader-Tagging
    

    No dependencies beyond what ComfyUI already has, no model downloads. This is one of those nodes that takes longer to explain than to install.

    The practical takeaway: use it as a rough prompt-length gauge and a teaching tool for why your prompts are getting long. When you genuinely need a token-accurate number for a specific model's encoder, that's what the dedicated tokenizer nodes are for.

    CategoryNMWave/text

    Inputs (1)

    NameTypeDefaultDescription
    input_stringSTRING

    Outputs (1)

    NameTypeDescription
    Token_COUNT_INTINT