Token counting
Token counting enables you to determine the number of tokens in a message before sending it to Claude, helping you make informed decisions about your prompts and usage. With token counting, you can
- Proactively manage rate limits and costs
- Make smart model routing decisions
- Optimize prompts to be a specific length
How to count message tokens
The token counting endpoint accepts the same structured list of inputs for creating a message, including support for system prompts, tools, images, and PDFs. The response contains the total number of input tokens.
The token count should be considered an estimate. In some cases, the actual number of input tokens used when creating a message may differ by a small amount.
Supported models
The token counting endpoint supports the following models:
- Claude 3.7 Sonnet
- Claude 3.5 Sonnet
- Claude 3.5 Haiku
- Claude 3 Haiku
- Claude 3 Opus
Count tokens in basic messages
Count tokens in messages with tools
Count tokens in messages with images
Count tokens in messages with extended thinking
See here for more details about how the context window is calculated with extended thinking
- Thinking blocks from previous assistant turns are ignored and do not count toward your input tokens
- Current assistant turn thinking does count toward your input tokens
Count tokens in messages with PDFs
Token counting supports PDFs with the same limitations as the Messages API.
Pricing and rate limits
Token counting is free to use but subject to requests per minute rate limits based on your usage tier. If you need higher limits, contact sales through the Anthropic Console.
Usage tier | Requests per minute (RPM) |
---|---|
1 | 100 |
2 | 2,000 |
3 | 4,000 |
4 | 8,000 |
Token counting and message creation have separate and independent rate limits — usage of one does not count against the limits of the other.
FAQ
Was this page helpful?