count_tokens
Calculates token usage for supplied text with a chosen Gemini model, helping you estimate prompt size and manage model input limits.
Instructions
Count tokens for a given text with a specific 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": {
"text": "<text>"
},
"name": "count_tokens"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text to count tokens for | |
| model | No | Model to use for token counting | gemini-2.5-flash |