Messages

Count message input tokens (Anthropic-compatible)

Estimates input tokens for an Anthropic-compatible Messages request without running or billing the model. max_tokens is optional. The per-key rate limit applies. anthropic-beta and Claude Code compatibility headers are accepted and ignored.

post/messages/count_tokens

Headers

anthropic-versionstring
Example:2023-06-01

Accepted and echoed back on the response.

anthropic-betastring

Accepted and ignored for client compatibility.

Request body

modelstring required

Model id returned by GET /v1/models.

max_tokensinteger

Required by POST /messages and optional for POST /messages/count_tokens. Reasoning spends this budget. 0 is refused.

temperaturenumber

Passed through.

top_pnumber

Passed through.

{"stackTrail":"components:schemas:AnthropicMessageRequest:properties:top_k","oasType":"schema","type":"unknown","description":"Accepted and ignored."}
stop_sequencesstring[]

Passed through as stop strings. The matched sequence is not reported.

streamboolean

true returns text/event-stream in the Anthropic event grammar.

{"stackTrail":"components:schemas:AnthropicMessageRequest:properties:cache_control","oasType":"schema","type":"unknown","description":"Accepted and ignored."}
{"stackTrail":"components:schemas:AnthropicMessageRequest:properties:service_tier","oasType":"schema","type":"unknown","description":"Accepted and ignored."}
{"stackTrail":"components:schemas:AnthropicMessageRequest:properties:container","oasType":"schema","type":"unknown","description":"Accepted and ignored."}
{"stackTrail":"components:schemas:AnthropicMessageRequest:properties:mcp_servers","oasType":"schema","type":"unknown","description":"Accepted and ignored."}
{"stackTrail":"components:schemas:AnthropicMessageRequest:properties:context_management","oasType":"schema","type":"unknown","description":"Accepted and ignored."}
{"stackTrail":"components:schemas:AnthropicMessageRequest:properties:inference_geo","oasType":"schema","type":"unknown","description":"Accepted and ignored."}
{"stackTrail":"components:schemas:AnthropicMessageRequest:properties:speed","oasType":"schema","type":"unknown","description":"Accepted and ignored."}

Example request

{
  "model": "deepseek-v4-flash"
}

Response

Estimated input token count

input_tokensinteger required

Estimated input tokens. The operation does not run or bill the model.

Changes

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