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
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Identifier of the model to use for generation. Must match one of the models served by the backend. |
messages | array | Yes | An array of message objects that make up the conversation history. Each message object should have a role (e.g., "user", "assistant") and content. |
system | string, object | No | Optional system-level instruction that guides the model’s behavior. Can be provided as a plain string or structured object. |
tool_choice | object | No | Specifies how the model should select tools. Can enforce a specific tool call or allow the model to decide automatically. |
tools | object | No | Definition of available tools/functions that the model may call. Typically includes name, description, and JSON schema for parameters. |
Message Configuration
| Field | Type | Required | Description |
|---|---|---|---|
role | string | Yes | The role of the message sender (e.g., "user", "assistant") |
content | string | Yes | The content of the message |
Tool
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | name of the tool |
description | string | No | description of the tool (strongly recommended) |
input_schema | dict | Yes | JSON 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
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | How 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) |
name | string | Yes | only 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
| Field | Type | Description |
|---|---|---|
input_tokens | int | Number of input tokens actually processed by the model. |