Token calculator (HCX)
- Print
- PDF
Token calculator (HCX)
- Print
- PDF
Article summary
Did you find this summary helpful?
Thank you for your feedback
Available in Classic and VPC
Calculate the number of tokens in a sentence entered in the HCX model.
Request
The following describes the request format for the endpoint. The request format is as follows:
Method | URI |
---|---|
POST | /v1/api-tools/chat-tokenize/{modelName} |
Request headers
The following describes the request headers.
Headers | Required | Description |
---|---|---|
X-NCP-CLOVASTUDIO-API-KEY | Required | API key issued when creating the test app or service app |
X-NCP-APIGW-API-KEY | Required | API Gateway key issued when creating the test app or service app |
X-NCP-CLOVASTUDIO-REQUEST-ID | Optional | Request ID |
Content-Type | Required | Request data format
|
Request path parameters
The following describes the request path parameters.
Field | Type | Required | Description |
---|---|---|---|
modelName | String | Required | Model name
|
Request body
The following describes the request body.
Field | Type | Required | Description |
---|---|---|---|
messages | Array | Required | List of conversation messages to count tokens for |
messages.role | Enum | Required | Role of conversation messages
|
messages.content | String | Required | Content of conversation messages |
Request example
The following is a sample request.
curl --location --request POST 'https://clovastudio.apigw.ntruss.com/v1/api-tools/chat-tokenize/{modelName}' \
--header 'X-NCP-CLOVASTUDIO-API-KEY: {CLOVA Studio API Key}' \
--header 'X-NCP-APIGW-API-KEY: {API Gateway 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
The following describes the response format.
Response body
The following describes the response body.
Field | Type | Required | Description |
---|---|---|---|
messages | Array | - | List of request conversation messages with counted tokens |
messages.role | Enum | - | Role of conversation messages
|
messages.content | String | - | Content of conversation messages |
messages.count | Integer | - | Result of calculating the number of tokens in the conversation message |
Response example
The following is a sample example.
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?