Count tokens in a Message

Count tokens in a Message

Request

Request payload.
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 objects or nullOptional
Optional tool definitions.
thinkingobjectOptional
Thinking configuration.
tool_choiceobjectOptional
Tool selection policy.
output_configobjectOptional
Optional output configuration options.
cache_controlobject or nullOptional

Optional request-level cache control.

Response

Successful Response
input_tokensinteger
Estimated number of input tokens for the provided payload.

Errors

401
Unauthorized Error
422
Unprocessable Entity Error