Count tokens in a message

Counts the input tokens a Messages request would consume, without calling a model.

Also served at /v1/anthropic/v1/messages/count_tokens; both paths accept the same requests.

Authentication

AuthorizationBearer
Your production key sent as a bearer token.

Request

This endpoint expects an object.
modelstringRequired
messageslist of objectsRequired
systemstring or list of objects or nullOptional
toolslist of objects or nullOptional
tool_choicemap from strings to any or nullOptional
Tool choice, counted as part of the prompt.
thinkingobject or nullOptional
Extended thinking settings for models that support it.

Response

Successful Response
input_tokensinteger

Errors

422
Unprocessable Entity Error