Skip to main content

Overview

Use POST /api/v1/messages/count_tokens to estimate the number of input tokens for an Anthropic Messages-format request. This endpoint is useful for request planning, context budgeting, and cost control. The result is an estimate and may not exactly match a provider tokenizer.

Endpoint

Authentication

Use either header:
  • Authorization: Bearer YOUR_API_KEY
  • x-api-key: YOUR_API_KEY

Request Body

Supported Content

The request uses Anthropic message format and supports:
  • text blocks
  • image and document-like blocks
  • tool use blocks
  • tool result blocks
  • system
  • tools
  • tool_choice

Response

Example

Notes

  • This is an estimate for planning and cost control.
  • It may not exactly match a provider tokenizer.
  • For generation, use POST /api/v1/messages.