Available in Classic and VPC
This guide describes Chat Completions v3, which can use the HCX-005 vision model that can interpret and understand images, and the lightweight HCX-DASH-002 model.
Request
This section describes the request format. The method and URI are as follows:
Method | URI |
---|---|
POST |
|
Request headers
The following describes the request headers.
Headers | Required | Description |
---|---|---|
Authorization |
Required | API key for authentication Example: Bearer nv-************ |
X-NCP-CLOVASTUDIO-REQUEST-ID |
Optional | Request ID for the request |
Content-Type |
Required | Request data format
|
Accept |
Conditional | Response data format
|
Response results are returned in JSON by default, but if you specify Accept
as text/event-stream
, then the response results are returned as a stream.
Request path parameters
You can use the following path parameters with your request:
Field | Type | Required | Description |
---|---|---|---|
modelName |
Enum | Required | Model name
|
- HCX-005 and HCX-DASH-002 are only available in the Chat Completions v3 API.
- Image input is only available in HCX-005, the HyperCLOVA X vision model, and tuning training is not supported.
Request body
You can include the following data in the body of your request:
Field | Type | Required | Description |
---|---|---|---|
messages |
Array | Required | Conversation messages |
topP |
Double | Optional | Sample generated token candidates based on cumulative probability.
|
topK |
Integer | Optional | Sample K high-probability candidates from the pool of generated token candidates
|
maxTokens |
Integer | Optional | Maximum number of generated tokensmaxTokens ≤ model maximum valuemaxCompletionTokens . |
maxCompletionTokens |
Integer | Optional | Maximum number of generated tokens (inference model)
|
temperature |
Double | Optional | Degree of diversity for the generated tokens (higher values generate more diverse sentences)
|
repetitionPenalty |
Double | Optional | Degree of penalty for generating the same token (the higher the setting, the less likely it is to generate the same result repeatedly)
|
stop |
Array | Optional | Token generation stop character
|
seed |
Integer | Optional | Adjust consistency level of output on model iterations.
|
includeAiFilters |
Boolean | Optional | Whether to display the AI filter results (degree of the generated results in categories such as profanity, degradation/discrimination/hate, sexual harassment/obscenity, etc.)
|
messages
The following describes messages
.
Field | Type | Required | Description |
---|---|---|---|
role |
Enum | Required | Role of conversation messages
|
content |
String | Array | Required | Conversation message content
|
content
The following describes content
.
Field | Type | Required | Description |
---|---|---|---|
type |
Enum | Required | Format of conversation message content
|
text |
String | Conditional | Conversation message content
|
imageUrl |
Object | Conditional | Image list
|
imageUrl.url |
String | Conditional | Public URL of a single image, including file extension
|
dataUri |
Object | Conditional | Image list
|
dataUri.data |
String | Conditional | Base64-encoded image string
|
When entering some fields, check the following:
role
: You can only include one Conversation message that issystem
per request.- HCX-005
- The sum of the input tokens and the output tokens cannot exceed 128,000 tokens.
- The input tokens can be up to 128,000 tokens.
- The output tokens (maxTokens) to be requested from the model can be up to 4096 tokens.
messages
: One image can be included per turn, and up to five images can be included per request.- The total request body size must be 50 MB or less. Therefore, if you want to include multiple images in a request, we recommend using image URLs rather than Base64 format.
- HCX-DASH-002
- The sum of the input tokens and the output tokens cannot exceed 32000 tokens.
- The input tokens can be up to 32000 tokens.
- The output tokens (maxTokens) to be requested from the model can be up to 4096 tokens.
Request example
The request example is as follows:
curl --location --request POST 'https://clovastudio.stream.ntruss.com/v3/chat-completions/HCX-005' \
--header 'Authorization: Bearer {CLOVA Studio API Key}' \
--header 'X-NCP-CLOVASTUDIO-REQUEST-ID: {Request ID}' \
--header 'Content-Type: application/json' \
--header 'Accept: text/event-stream' \
--data '{
"messages": [
{
"role": "system",
"content": [
{
"type": "text",
"text": "- This is a friendly AI assistant."
}
]
},
{
"role": "user",
"content": [
{
"type": "image_url",
"imageUrl": {
"url": "https://www.******.com/image_a1b1c1.png"
}
},
{
"type": "text",
"text": "Please describe this photo."
}
]
}
],
"topP": 0.8,
"topK": 0,
"maxTokens": 100,
"temperature": 0.5,
"repetitionPenalty": 1.1,
"stop": []
}'
Response
This section describes the response format.
Response headers
The following describes the response headers.
Headers | Required | Description |
---|---|---|
Content-Type |
- | Response data format
|
Response body
The response body includes the following data:
Field | Type | Required | Description |
---|---|---|---|
status |
Object | - | Response status |
result |
Object | - | Response result |
result.created |
Integer | - | Response date and time
|
result.usage |
Object | - | Token usage |
result.usage.completionTokens |
Integer | - | Generated token count |
result.usage.promptTokens |
Integer | - | Number of input (prompt) tokens |
result.usage.totalTokens |
Integer | - | Total number of tokens
|
result.message |
Object | - | Conversation messages |
result.message.role |
Enum | - | Role of conversation messages
|
result.message.content |
String | - | Content of conversation messages |
result.finishReason |
String | - | Reason for stopping token generation (generally passed to the last event)
|
result.seed |
Integer | - | Input seed value (Return a random value when 0 is entered or not entered) |
result.aiFilter |
Array | - | AI Filter result |
aiFilter
The following describes aiFilter
.
Field | Type | Required | Description |
---|---|---|---|
groupName |
String | - | AI Filter category
|
name |
String | - | AI Filter subcategory
|
score |
String | - | AI Filter score
|
result |
String | - | Whether AI Filter is operating properly
|
AI Filter can analyze up to 500 characters. However, if the text being analyzed contains many unusual formats, emojis, or special characters, it may not be analyzed correctly.
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": {
"created": 1791043155000,
"usage": {
"completionTokens": 80,
"promptTokens": 843,
"totalTokens": 923
},
"message": {
"role": "assistant",
"content": "The photo shows a young child feeding a sheep. The child is wearing a blue outfit and a striped hat. The child appears to be concentrating, while the sheep is lowering its head to eat the food the child is offering. Other sheep can be seen in the background, suggesting that the location is a sheep farm."
},
"seed": 1561390649,
"aiFilter": [
{
"groupName": "curse",
"name": "insult",
"score": "1"
},
{
"groupName": "curse",
"name": "discrimination",
"score": "0"
},
{
"groupName": "unsafeContents",
"name": "sexualHarassment",
"score": "2"
}
]
}
}
Failure
The following is a sample response upon a failed call.
Response stream
You can use token streaming to output the tokens as they are generated, one by one. The following describes the token streaming format.
Response headers
The following describes the response headers.
Headers | Required | Description |
---|---|---|
Accept |
- | Response data format
|
Response body
The response body includes the following data:
StreamingChatCompletionsTokenEvent
The following describes StreamingChatCompletionsTokenEvent
.
Field | Type | Required | Description |
---|---|---|---|
created |
Integer | - | Response timestamp |
usage |
Object | - | Token usage |
usage.promptTokens |
Integer | - | Number of input (prompt) tokens |
usage.completionTokens |
Integer | - | Generated token count |
message |
Object | - | Conversation messages |
message.role |
Enum | - | Conversation message role
|
message.content |
String | - | Content of conversation messages |
finishReason |
String | - | Reason for stopping token generation (typically passed to the last event)
|
StreamingChatCompletionsResultEvent
The following describes StreamingChatCompletionsResultEvent
.
Field | Type | Required | Description |
---|---|---|---|
created |
Integer | - | Response timestamp |
usage |
Object | - | Token usage |
usage.promptTokens |
Integer | - | Number of input (prompt) tokens |
usage.completionTokens |
Integer | - | Generated token count |
usage.totalTokens |
Integer | - | Total number of tokens
|
message |
Object | - | Conversation messages |
message.role |
Enum | - | Conversation message role
|
message.content |
String | - | Content of conversation messages |
finishReason |
String | - | Reason for stopping token generation (typically passed to the last event)
|
aiFilter |
Array | - | AI Filter result |
ErrorEvent
The following describes ErrorEvent
.
Field | Type | Required | Description |
---|---|---|---|
status |
Object | - | Response status |
status.code |
Object | - | Response status code |
status.message |
Object | - | Response status message |
SignalEvent
The following describes SignalEvent
.
Field | Type | Required | Description |
---|---|---|---|
data |
String | - | Signal data information to pass |
Response example
The response example is as follows:
Succeeded
The following is a sample response upon a successful call.
id: aabdfe-dfgwr-edf-hpqwd-f3asd-g
event: token
data: {"message": {"role": "assistant", "content": “He”},"finishReason": null, "created": 1744710905, "seed": 3284419119, "usage": null}
id: aabdfe-dfgwr-edf-hpqwd-f2asd-g
event: token
data: {"message": {"role": "assistant", "content": “llo”},"finishReason": null, "created": 1744710905, "seed": 3284419119, "usage": null}
id: aabdfe-dfgwr-edf-hpqwd-f1asd-g
event: result
data: {"message": {"role": "assistant", "content": “Hello”}, "finishReason": "stop", "created": 1744710905, "seed": 3284419119, "usage": {"promptTokens": 20, "completionTokens": 5, "totalTokens": 25}}
Failure
The following is a sample response upon a failed call.