Converge AI Gateway
Converge AI Gateway · Tokens

Count tokens (Anthropic format)

POST

Counts the input tokens of an Anthropic Messages request without generating output.

Request

Request line
POST https://models.convergestudios.ai/v1/messages/count_tokens
Authentication

A Converge AI Gateway virtual key, sent as Authorization: Bearer <virtual key>. The key is issued per team and is valid only for the model routes of the gateway.

Request body

JSON, with Content-Type: application/json. A dash in the Required column means that requiredness is not stated.

FieldTypeRequiredDescription
modelstring—Model id from `GET /v1/models`.
messagesarray—The conversation to count.

Examples

Count tokensShow
Request (curl)
curl -sS -X POST https://models.convergestudios.ai/v1/messages/count_tokens \
  -H "Authorization: Bearer $GATEWAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gemini/gemini-3.1-flash-lite",
  "messages": [
    {
      "role": "user",
      "content": "Reply with the single word: pong"
    }
  ]
}'
Response — 200
{
  "input_tokens": 8,
  "litellm_count_source": "provider"
}

Response

200. input_tokens. litellm_count_source tells whether the model provider (provider) or a local estimate counted the tokens.

FieldTypeDescription
input_tokensinteger—
litellm_count_sourcestring—

Behaviour

Two token counters

POST /v1/messages/count_tokens returns the count of the model provider. POST /utils/token_counter can return a local estimate (count_source: "local_estimate"), which differs from the provider count for the same messages.