Skip to main content

Count the number of tokens in a Message. The Token Count API can be used to count the number of tokens in a Message, including tools, images, and documents, without creating it.

Authorization

The AccessToken must be included in the request as a header when making REST API requests, along with the Content-Type header. You can use the following format for authorization:

--header 'Authorization: Bearer <your_token_here>'
--header 'Content-Type: application/json'

Note: Replace your_token_here with your actual AccessToken. It contains information that allows the server to verify your identity and permissions. You can create your API key here.

Request Body

FieldTypeRequiredDescription
modelstringYesIdentifier of the model to use for generation. Must match one of the models served by the backend.
messagesarrayYesAn array of message objects that make up the conversation history. Each message object should have a role (e.g., "user", "assistant") and content.
systemstring, objectNoOptional system-level instruction that guides the model’s behavior. Can be provided as a plain string or structured object.
tool_choiceobjectNoSpecifies how the model should select tools. Can enforce a specific tool call or allow the model to decide automatically.
toolsobjectNoDefinition of available tools/functions that the model may call. Typically includes name, description, and JSON schema for parameters.

Message Configuration

FieldTypeRequiredDescription
rolestringYesThe role of the message sender (e.g., "user", "assistant")
contentstringYesThe content of the message

Tool

FieldTypeRequiredDescription
namestringYesname of the tool
descriptionstringNodescription of the tool (strongly recommended)
input_schemadictYesJSON Schema for the tool input shape that the model will produce in tool_use output content blocks.

Example for tools

[
{
"name": "get_weather",
"description": "Get the current weather information for a given city.",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "The name of the city, e.g. Singapore."
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The temperature unit to use."
},
"include_forecast": {
"type": "boolean",
"description": "Whether to include a short-term weather forecast."
}
},
"required": ["city"]
}
}
]

Tool Choice Configuration

Tool Choice Configuration

FieldTypeRequiredDescription
typestringYesHow the model should use the provided tools. The model can use a specific tool, any available tool, decide by itself, or not use tools at all. (auto, any, tool, none)
namestringYesonly used when type is tool

Example Request

{
"model": "minimax/minimax-m2.5",
"messages": [
{
"role": "user",
"content": "What is the weather in Singapore today?"
}
],
"system": "You are a helpful assistant that can use tools when needed."
"tools": [
{
"name": "get_weather",
"description": "Get the current weather information for a given city.",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "The name of the city, e.g. Singapore."
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["city"]
}
}
],
"tool_choice": {
"type": "auto"
}
}

Response

Success Response

FieldTypeDescription
input_tokensintNumber of input tokens actually processed by the model.