Anthropic

Count message tokens (Anthropic-compatible)

Counts input tokens for an Anthropic-compatible messages request without creating a model response. Authentication is required; the operation is not billed. Verified upstream counting is preferred. Upstream availability failures return a local estimate marked by X-TokenLab-Count-Tokens-Source: local_estimate. Platform authentication, permission and input errors remain errors. Bound files unreadable locally require upstream counting.

post/v1/messages/count_tokens

Request

  • Base URL: https://api.tokenlab.sh
  • URL: https://api.tokenlab.sh/v1/messages/count_tokens
  • Auth: HTTP bearer

Request body

modelstring required

Model to count tokens for

cache_controlobject

Top-level Anthropic cache control marker for count_tokens requests.

output_configobject

Anthropic output configuration fields that may affect token counting.

thinkingobject

Anthropic extended thinking configuration for token counting.

toolsobject[]

Tool definitions available to the model.

Example request

{
  "model": "claude-sonnet-4-6"
}

Response

Token count response

input_tokensinteger required

Number of input tokens in the supplied Anthropic messages request

Example response

{
  "input_tokens": 1234
}

Changes

No recorded changes to this operation across all 1 revision of this API.