Count tokens API: free pre-send token estimate
Estimate the input tokens of a Messages request for free, on an ordinary API key, without the gateway calling a model.
Size a Messages request before you send it with POST /v1/messages/count_tokens at https://api.uplinkswitch.com/v1, for free and with no model call.
Route
| Method | Path | Auth | Cost |
|---|---|---|---|
| POST | /v1/messages/count_tokens | an ordinary API key | free (no model call) |
Request
| Field | Type | Notes |
|---|---|---|
| model | string | include the Messages model id: the schema only requires messages, but the documented 400 response includes a missing model |
| messages | array | required; the message list, same shape as a Messages request |
| system | string or array | optional; system prompt |
| tools | array | optional; tool definitions |
Response
| Field | Notes |
|---|---|
| input_tokens | integer; estimated input tokens. Counted locally (roughly four characters per token plus a few per message, each image about 1,600 tokens). It errs high, so treat it as an estimate. |
Example
bash
curl https://api.uplinkswitch.com/v1/messages/count_tokens \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"claude-sonnet-5-5","messages":[{"role":"user","content":"hello"}]}'Errors
| Status | Code | When |
|---|---|---|
| 400 | invalid_request | no model, or messages is not a list |
| 401 | invalid_api_key | missing or invalid key |
| 413 | invalid_request | body too large |
Questions and answers
No. It is free and the gateway never calls a model, so nothing bills.
It is an estimate that runs locally and errs high, but is not a ceiling or a tokenizer guarantee. Billing uses the model-reported count.
Any ordinary API key on your org. There is no admin requirement.
Each image counts as about 1,600 tokens, added to the text estimate.
You get 413 invalid_request. Trim the messages or send fewer at once. ## Sources Live OpenAPI, checked 2026-11-22.