TokenCounts processes Claude tokens by querying Anthropic's official `/v1/messages/count_tokens` endpoint. We transmit the exact prompt content array (including multimodal media blocks) to Anthropic and output the precise token sum charged for inference.
We fetch real API counts to account for Anthropic's model-specific headers, system prompt layouts, and multimodal overhead.
| Factor / Area | How Anthropic Counts It | TokenCounts Handling |
|---|---|---|
| Text Inputs | Tokenized using Anthropic's proprietary subword vocabularies (e.g. cl100k_base equivalents). | Sends text inside user messages to the live API to retrieve the exact count. |
| Image Inputs | Calculated dynamically based on aspect ratio and tile resolution. Typically adds ~1,600 tokens per image. | Passes the image base64 directly to count_tokens to capture Anthropic's exact vision count. |
| PDF Attachments | Files are parsed on the server and charged based on text length and formatting. | Sends base64 PDF block data inside document blocks to return the correct count. |
| Overhead | Adds minor metadata wrapping overhead to compile messages. | Anthropic handles billing calculations automatically within the response counts. |