Count tokens in a Message

Count tokens in a Message

Request

This endpoint expects an object.
modelstringRequiredDefaults to default
Model identifier or alias.
messageslist of objectsRequired
Conversation messages for the request.
systemlist of objectsOptional

System prompt input. Accepts str, list[str], System, list[System], or null. It is normalized internally to list[System].

toolslist of objectsOptional
Optional tool definitions.
thinkingobjectOptional
Thinking configuration.
tool_choiceobjectOptional
Tool selection policy.
output_configobjectOptional
Optional output configuration options.
cache_controlobjectOptional

Optional request-level cache control.

Response

This endpoint returns an object.
input_tokensinteger
Estimated number of input tokens for the provided payload.

Errors

401
Unauthorized
422
Unprocessable Entity