Skip to main content
POST
Count Anthropic Tokens

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

Body for /v1/messages/count_tokens, same fields as messages but max_tokens is optional.

Not a pass-through body: count_tokens_for_request runs litellm's tokenizer locally and never builds a provider call, so there is nothing for an unknown field to reach. Unknown fields are dropped rather than refused, which also keeps tags working here: this body does not inherit TagsBody, and litellm happens to reserve that name.

model
string
required
messages
AnthropicMessage · object[]
required
Minimum array length: 1
system
tools
Tools · object[] | null
tool_choice
Tool Choice · object | null

Response

Successful Response

Response body for POST /v1/messages/count_tokens.

input_tokens
integer
required

Number of input tokens the request would consume.