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.
/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 generate a charge or reserve credits for a later inference request. Generation checks for a positive available balance, model availability and spending limits, then charges actual usage after completion. See billing.