messages_count_tokens
Count tokens (Anthropic-compatible) — Anthropic Messages API compatible token counter: POST the same body you would send to /v1/messages (model, messages, optional system and tools) and get {input_tokens} back before you send it. Handles text, image, document, tool_use and tool_result blocks plus tool-definition overhead, with a per-part breakdown. Heuristic estimate (typically within about 15% for English), no model call, instant. Use it to budget context windows and cost before calling /v1/messages. Price: $0.001 USDC (Base, via x402).
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": {
"model": "<model>",
"messages": "<messages>"
},
"name": "messages_count_tokens"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| model | Yes | claude-sonnet-4-5 | |
| messages | Yes |