Count Tokens
Count tokens for Anthropic Messages API format.
This endpoint follows the Anthropic Messages API token counting specification. It accepts the same parameters as the /v1/messages endpoint but returns token counts instead of generating a response.
Example usage:
curl -X POST "http://localhost:4000/v1/messages/count_tokens?beta=true" -H "Content-Type: application/json" -H "Authorization: Bearer your-key" -d '{
"model": "claude-3-sonnet-20240229",
"messages": [{"role": "user", "content": "Hello Claude!"}]
}'
Returns: {"input_tokens": <number>}
Response
Successful Response
Changes
Changed in 10 of the 42 revisions of this API.20
- ○
api tag
[beta] Anthropic Messages Token Countingaddedapi-tag-added
- ○
api tag
anthropic_passthroughremovedapi-tag-removed
- ○
- ○
api tag
anthropic_passthroughaddedapi-tag-added
- ○
api tag
[beta] Anthropic Messages Token Countingremovedapi-tag-removed
- ○
- ○
api tag
[beta] Anthropic Messages Token Countingaddedapi-tag-added
- ○
api tag
anthropic_passthroughremovedapi-tag-removed
- ○
- ○
api tag
anthropic_passthroughaddedapi-tag-added
- ○
api tag
[beta] Anthropic Messages Token Countingremovedapi-tag-removed
- ○
- ○
api tag
[beta] Anthropic Messages Token Countingaddedapi-tag-added
- ○
api tag
anthropic_passthroughremovedapi-tag-removed
- ○
- ○
api tag
anthropic_passthroughaddedapi-tag-added
- ○
api tag
[beta] Anthropic Messages Token Countingremovedapi-tag-removed
- ○
- ○
api tag
[beta] Anthropic Messages Token Countingaddedapi-tag-added
- ○
api tag
anthropic_passthroughremovedapi-tag-removed
This revision also has 5 changes that name no endpoint, such as unreferenced schemas being removed. See the revision's changelog
- ○
- ○
api tag
anthropic_passthroughaddedapi-tag-added
- ○
api tag
[beta] Anthropic Messages Token Countingremovedapi-tag-removed
This revision also has 21 changes that name no endpoint, such as unreferenced schemas being removed. See the revision's changelog
- ○
- ○
api tag
[beta] Anthropic Messages Token Countingaddedapi-tag-added
- ○
api tag
anthropic_passthroughremovedapi-tag-removed
This revision also has 1 change that name no endpoint, such as unreferenced schemas being removed. See the revision's changelog
- ○
- ○
api tag
anthropic_passthroughaddedapi-tag-added
- ○
api tag
[beta] Anthropic Messages Token Countingremovedapi-tag-removed
This revision also has 19 changes that name no endpoint, such as unreferenced schemas being removed. See the revision's changelog
- ○