Token calculator
- Print
- PDF
Token calculator
- 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 a model other than 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 headers.
Header | Required | Description |
---|---|---|
X-NCP-CLOVASTUDIO-API-KEY | Y | API key issued when viewing code |
X-NCP-APIGW-API-KEY | Y | API Gateway key issued when viewing code |
X-NCP-CLOVASTUDIO-REQUEST-ID | N | Request ID for each request |
Content-Type | Y | application/json |
Request path parameters
The following describes the parameters.
Field | Type | Required | Description |
---|---|---|---|
modelName | string | Y | Name of the model to use <E.g.> LK-D2 |
Request body
The following describes the body.
Field | Type | Required | Description |
---|---|---|---|
text | array[ChatMessage] | Y | List of request conversation messages to count tokens for |
Request syntax
The following is a sample syntax.
curl --location --request POST 'https://clovastudio.apigw.ntruss.com/v1/api-tools/chat-tokenize/{modelName}' \
--header 'X-NCP-CLOVASTUDIO-API-KEY: <X-NCP-CLOVASTUDIO-API-KEY>' \
--header 'X-NCP-APIGW-API-KEY: <X-NCP-APIGW-API-KEY>' \
--header 'X-NCP-CLOVASTUDIO-REQUEST-ID: <X-NCP-CLOVASTUDIO-REQUEST-ID>' \
--header 'Content-Type: application/json' \
--data '{
"text" : "Tell me the total number of tokens."
}'
Response
The following describes the response format.
Response body
The following describes the body.
Field | Type | Required | Description |
---|---|---|---|
numTokens | int | Y | Total number of tokens used |
Response syntax
The following is a sample syntax.
Success
The following is a sample syntax upon a successful call.
{
"status": {
"code": "20000",
"message": "OK"
},
"result": {
"numTokens": 1000
}
}
Failure
The following is a sample syntax upon a failed call.
Was this article helpful?