Messages API

Count tokens for an Anthropic message

Changed on

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

post/messages/count_tokens

Request

  • Base URL
    https://api.sailresearch.com/v1
  • URL
    https://api.sailresearch.com/v1/messages/count_tokens
  • Auth
    • HTTP bearer
    • or API key in header x-api-key

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

Changes

    • breaking

      removed the enum value priority of the request property /

    • warning

      removed the optional property / from the response with the status

    • warning

      removed the optional property / from the response with the status

    • warning

      removed the optional property / from the response with the status

    • warning

      removed the optional property / from the response with the status

    • warning

      removed the optional property / from the response with the status

    • warning

      removed the optional property / from the response with the status

    • warning

      removed the optional property / from the response with the status

    • warning

      removed the optional property / from the response with the status

    • warning

      added the new api_error enum value to the / response property for the response status

    • warning

      added the new api_error enum value to the / response property for the response status

    • warning

      added the new api_error enum value to the / response property for the response status

    • warning

      added the new api_error enum value to the / response property for the response status

    • warning

      added the new authentication_error enum value to the / response property for the response status

    • warning

      added the new authentication_error enum value to the / response property for the response status

    • warning

      added the new authentication_error enum value to the / response property for the response status

    • warning

      added the new authentication_error enum value to the / response property for the response status

    • warning

      added the new billing_error enum value to the / response property for the response status

    • warning

      added the new billing_error enum value to the / response property for the response status

    • warning

      added the new billing_error enum value to the / response property for the response status

    • warning

      added the new billing_error enum value to the / response property for the response status

    • warning

      added the new conflict_error enum value to the / response property for the response status

    • warning

      added the new conflict_error enum value to the / response property for the response status

    • warning

      added the new conflict_error enum value to the / response property for the response status

    • warning

      added the new conflict_error enum value to the / response property for the response status

    • warning

      added the new invalid_request_error enum value to the / response property for the response status

    • warning

      added the new invalid_request_error enum value to the / response property for the response status

    • warning

      added the new invalid_request_error enum value to the / response property for the response status

    • warning

      added the new invalid_request_error enum value to the / response property for the response status

    • warning

      added the new not_found_error enum value to the / response property for the response status

    • warning

      added the new not_found_error enum value to the / response property for the response status

    • warning

      added the new not_found_error enum value to the / response property for the response status

    • warning

      added the new not_found_error enum value to the / response property for the response status

    • warning

      added the new overloaded_error enum value to the / response property for the response status

    • warning

      added the new overloaded_error enum value to the / response property for the response status

    • warning

      added the new overloaded_error enum value to the / response property for the response status

    • warning

      added the new overloaded_error enum value to the / response property for the response status

    • warning

      added the new permission_error enum value to the / response property for the response status

    • warning

      added the new permission_error enum value to the / response property for the response status

    • warning

      added the new permission_error enum value to the / response property for the response status

    • warning

      added the new permission_error enum value to the / response property for the response status

    • warning

      added the new rate_limit_error enum value to the / response property for the response status

    • warning

      added the new rate_limit_error enum value to the / response property for the response status

    • warning

      added the new rate_limit_error enum value to the / response property for the response status

    • warning

      added the new rate_limit_error enum value to the / response property for the response status

    • warning

      added the new request_too_large enum value to the / response property for the response status

    • warning

      added the new request_too_large enum value to the / response property for the response status

    • warning

      added the new request_too_large enum value to the / response property for the response status

    • warning

      added the new request_too_large enum value to the / response property for the response status

    • warning

      added the new timeout_error enum value to the / response property for the response status

    • warning

      added the new timeout_error enum value to the / response property for the response status

    • warning

      added the new timeout_error enum value to the / response property for the response status

    • warning

      added the new timeout_error enum value to the / response property for the response status

    • info

      the endpoint scheme security AnthropicApiKey was added to the API

    • info

      the endpoint scheme security BearerAuth was added to the API

    • info

      added the new optional request property

    • info

      added the new optional request property /

    • info

      added the new optional request property

    • info

      added the new balanced enum value to the request property /

    • info

      added to the //// request property oneOf list

    • info

      added to the /////////// request property oneOf list

    • info

      added the non-success response with the status

    • info

      added the required property to the response with the status

    • info

      added the required property to the response with the status

    • info

      added the required property to the response with the status

    • info

      added the required property to the response with the status

    • info

      added the required property to the response with the status

    • info

      added the required property to the response with the status

    • info

      added the required property to the response with the status

    • info

      added the required property to the response with the status