- Print
- PDF
Chat Completions
- Print
- PDF
Available in Classic and VPC
Generates conversational sentences using HyperCLOVA X model.
Requests
Describes the request format. The request format is as follows:
Method | URI |
---|---|
POST | /v1/chat-completions/{modelName} |
Header
The following describes the header.
Header | Required | Description |
---|---|---|
X-NCP-CLOVASTUDIO-API-KEY | Y | API key issued when creating a test app or service app |
X-NCP-APIGW-API-KEY | Y | API Gateway key issued when creating a test app or service app |
X-NCP-CLOVASTUDIO-REQUEST-ID | N | Request ID for each request |
Content-Type | Y | application/json |
Accept | N | text/event-stream |
- The response result is returned in JSON format by default, but when
Accept
is specified astext/event-stream
, the response result is returned in a stream format. - When using the response stream, please use
https://clovastudio.stream.ntruss.com/
as the API URL.
Path parameters
The following describes the parameters.
Field | Type | Required | Description |
---|---|---|---|
modelName | string | Y | Model name: HCX-002 |
Body
The following describes the body.
Field | Type | Required | Description |
---|---|---|---|
messages | array | Y | Conversation messages |
messages.role | enum | Y | Role of the conversational message |
messages.content | string | Y | Content of the conversation message |
temperature | double | N | Degree of diversity for generated tokens (a higher setting generates more diverse sentences) |
topK | int | N | Selects and samples the top k token candidates with the highest probabilities from the generated token pool |
topP | double | N | Samples based on the cumulative probabilities of the generated token candidates |
repeatPenalty | double | N | The degree of penalty applied when generating the same token (a higher setting reduces the likelihood of repeatedly generating the same result) |
stopBefore | string | N | Character that halts token generation |
maxTokens | int | N | Maximum number of tokens generated |
seed | int | N | When running the model repeatedly, adjust the level of consistency in the results |
When filling out some fields, please check the following:
Syntax
The following is an example of syntax.
curl --location --request POST 'https://clovastudio.stream.ntruss.com/testapp/v1/chat-completions/HCX-002' \
--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' \
--header 'Accept: text/event-stream' \
--data '{
"topK" : 0,
"includeAiFilters" : true,
"maxTokens" : 256,
"temperature" : 0.5,
"messages" : [ {
"role" : "system",
"content" : "test"
}, {
"role" : "user",
"content": "Let's do a test."
}, {
"role" : "assistant",
"content": "Understood. What would you like to test?"
} ],
"stopBefore" : [ ],
"repeatPenalty" : 5.0,
"topP" : 0.8
}'
Responses
Describes the responses format.
Header
The following describes the header.
Header | Required | Description |
---|---|---|
Content-Type | - | application/json |
Body
The following describes the body.
Field | Type | Required | Description |
---|---|---|---|
result | - | - | Response result |
result.message | array | Y | Conversation messages |
result.message.role | enum | Y | Role of the conversational message |
result.message.content | string | Y | Content of the conversation message |
result.stopReason | enum | - | Token generation termination reasons (typically passed in the last event) |
result.inputLength | int | - | Number of input tokens (inclusive of special tokens like end of turn for billing purposes) |
result.outputLength | int | - | Number of response tokens |
result.seed | int | - | Input seed value (When 0 is entered or left blank, a random value will be returned) |
aiFilter | array | - | AI Filter result |
aiFilter.groupName | string | Y | AI Filter category group name |
aiFilter.name | string | Y | Detailed AI Filter category name |
aiFilter.score | string | Y | AI Filter score |
The AI Filter can analyze up to 500 characters. However, if the text for analysis contains many unconventional formats, emojis, special characters, and so on, it might not be analyzed accurately.
Syntax
The following is an example of syntax.
{
"status": {
"code": "20000",
"message": "OK"
},
"result": {
"message": {
"role": "assistant",
"content": "phrase: reflect on your day, jotting down the events that transpired, and prepare for tomorrow. A diary will enrich your life further.\n"
},
"stopReason": "LENGTH",
"inputLength": 100,
"outputLength": 10,
"aiFilter": [
{
"groupName": "curse",
"name": "insult",
"score": "1"
},
{
"groupName": "curse",
"name": "discrimination",
"score": "0"
},
{
"groupName": "unsafeContents",
"name": "sexualHarassment",
"score": "2"
}
]
}
}
Response stream
You can use token streaming to display the generated tokens one by one. It describes the token streaming format.
Header
The following describes the header.
Header | Required | Description |
---|---|---|
Accept | - | text/event-stream |
Body
The following describes the body.
StreamingChatCompletionsResultEvent
The following describes StreamingChatCompletionsResultEvent.
Field | Type | Required | Description |
---|---|---|---|
message | array | - | Conversation messages |
message.role | enum | - | Role of the conversational message |
message.content | string | - | Content of the conversation message |
stopReason | enum | - | Token generation termination reasons (typically passed in the last event) |
inputLength | int | - | Number of input tokens (inclusive of special tokens like end of turn for billing purposes) |
outputLength | int | - | Number of response tokens |
aiFilter | array | - | AI Filter result |
aiFilter.groupName | string | Y | AI Filter category group name |
aiFilter.name | string | Y | AI Filter category detailed name |
aiFilter.score | string | Y | AI Filter score |
StreamingChatCompletionsTokenEvent
The following describes StreamingChatCompletionsResultEvent.
Field | Type | Required | Description |
---|---|---|---|
id | string | - | Event ID that identifies the request |
message | array | - | Conversation messages |
message.role | enum | - | Role of the conversational message |
message.content | string | - | Content of the conversation message |
inputLength | int | - | Number of input tokens (inclusive of special tokens like end of turn for billing purposes) |
stopReason | enum | - | Token generation termination reasons (typically passed in the last event) |
ErrorEvent
The following describes ErrorEvent.
Field | Type | Required | Description |
---|---|---|---|
status | status | - | Response status |
SignalEvent
The following describes SignalEvent.
Field | Type | Required | Description |
---|---|---|---|
data | string | - | Signal data information to be transmitted |
Syntax
The following is an example of syntax.
id: aabdfe-dfgwr-edf-hpqwd-f2asd-g
event: token
data: {"message": {"role": "assistant", "content": "An"}}
id: aabdfe-dfgwr-edf-hpqwd-f1asd-g
event: result
data: {"message": {"role": "assistant", "content": "nyeong"}}