Messages
Messages

Count tokens in a Message

Count tokens in a Message

post/v1/messages/count_tokens

Request body

modelstring required

Model identifier or alias.

Example request

{
  "messages": [
    {
      "content": "Count tokens for this input.",
      "role": "user"
    }
  ],
  "model": "default",
  "system": [
    {
      "text": "You are a tokenizer."
    }
  ],
  "thinking": {
    "enabled": false
  },
  "tool_choice": {
    "disable_parallel_tool_use": false,
    "type": "auto",
    "validation_mode": "lazy"
  },
  "tools": [
    {
      "description": "Get current weather for a city.",
      "inputSchema": {
        "properties": {
          "city": {
            "description": "City name.",
            "type": "string"
          }
        },
        "required": [
          "city"
        ],
        "type": "object"
      },
      "name": "get_weather"
    }
  ]
}

Response

Successful Response

input_tokensinteger required

Estimated number of input tokens for the provided payload.

Changes

Changed in 3 of the 11 revisions of this API.446

  • 594fa71dfb90436See the full diff
    • removed from the ////// request property oneOf list

      request-property-one-of-removed

    • removed from the ///////// request property oneOf list

      request-property-one-of-removed

    • removed from the ////////// request property oneOf list

      request-property-one-of-removed

    • removed from the ///////////// request property oneOf list

      request-property-one-of-removed

    • added the new optional request property ///

      new-optional-request-property

    • added the new optional request property ///

      new-optional-request-property

    • added to the /////// request property anyOf list

      request-property-any-of-added

    • added to the /////////// request property anyOf list

      request-property-any-of-added

    • the request property //////// became optional

      request-property-became-optional

    • the request property //////// became optional

      request-property-became-optional

    • the request property /////////// became optional

      request-property-became-optional

    • the request property /////////// became optional

      request-property-became-optional

    • the request property //////////// became optional

      request-property-became-optional

    • the request property //////////// became optional

      request-property-became-optional

    • the request property /////////////// became optional

      request-property-became-optional

    • the request property /////////////// became optional

      request-property-became-optional

    • the request property default value content was added

      request-property-default-value-added

    • the request property default value content was added

      request-property-default-value-added

    • the request property default value content was added

      request-property-default-value-added

    • the request property default value content was added

      request-property-default-value-added

    • the request property default value text was added

      request-property-default-value-added

    • the request property default value text was added

      request-property-default-value-added

    • the request property default value text was added

      request-property-default-value-added

    • the request property default value text was added

      request-property-default-value-added

    • added local_resource discriminator mapping keys to the //// request property

      request-property-discriminator-mapping-added

    • added local_resource discriminator mapping keys to the //////// request property

      request-property-discriminator-mapping-added

    • mapped value for discriminator key base64 changed from to for ////// request property

      request-property-discriminator-mapping-changed

    • mapped value for discriminator key base64 changed from to for ///////// request property

      request-property-discriminator-mapping-changed

    • mapped value for discriminator key base64 changed from to for ////////// request property

      request-property-discriminator-mapping-changed

    • mapped value for discriminator key base64 changed from to for ///////////// request property

      request-property-discriminator-mapping-changed

    • mapped value for discriminator key url changed from to for ////// request property

      request-property-discriminator-mapping-changed

    • mapped value for discriminator key url changed from to for ///////// request property

      request-property-discriminator-mapping-changed

    • mapped value for discriminator key url changed from to for ////////// request property

      request-property-discriminator-mapping-changed

    • mapped value for discriminator key url changed from to for ///////////// request property

      request-property-discriminator-mapping-changed

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

      request-property-one-of-added

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

      request-property-one-of-added

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

      request-property-one-of-added

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

      request-property-one-of-added

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

      request-property-one-of-added

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

      request-property-one-of-added

    This revision also has 2 changes that name no endpoint, such as unreferenced schemas being removed. See the revision's changelog

    • added to the /////// request property anyOf list

      request-property-any-of-added

    • added to the /////////// request property anyOf list

      request-property-any-of-added

    • added mid_conv_system discriminator mapping keys to the //// request property

      request-property-discriminator-mapping-added

    • added mid_conv_system discriminator mapping keys to the //////// request property

      request-property-discriminator-mapping-added

    • added the new system enum value to the request property //

      request-property-enum-value-added

    • added the new xhigh enum value to the request property //

      request-property-enum-value-added

    • added the new xhigh enum value to the request property //

      request-property-enum-value-added

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

      request-property-one-of-added

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

      request-property-one-of-added

    • endpoint added

      endpoint-added

    This revision also has 13 changes that name no endpoint, such as unreferenced schemas being removed. See the revision's changelog