Token calculator (chat)
    • PDF

    Token calculator (chat)

    • PDF

    Article summary

    The latest service changes have not yet been reflected in this content. We will update the content as soon as possible. Please refer to the Korean version for information on the latest updates.

    Available in Classic and VPC

    Calculate the number of tokens in a sentence entered in the HCX 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.

    HeadersRequiredDescription
    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.> HCX-003

    Request body

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

    FieldTypeRequiredDescription
    messagesArrayRequiredList of conversation messages to count tokens for
    messages.roleEnumRequiredRole of conversation messages
    • system | user | assistant
      • system: directives that define roles
      • user: user utterances/questions
      • assistant: answers of the model
    messages.contentStringRequiredContent of conversation messages

    Request example

    The request example is as follows:

    curl --location --request POST 'https://clovastudio.stream.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 '{
            "messages": [
            {
                "role": "system",
                "content": "- HyperCLOVA X is NAVER's hyperscale AI."
            },
            {
                "role": "user",
                "content": "Hello, what is your name?"
            },
            {
                "role": "assistant",
                "content": "I'm HyperCLOVA X."
            }
        ]
    }'
    

    Response

    This section describes the response format.

    Response body

    The response body includes the following data:

    FieldTypeRequiredDescription
    messagesArray-List of request conversation messages with counted tokens
    messages.roleEnum-Role of conversation messages
    • system | user | assistant
      • system: directives that define roles
      • user: user utterances/questions
      • assistant: answers of the model
    messages.contentString-Content of conversation messages
    messages.countInteger-Result of calculating the number of tokens in the conversation message

    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": {
          "messages": [
            {
              "role": "system",
              "content": "- HyperCLOVA X is NAVER's hyperscale AI.",
              "count": 15
            },
            {
              "role": "user",
              "content": "Hello, what is your name?",
              "count": 10
            },
            {
              "role": "assistant",
              "content": "I'm HyperCLOVA X.",
              "count": 9
            }
          ]
        }
      }
    

    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.