Skip to main content
POST
Count tokens for an Anthropic message

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

Same shape as a create-message request; max_tokens is optional and ignored for counting.

model
string
required
messages
object[]
required
Minimum array length: 1
max_tokens
integer

Optional here; validated if present, not used for counting.

Required range: x >= 1
system

System prompt: a string, or an array of text blocks.

temperature
number
Required range: 0 <= x <= 1
top_p
number
Required range: 0 <= x <= 1
output_config
object
routing
object
tools
object[]

Tool definitions the model may call. Responses include tool_use blocks; return outcomes as tool_result content blocks in a follow-up message.

tool_choice
object

Controls tool use: auto, any, tool, or none.

thinking
object

Extended thinking configuration; translated to the model's reasoning.

metadata
object

Optional string metadata. completion_window controls scheduling; completion_webhook/webhook_token configure completion webhooks; supercache_write stores a reusable prompt prefix.

context_management
object

Anthropic server-side context-editing config (Claude Code sends it automatically). Accepted for compatibility but ignored: Sail forwards the full context each turn.

cache_control
object

Prompt-cache breakpoint (e.g. { "type": "ephemeral" }). Accepted for Anthropic SDK compatibility and has no effect: Sail caches repeated prompt prefixes automatically, without breakpoints. Cache reads are reported in usage.cache_read_input_tokens.

Response

Input token count.

input_tokens
integer
required