Application Process
To use the Claude Messages Count Tokens API, you can first go to the Claude Messages Count Tokens API page and click the “Acquire” button to obtain the credentials needed for the request. If you are not logged in or registered, you will be automatically redirected to the login page inviting you to register and log in. After logging in or registering, you will be automatically returned to the current page. This API is completely free to use and does not consume any quota.Basic Usage
The request path for the Claude Messages Count Tokens API is/v1/messages/count_tokens, consistent with the official Anthropic API. We need to provide at least two required parameters:
model: Choose the Claude model to use, such asclaude-sonnet-4-5-20250929,claude-opus-4-20250514, etc.messages: An array of input messages, each containingroleandcontent.
system: System prompt, which will be included in the token count.tools: Tool definitions, which will be included in the token count.thinking: Extended thinking configuration.
cURL Example
Python Example
Using Anthropic SDK
The Claude Messages Count Tokens API is fully compatible with the official Anthropic SDK and can be called directly using theanthropic library.
Token Count Including Tools
If your request includes tool definitions, these tools will also be included in the token count:Token Count Including System Prompts
System prompts will also be included in the token count:Notes
- This API only calculates the input token count and does not produce any model output.
- The token count result can be used to estimate the cost of calling the Claude Messages API.
- The tokenization method may vary for different models, so please use the same model parameter as in the actual call.
- This API is completely free and does not consume any quota.

