API reference
Count tokens
POST /v1/messages/count_tokens estimates how many input tokens a Messages request would use. It costs nothing.
POST
https://gateway.kalsenti.ai/v1/messages/count_tokensOn this page
Request
Send the body you’d send to Messages, without max_tokens. The same headers are needed, including anthropic-version. The Python and JavaScript snippets use an Anthropic SDK client set up as on the SDKs page.
curl https://gateway.kalsenti.ai/v1/messages/count_tokens \
-H "x-api-key: $KALSENTI_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-1017-raw",
"system": "You are a concise assistant.",
"messages": [{ "role": "user", "content": "Name three sea birds." }]
}'Response
{ "input_tokens": 40 }An unknown model gets a 404 with not_found_error, and a body that can’t be read as a Messages request gets a 400, as it would from Messages itself.
How the count is made
The count is an estimate. The tokens you’re charged for can be a little different.
- It’s worked out from the size of the request, at about four bytes per token, because every model counts tokens a little differently.
- It doesn’t reach a model and costs nothing, and it doesn’t appear on the Usage page.
- It does count as a request towards your key’s rate limit.