count_tokens
Counts tokens in text using model-specific tokenizers. Specify a model name to route between Anthropic/Claude and OpenAI/tiktoken for accurate token counts.
Instructions
Count tokens in text.
Routes by model name to Anthropic/Claude (default) or OpenAI/tiktoken.
Args:
text: The text to tokenize.
model: Model or encoding name (e.g. claude-opus-4-8, gpt-4, o200k_base).
Empty uses ANTHROPIC_TOKEN_COUNT_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 | ||
| model | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |