API reference

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

Request body fields
FieldTypeWhat it is
modelrequiredstring
systemany
messagesrequiredarray of object
toolsarray of object
tool_choiceobject

Example

{
  "model": "antimatter/auto",
  "messages": [
    {}
  ]
}

Answer 200

The estimate.

Headers: x-antimatter-request-id, x-request-id, x-antimatter-token-count

Fields of the 200 answer
FieldTypeWhat it is
input_tokensinteger
estimatetrue

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.

Antimatter