Token counting (beta)
Token counting is in beta
To access this feature, include the anthropic-beta: token-counting-2024-11-01
header in your API requests, or use client.beta.messages.count_tokens
in your SDK calls.
We’ll be iterating on this open beta over the coming weeks, so we appreciate your feedback. Please share your ideas and suggestions using this form.
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.
Count tokens in basic messages
{ "input_tokens": 14 }
Count tokens in messages with tools
{ "input_tokens": 403 }
Count tokens in messages with images
{ "input_tokens": 1551 }
Count tokens in messages with PDFs
{ "input_tokens": 2188 }
The Token Count API 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.