messages

Count Message Tokens

Changed on

Anthropic /v1/messages/count_tokens-compatible endpoint.

Returns {"input_tokens": N} without contacting an upstream provider: counting is local, so there is no budget reservation, pricing, or usage logging. Authentication mirrors :func:create_message — hybrid mode resolves the caller's token against the platform, standalone mode validates the API key — so the endpoint is not an open token-counting oracle.

post/api/v1/messages/count_tokens

Request

  • The document declares no server URL.
  • Auth: one of:
    • API key in header Otari-Key
    • API key in header x-api-key

Request body

betasstring[] nullable
cache_controlobject nullable
context_managementobject nullable
messagesobject[] required
metadataobject nullable
modelstring required
thinkingobject nullable
tool_choiceobject nullable
toolsobject[] nullable

Response

Successful Response

input_tokensinteger required

Changes

    • info

      added the optional property to the response with the status

    • info

      api operation id count_message_tokens_api_v1_messages_count_tokens_post removed and replaced with messages-count_message_tokens