Skip to main content
POST
Count message tokens
Related guide: Anthropic Messages API. See the Anthropic Messages API guide for token counting against a resolved model.

Authorizations

Authorization
string
header
required

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

Body

application/json
messages
object[]
required

Conversation so far, oldest turn first.

model
string
required

Model whose tokenizer counts the request.

cache_control
object

Applies a cache_control marker to the last cacheable block.

output_config
object

Output shaping for the request.

system

System prompt: a string, or an array of text blocks that can each carry cache_control.

thinking
Manual budget · object

Extended thinking configuration.

tool_choice
Auto · object

Tool selection policy.

tools
(Custom tool · object | Server tool · object)[]

Tools the model may call: custom tools with an input_schema, or Anthropic server tools such as web_search.

A tool the caller executes.

Response

Token count for the request.

input_tokens
integer<int64>
required

Number of input tokens the request would consume.