messages

Count message tokens (Anthropic Messages API)

Returns a provider-agnostic heuristic estimate of the input token count.

post/v1/messages/count_tokens

Request body

cache_controlobject
max_tokensinteger
modelstring
stop_sequencesstring[]
streamboolean
temperaturenumber
top_kinteger
top_pnumber

Response

OK

input_tokensinteger

Changes

Changed in 3 of the 53 revisions of this API.5

    • added the optional property error/provider to the response with the 400 status

      response-optional-property-added

    • added the optional property error/provider to the response with the 401 status

      response-optional-property-added

    • added the new optional request property cache_control

      new-optional-request-property

    • added the new optional request property tools/items/cache_control

      new-optional-request-property

    • endpoint added

      endpoint-added