Count tokens
Counts the input tokens a Messages request would use, without running the model. It is free and isn't billed or listed in your usage, but it counts toward your key's requests per minute.
The body is the same as for creating a message. model and a non-empty messages are required. max_tokens and stream are accepted and ignored. The anthropic-beta header is not passed on.
x-api-key<token>Your EZAT Router key (ezat_sk_…) in the x-api-key header, as the Anthropic SDKs send it. Accepted on every /v1 and /openai/v1 endpoint.
anthropic-version?stringAccepted for compatibility with Anthropic's SDKs, which send it, but not used. You don't need to send it.
x-request-id?stringYour own id for this request, echoed in the x-request-id response header (and as request_id in Anthropic-format error bodies). Used only if it is 1 to 128 characters of letters, digits and ._:-; otherwise the gateway makes a new UUID.
^[A-Za-z0-9._:-]{1,128}$application/json- body
The same body as for creating a message. model and messages are required; max_tokens and stream are ignored.
model*ModelNameA canonical model id (anthropic/claude-sonnet-5-5) or an alias (claude-sonnet-5-5, claude-sonnet-5.5), in any letter case. Surrounding spaces are ignored.
1 <= length <= 128messages*array<>1 <= itemssystem?|array<>The system prompt, as a string or an array of text blocks.
tools?array<>thinking?[key: string]?anyThe number of input tokens.
application/json- response
input_tokens*integerTokens in the system prompt, tools and messages.
0 <= valuecurl -X POST 'https://api.router.ezat.io/v1/messages/count_tokens' \ -H "x-api-key: $EZAT_API_KEY" \ -H 'Content-Type: application/json' \ -d '{ "model": "anthropic/claude-sonnet-5-5", "system": "You are a concise assistant.", "messages": [ { "role": "user", "content": "Hello, what can you do?" } ]}'{ "input_tokens": 23}