count_tokens
Estimate token counts for text or chat messages to fit into a model's context window. Supports multiple model families with per-message overhead.
Instructions
Estimate tokens in a string or chat-message array. Fast, dependency-free, within ~10-20% of true tokenizer counts on English prose. Pass a model name to pick the right per-family estimator (openai, anthropic, google, llama, default).
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": {
"input": "<input>"
},
"name": "count_tokens"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| input | Yes | String or array of chat messages. | |
| model | No | Optional model name (e.g. "gpt-5", "claude-sonnet-4-6"). Picks the closest estimator family. | |
| overhead | No | Per-message overhead in tokens (default depends on model family, usually 4-6). |