API reference · API
Count a message's input tokens (Anthropic wire format), an estimate
POST/v1/messages/count_tokensAPI key
Anthropic's token counter, which the Anthropic clients call as messages.countTokens. The count is the gateway's own estimate over the request (the messages, the system prompt, a flat allowance per image and the tools as JSON), not a vendor tokenizer's: within roughly a fifth on English prose. The answer says so, with estimate: true and x-antimatter-token-count: estimate. Free, and nothing is sent upstream. Takes the chat scope, with its own rate window.
Request body
application/json, required
| Field | Type | What it is |
|---|---|---|
| modelrequired | string | |
| system | any | |
| messagesrequired | array of object | |
| tools | array of object | |
| tool_choice | object |
Example
{
"model": "antimatter/auto",
"messages": [
{}
]
}Answer 200
The estimate.
Headers: x-antimatter-request-id, x-request-id, x-antimatter-token-count
| Field | Type | What it is |
|---|---|---|
| input_tokens | integer | |
| estimate | true |
Errors
- 400Anthropic shaped error.
- 401Anthropic shaped error.
- 403Anthropic shaped error.
- 404Anthropic shaped error.
- 413Anthropic shaped error.
- 429Anthropic shaped error.
Every error answers in one shape, with its type, code and the field it names. The whole list is in the docs' Errors section.