Token calculator (Embedding v2)

Prev Next

Available in Classic and VPC

Calculate the number of tokens in a sentence entered in Embedding v2.

Request

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

Method URI
POST /v1/api-tools/embedding/v2/tokenize

Request headers

The following describes the headers.

Headers Required Description
Authorization Required API key for authentication <e.g.,> Bearer nv-************
X-NCP-CLOVASTUDIO-REQUEST-ID Optional Request ID
Content-Type Required Request data format
  • application/json

Request body

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

Field Type Required Description
text String Required List of conversation messages to count tokens for
  • 1-10,000 characters (based on Korean)

Request example

The request example is as follows:

curl --location --request POST 'https://clovastudio.stream.ntruss.com/v1/api-tools/embedding/v2/tokenize' \
--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."
}'

Response

This section describes the response format.

Response body

The response body includes the following data:

Field Type Required Description
numTokens Integer - 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
    }
}

Failure

The following is a sample response upon a failed call.