Text Preview + Token Count
Token counting you can trust — and the 75-token wall it makes visible
- clip
- text
- tokens
- report
The reason you want this node is the 75-token wall. An LLM writing your prompts will happily hand you a 300-token masterpiece - but if you're on SDXL or any CLIP-encoded model, the encoder splits your prompt into chunks and everything past token 75 lands in a new chunk, which quietly weakens the whole thing. This node is a text preview that counts, so the problem shows up on screen in red instead of as a mystery quality drop. It's the Text Preview + Token Count node, and it's exactly as useful as that sounds.
How it works
Feed it text (or type into the box) and it shows the text on the node plus a count. Four counting methods, picked with the tokenizer dropdown, plus auto:
- estimate - pure arithmetic, needs nothing installed, lands within ~15%. It takes the larger of characters/4 and words×1.33, so comma-heavy tag soup doesn't get undercounted - the direction that actually costs you.
- CLIP (connected) - connect the
clipof your image model and you get the exact count the encoder will see. The padding and start/end markers are measured from the encoder itself by tokenizing an empty string, so it works on CLIP-L, CLIP-G, T5 and whatever ships next, no hard-coding per flavour. - tiktoken - OpenAI's BPE, for budgeting (o200k for GPT-4o/GPT-5, cl100k for GPT-4/3.5). Requires
pip install tiktoken. - LLM server /tokenize - posts to a vLLM server's
/tokenizeendpoint for the exact count for the model that will actually read the prompt. LM Studio doesn't serve/tokenize, so on LM Studio it falls back to the estimate and says so.
auto picks the best of what's available: connected CLIP, then tiktoken if installed, then the estimate. Anything that fails just falls back to the estimate with a note in the report - it never hard-errors the graph.
token_limit is the budgeting knob. Set it to 75 (the CLIP chunk) and the report tells you how many tokens are left, or how far over you are - in red. When counting through CLIP, going past 75 also prints how many chunks the encoder will split the prompt into. That number is the whole reason to install this node: it makes a silent quality killer visible.
Outputs
text- the text, passed straight through. Wire this downstream if you want the preview node sitting in your prompt path without touching the text.tokens- the count as an INT, which you can feed into logic or a display node.report- the full multi-line summary: count, method, chars/words/lines, budget status, chunk warnings.
Install
Part of the comfyui-llm-prompt-studio pack. ComfyUI Manager: search comfyui-llm-prompt-studio, or:
cd ComfyUI/custom_nodes
git clone https://github.com/grandju51/comfyui-llm-prompt-studio
Restart and refresh. Nothing else to install for the estimate or CLIP modes; pip install tiktoken only if you want the OpenAI counts. ComfyUI Manager will offer to handle that dependency automatically.
Notes
The node deliberately has no IS_CHANGED hook. Forcing a re-run on every queue would invalidate everything wired to the passthrough text output and re-sample the whole graph just to redraw a number - a bad trade. Unchanged inputs mean an unchanged count anyway, so it only refreshes when its inputs actually change. Preview nodes like this are the cheap insurance of a ComfyUI graph: they don't touch pixels, they just stop you from shipping a prompt you'd regret.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | The text to preview. Connect a STRING output here, or type into the box to count something by hand. | |
| tokenizer | COMBO | auto | How to count. 'auto' = the connected CLIP if there is one, else tiktoken if installed, else the estimate. The estimate needs nothing installed and lands within ~15%. |
| token_limit | INT | 00–1000000 | Budget to compare against: the report says how many tokens are left or how far over you are. 0 = off. 75 is the CLIP chunk, 77 the raw CLIP slot count. |
| clipopt | CLIP | Connect the CLIP of your image model to count the tokens it will actually see (75 per chunk). | |
| base_urlopt | STRING | http://localhost:1234/v1 | Only for 'LLM server /tokenize': the same address as the generator node. vLLM serves /tokenize; LM Studio does not, and falls back to the estimate. |
| api_keyopt | STRING | lm-studio | — |
| modelopt | STRING | Only for 'LLM server /tokenize'. Empty = the server picks its loaded model. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |
| tokens | INT | — |
| report | STRING | — |