Anthropic Count Tokens
The Count Tokens operation in the Anthropic Messages API.
The Count Tokens operation in the Anthropic Messages API
Count Tokens is a specific operation in the Anthropic Messages API. It uses the same API-family authentication and model-product selection. It does not create a model-call charge settlement, but it still checks the user key, balance, model, and upstream availability.
Paths
| Purpose | Method and path |
|---|---|
| Count tokens | POST /v1/messages/count_tokens |
| Compatible path | POST /anthropic/v1/messages/count_tokens |
Request example
curl https://dingjiai.com/v1/messages/count_tokens \
-H "x-api-key: YOUR_USER_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "Copy a model name from the Anthropic model list",
"messages": [
{ "role": "user", "content": "Estimate the token count for this input" }
]
}'Actual boundaries
Prop
Type
Request-body handling
When forwarding Count Tokens, the gateway removes fields that are needed only for generation requests, such as stream, temperature, top_p, top_k, stop, and stop_sequences.
It cannot bypass balance checks
Count Tokens is not billed, but it is not fully anonymous or an offline calculation. The call still fails when the user key is invalid, the balance is insufficient, the model is not open for the entry, or no upstream is available.
Last updated on