Claude Token Counter
Know what a call costs before you make it
- client
- token_count
- summary
Paid LLM nodes have a way of sneaking up on your wallet - you build a workflow that calls Claude five times per image, and the bill appears later. Claude Token Counter is the odometer you wish you'd added first. It counts the tokens in any text and estimates the cost against Anthropic's published per-million-token pricing, before any request goes out.
It's an output node (is_output_node in the schema), so you drop it on the canvas, feed it text, and read the results. It won't call the API on its own unless you connect a client.
How it counts
Two paths, and the difference is honesty:
- With a
clientconnected (from the Claude API Client node): it uses Anthropic's own tokenizer for an accurate count. This is the real number. - Without a client: it falls back to a ~4 characters-per-token estimate. Fine for rough sanity checks, wrong enough to matter for CJK text or heavy code.
The pricing table ships inside the pack (claude/pricing.json), keyed to model - so pick the model you actually use (claude-sonnet-5 is the default). If the prices look stale, that's the file to check; the pack can't auto-refresh a JSON it ships.
Inputs
- text - what to count. Multiline.
- model - which Claude model's pricing to use. A token count doesn't depend on the model, but the cost does, and the summary reflects that.
- client - optional, but connecting it upgrades the estimate to a real API-based count. You generally want this on if you're serious about the number.
Outputs
- token_count - the raw
INT, so you can wire it into other logic ("if under N tokens, proceed"). - summary - a human-readable
STRINGwith the count and the estimated input/output cost. Wire this into Preview Anything to actually see it.
Install and gotchas
It's part of the ERPK Collection; ComfyUI Manager → search erpk → ERPK Custom Nodes, or git clone https://github.com/eRepublik-Labs/comfyui-nodes-erpk.git erpk into custom_nodes/, then pip install -r requirements.txt and restart. No key needed to use the estimator - the count happens locally. Connect a client only if you want the accurate API-backed number (which does spend a tiny bit of an API call, though counting endpoints are cheap).
Where people trip: they feed it the prompt but forget that the real cost driver is the response - Claude pricing counts both input and output tokens, and output tokens are usually pricier per token. The summary shows both, so read the output column, not the headline number. And if you're chaining many calls, count the system prompt too; that's billed on every call in the chain.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | Text to count tokens for | |
| model | COMBO | claude-sonnet-5 | Model for token counting and cost estimation |
| clientopt | CLAUDE_API_CLIENT | Optional: Connect client for accurate API-based counting (otherwise uses ~4 chars/token estimation) |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| token_count | INT | — |
| summary | STRING | — |