MENU
      Token calculator

        Token calculator


        Article summary

        Available in Classic and VPC

        Calculate the number of tokens in a sentence entered in a model other than the HyperCLOVA model.

        Request

        This section describes the request format. The method and URI are as follows:

        MethodURI
        POST/v1/api-tools/chat-tokenize/{modelName}

        Request headers

        The following describes the request headers.

        FieldRequiredDescription
        AuthorizationRequiredAPI key for authentication <e.g.,> Bearer nv-************
        X-NCP-CLOVASTUDIO-REQUEST-IDOptionalRequest ID
        Content-TypeRequiredRequest data format
        • application/json

        Request path parameters

        You can use the following path parameters with your request:

        FieldTypeRequiredDescription
        modelNameStringRequiredModel name
        • <e.g.> LK-D2

        Request body

        You can include the following data in the body of your request:

        FieldTypeRequiredDescription
        textStringRequiredList of conversation messages to count tokens for

        Request example

        The request example is as follows:

        curl --location --request POST 'https://clovastudio.apigw.ntruss.com/v1/api-tools/chat-tokenize/{modelName}' \
        --header 'Authorization: Bearer {API Key}' \
        --header 'X-NCP-CLOVASTUDIO-REQUEST-ID: {Request ID}' \
        --header 'Content-Type: application/json' \
        --data '{
            "text" : "Tell me the total number of tokens."
        }'
        Plain text

        Response

        This section describes the response format.

        Response body

        The response body includes the following data:

        FieldTypeRequiredDescription
        numTokensInteger-Result of calculating the number of tokens

        Response example

        The response example is as follows:

        Succeeded

        The following is a sample response upon a successful call.

        {
            "status": {
              "code": "20000",
              "message": "OK"
            },
            "result": {
              "numTokens": 1000
            }
          }
        Plain text

        Failure

        The following is a sample response upon a failed call.


        Was this article helpful?

        Changing your password will log you out immediately. Use the new password to log back in.
        First name must have atleast 2 characters. Numbers and special characters are not allowed.
        Last name must have atleast 1 characters. Numbers and special characters are not allowed.
        Enter a valid email
        Enter a valid password
        Your profile has been successfully updated.