Claude Token Counting
POST /v1/messages request. It is useful for Claude CLI, Claude Code, budget checks, and context-trimming logic.
Authentication
The recommended headers follow Anthropic-style requests:Request Body
The body follows the Claude Messages shape. The smallest practical request usually includes:modelmessages
system, tools, tool results, or text content, those are included in the estimate too.
Request Example
Response Example
Response Fields
| Field | Type | Description |
|---|---|---|
input_tokens | integer | Estimated input tokens for the text portion of the request |
warning | string | Optional warning; may appear when images or files were not included in the estimate |
Current Limits
The current implementation mainly estimates:system- text content in
messages - text and JSON content in tool definitions and tool results
This endpoint returns an estimate, not a final billing record. Actual usage is determined by the real model call.