EZAT RouterDocs

Count tokens

POST
/v1/messages/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.

Authorization

headerx-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.

Header Parameters

anthropic-version?string

Accepted for compatibility with Anthropic's SDKs, which send it, but not used. You don't need to send it.

x-request-id?string

Your 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.

Match^[A-Za-z0-9._:-]{1,128}$

Request Body

application/json
  1. body

The same body as for creating a message. model and messages are required; max_tokens and stream are ignored.

model*ModelName

A 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.

Length1 <= length <= 128
messages*array<>
Items1 <= items
system?|array<>

The system prompt, as a string or an array of text blocks.

tools?array<>
thinking?
[key: string]?any

Response Body

The number of input tokens.

application/json
  1. response
input_tokens*integer

Tokens in the system prompt, tools and messages.

Range0 <= value
Example Request
curl -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?"    }  ]}'
Example Response
{  "input_tokens": 23}