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_counterAuthentication
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.
| Field | Type | Required | Description |
|---|---|---|---|
| model | string | — | Model id from `GET /v1/models`. |
| messages | array | — | 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.
| Field | Type | Description |
|---|---|---|
| total_tokens | integer | — |
| request_model | string | — |
| model_used | string | — |
| tokenizer_type | string | — |
| count_source | string | — |
| original_response | null | — |
| error | boolean | — |
| error_message | null | — |
| status_code | null | — |
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.
