count_tokens
Estimate token count for any text or message list to decide whether to compress, prune, or skip content before sending to an API.
Instructions
Estimate token count for text or a message list before sending to an API. Use this to decide whether to compress, prune, or skip content.
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": {
"content": "<content>"
},
"name": "count_tokens"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Plain string OR list of {"role": "...", "content": "..."} dicts. | |
| model | No | Model name — used to pick the right tokenizer encoding. | gpt-4o |
| include_message_overhead | No | Add per-message role/separator overhead (4 tokens each). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||