Inference

Count tokens for a Messages API request

Returns the input token count a /v1/messages request would consume, without generating a completion. Accepts the same body as /v1/messages; max_tokens is accepted and ignored (it is an output-side cap and cannot change the input count).

post/v1/messages/count_tokens

Request

  • Base URL: https://api.consus.io
  • URL: https://api.consus.io/v1/messages/count_tokens
  • Auth: API key in header x-api-key

Request body

modelstring required

A Claude model with a compliance level, e.g. claude-sonnet-4-5:itar. Bare model names return 400.

messagesobject[] required
max_tokensinteger required
systemstring
streamboolean
toolsobject[]
tool_choiceobject
thinkingobject

Response

Token count for the given request.

input_tokensinteger

Example response

{
  "input_tokens": 42
}

Changes

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