Count tokens
count_tokensCounts the input tokens a generate_text request would use for a prompt, model, optional images, instructions, and web search, without running the model.
Instructions
Count the input tokens a generate_text request would use, without running the model
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"prompt": "<prompt>",
"model": "<model>"
},
"name": "count_tokens"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model | Yes | OpenAI model whose tokenizer to use. Must support image input if images are provided | |
| images | No | Images to include in the count, each as an http(s) URL or a file path on this server's filesystem (PNG, JPEG, WEBP, or GIF) | |
| prompt | Yes | The input text to count | |
| webSearch | No | Count the request as one that has web search enabled | |
| instructions | No | Optional instructions to include in the count |