Converge AI Gateway
Converge AI Gateway · Tokens

Count tokens

POST

Counts the tokens of a chat request without generating output.

Request

Request line
POST https://models.convergestudios.ai/utils/token_counter
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/utils/token_counter \
  -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
{
  "total_tokens": 14,
  "request_model": "gemini/gemini-3.1-flash-lite",
  "model_used": "gemini-3.1-flash-lite",
  "tokenizer_type": "openai_tokenizer",
  "count_source": "local_estimate",
  "original_response": null,
  "error": false,
  "error_message": null,
  "status_code": null
}

Response

200. total_tokens. count_source tells whether the model provider or a local estimate (local_estimate) counted the tokens.

FieldTypeDescription
total_tokensinteger—
request_modelstring—
model_usedstring—
tokenizer_typestring—
count_sourcestring—
original_responsenull—
errorboolean—
error_messagenull—
status_codenull—

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.