DocsPOST /v1/messages/count_tokens
POST

/v1/messages/count_tokens

API reference

Counts the input tokens of an Anthropic Messages request without running generation. Works with Claude models only.

1Request example

bash
curl https://api.zukko.pro/v1/messages/count_tokens \
  -H "Authorization: Bearer fetch_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{"model":"claude-sonnet-5","system":"You are an assistant","messages":[{"role":"user","content":"Hello!"}]}'

The body is the same as for POST /v1/messages; max_tokens is not needed.

2Response

json
{
  "input_tokens": 12
}

3Cost and requirements

  • The request is billed: the counted tokens are charged at the model's input price. 12 tokens on claude-sonnet-5 ($0.2 per 1M) cost 2.4 microdollars, rounded to a whole microdollar — $0.000002.
  • As with generation, you need a verified email and a balance of at least $0.01; key limits apply.
  • The Zukko cache and Idempotency-Key do not apply to this endpoint.
  • Works for Claude, GPT, Gemini, Qwen, and DeepSeek. Counting is not supported for GLM.
POST /v1/messages/count_tokens · Zukko Docs