/messages/count_tokens
Count tokens in messages without generating a response. Useful for estimating costs and staying within context limits.
POST
/v1/messages/count_tokensCount the number of tokens in a message without generating a response. This endpoint does not incur generation costs.
Request Body
modelThe model to use for tokenization (required)messagesMessages to count tokens for (required)Request Body
{
"model": "your-model",
"messages": [
{"role": "user", "content": "Hello, how are you?"}
]
}