メインコンテンツへスキップ
更新日: 2026-06-06

Claude Token Counting

Use this endpoint to estimate input token usage before you send the real 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:
Standard Bearer authentication also works, but Anthropic ecosystem clients usually send the headers above.

Request Body

The body follows the Claude Messages shape. The smallest practical request usually includes:
  • model
  • messages
If your request also includes system, tools, tool results, or text content, those are included in the estimate too.

Request Example

Response Example

Response Fields

Current Limits

The current implementation mainly estimates:
  • system
  • text content in messages
  • text and JSON content in tool definitions and tool results
If the request contains images or files, those image/file tokens are not included in input_tokens. In that case the response may include a warning, and real billing can be higher than this estimate.
This endpoint returns an estimate, not a final billing record. Actual usage is determined by the real model call.