Nodes/comfyui-llm-prompt-studio/Token Count (simple)
ComfyUI Node

Token Count (simple)

The '~123 tokens' box — the honest, boring, correct version

By grandju51·Created 2 months ago·Updated 11 days ago· 5
Token Count (simple)
    • text
    • tokens
    text

    This is the simplest node in the pack and it knows it. Text goes in, a number like ~123 tokens shows up on the node. No tokenizer dropdown, no CLIP to connect, nothing to install, no failure modes. It's the Token Count (simple) node, and for most people most of the time, it's the one to use.

    What it does

    Feed it text - by typing into the box, or by wiring a STRING output from anywhere in your graph (the LLMPromptStudio prompt output is the obvious match) - and it counts. The count is a heuristic: it takes the larger of characters / 4 and words × 1.33, which are the two rules of thumb for prose and for comma-heavy tag soup respectively. Taking the max keeps it from undercounting the kind of text a prompt writer actually produces. Expect it within roughly 15% of a real tokenizer, and expect it to be on the safe side for Danbooru-tag blocks.

    Two outputs, both exactly what they look like:

    • text - the input, passed straight through unchanged.
    • tokens - the count as an INT, if you want to do something with the number (feed a text formatter, drive logic, show it somewhere).

    The on-node display shows only the count, not the text - that's the whole point of this node being "simple." If you want the text visible and the count, that's the sibling node, Text Preview + Token Count, which is strictly more capable (exact CLIP counts, budgets, tiktoken) at the cost of a dropdown and two more sockets.

    When to reach for it

    Quick sanity checks mostly. Is this LLM output about to blow a context window? Roughly how big is a batch of prompts? Does the count change as I tweak a card? For all of those, a ~15% ballpark is plenty and this node is the least effort on offer. It's also the least likely to break: it's arithmetic on a string, so there's no CLIP to forget to connect, no server to be down, no package to be missing. A tool that cannot fail is worth having in a graph full of things that can.

    When to grab the fancier sibling instead

    You need the exact number the model will see - a 75-token CLIP budget, or counting against a vLLM server's context - only then is it worth wiring up the Text Preview + Token Count node with a connected clip or a base_url. If "close enough, right now" is the question, this is the answer.

    Install

    Part of the comfyui-llm-prompt-studio pack, so install the pack and it's there:

    cd ComfyUI/custom_nodes
    git clone https://github.com/grandju51/comfyui-llm-prompt-studio
    

    Restart ComfyUI and refresh the browser. That's the entire installation - the pack has zero external dependencies, and this node doesn't even need the optional ones. It appears under Add Node → LLM Prompt Studio. If you don't have ComfyUI Manager, install it first and search comfyui-llm-prompt-studio there - same result, one click.

    CategoryLLM Prompt Studio

    Inputs (1)

    NameTypeDefaultDescription
    textSTRINGThe text to measure. Connect a STRING output here, or type into the box.

    Outputs (2)

    NameTypeDescription
    textSTRING
    tokensINT