v1

latestOpenAPI 3.1.02026-07-26105141.0 KB
Messages API

Count tokens for an Anthropic message

Counts the input tokens a create-message request would consume, without running the model.

post/messages/count_tokens

Request body

modelstring required
max_tokensinteger

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

temperaturenumber
top_pnumber
toolsobject[]

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

tool_choiceobject

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

thinkingobject

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

context_managementobject

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

Response

Input token count.

input_tokensinteger required