Skip to main content
POST /v1/messages/count_tokens accepts model and messages, plus Messages input fields such as system, tools, thinking, and image blocks. It returns input_tokens without generating a completion.
Use the API origin without /v1 for the Anthropic SDK. This operation requires the customer key’s inference:write permission. It does not stream, create an inference usage event, or settle a token charge. It still consumes the workspace’s request-rate allowance and requires an actively priced model. The result comes from the active backend. Its counting implementation can use an estimator when its native tokenizer is unavailable, so treat the count as a planning aid rather than a guaranteed bill. Generated output and subsequent tool rounds are not included. A count request does not reserve credits for a later inference request. Generation still checks current balance, model availability, and spending limits. The conservative billing reservation is calculated independently of this count.