v51

OpenAPI 3.1.0raw.githubusercontent.com2026-08-018486293.2 KB
messages

Count Message Tokens

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/v1/messages/count_tokens

Request body

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

Response

Successful Response

input_tokensinteger required