Nodes/ComfyUI TK3R Extensions/TK3R CLIP Text Encode With Token Count
ComfyUI Node

TK3R CLIP Text Encode With Token Count

Stop guessing whether your prompt fits in the token budget

By TK3R·Created 7 months ago·Updated 7 months ago· 2
TK3R CLIP Text Encode With Token Count
  • clip
  • conditioning
  • token_count
  • info
text
system_promptnone

Every text encoder has a token ceiling, and it's almost never the number you'd guess from reading the prompt. SD 1.5 and SDXL chunk their 77-token budgets, Flux's T5 runs at 256 or 512 depending on the variant, and by the time you've stacked adjectives you genuinely can't tell whether the tail of your prompt got encoded or silently dropped. TK3R CLIP Text Encode With Token Count is the fix: it's the normal CLIP Text Encode, plus it tells you the character count and the real token count after encoding.

That's the whole pitch, and it's honestly the one I'd reach for when I'm doing prompt iteration on a new model. Instead of writing 120 words and hoping, you get a number you can trust.

How it works

It tokenizes your text with clip.tokenize(), counts the non-padding tokens (it has to be careful here - the tokenizer pads everything out to a fixed length, so it looks for the repeating end/pad pattern and stops counting there), and then encodes from those tokens exactly like the stock node. The conditioning you get out is identical to what CLIP Text Encode would produce; the token count is a bonus output, not a change in behavior.

It also merges in the Lumina2 system-prompt node, so if you're on a Lumina2 model you can skip a separate node - the system_prompt dropdown injects the "superior" or "alignment" prompt prefix for you.

The inputs and outputs

Only three inputs, all obvious:

  • text - your prompt, multiline.
  • clip - the CLIP model, usually from your checkpoint or dual-text-encoder loader.
  • system_prompt - none (default, correct for everything that isn't Lumina2), or one of the two Lumina2 presets.

Outputs:

  • conditioning - identical to the stock node, wires into your sampler.
  • token_count - an INT, so you can actually wire it into logic or a text node rather than just eyeballing it.
  • info - a STRING with the total token count, character length, and a per-tokenizer breakdown when the model has more than one text encoder.

The node is marked as an output node, so the info text shows up in its UI widget after a run.

Installing

Part of the TK3R Extensions pack:

  • ComfyUI Manager → search "TK3R Extensions" → Install, then restart.
  • Or cd ComfyUI/custom_nodes && git clone https://github.com/TK3R/ComfyUI_TK3R_Ext and restart.

Only dependency is rich; nothing to download.

The one thing to remember

Leave system_prompt on none unless you're literally running Lumina2. The tooltip says it, and it's right - pasting a system prompt into a Qwen or Flux encoder does nothing useful. And don't panic when the count includes the start and end tokens; that's how the tokenizers actually budget, and the number you see is the number that matters.

CategoryTK3R/Utility

Inputs (3)

NameTypeDefaultDescription
textSTRINGThe text to be encoded.
clipCLIPThe CLIP model used for encoding the text.
system_promptCOMBOnoneSystem prompt for Lumina2 models. Use 'none' for other models.

Outputs (3)

NameTypeDescription
conditioningCONDITIONING
token_countINT
infoSTRING