Available in Classic and VPC
This section describes Chat Completions v3 with support for structured outputs, which allows you to generate output results in the desired JSON schema format.
Request
This section describes the request format. The method and URI are as follows:
Method | URI |
---|---|
POST | /v3/chat-completions/{modelName} |
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
|
Structured outputs are only available on the HCX-007 model.
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 tokens
|
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 | Character to abort token generation
|
seed |
Integer | Optional | Adjust consistency level of output on model iterations.
|
thinking |
Object | Optional | Inference model configuration information |
thinking.effort |
String | Optional | Set whether to infer and the depth of the thought process
|
responseFormat |
Object | Optional | Response format the model outputs |
responseFormat.type |
String | Required | Response format type
|
responseFormat.schema |
Object | Required | Response format schema
|
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
|
Supported JSON schema
The following describes the supported JSON schemas.
- Type
string
,number
,boolean
,integer
,object
,array
- Validation keyword
- String (
string
)format
: Must be one of the defined formats.- Example:
"date-time": "2025-06-30T14:00:00Z", "date": "2025-06-30", "time": "14:30:00", "duration": "P3Y6M4DT12H30M5S", "email": "user@example.com", "hostname": "example.com", "ipv4": "192.***.***.***", "ipv6": "2001:****::1", "uuid": "123e4567-e89b-12d3-a456-426614174000"
- Number (
number
,integer
)minimum
: minimum value (equal to or greater)maximum
: maximum value (equal to or less)
- Array (
array
)minItems
: minimum number of itemsmaxItems
: maximum number of itemsitems
: array item schema definition
- Object (
object
)properties
: field schema definitionrequired
: required field list
- Enum and compound schemas
enum
: Must be one of the predefined list of values.anyOf
: Must satisfy at least one of the listed schemas.
- String (
When entering some fields, check the following:
role
: You can only include one Conversation message that issystem
per request.- Structured outputs can't be requested at the same time as inference or function calling.
- Structured Outputs only support some of the JSON schemas.
pattern
(validation keyword) is not supported.
Request example
The request example is as follows:
curl --location --request POST 'https://clovastudio.stream.ntruss.com/v3/chat-completions/HCX-007' \
--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": "- This is a friendly AI assistant."
},
{
"role": "user",
"content": "text": "Today's high is 32 degrees, the low is 15 degrees, and there is a 30% chance of precipitation."
}
],
"topP": 0.8,
"topK": 0,
"maxTokens": 100,
"temperature": 0.5,
"repetitionPenalty": 1.1,
"stop": [],
"responseFormat": {
"type" : "json",
"schema": {
"type": "object",
"properties": {
"temp_high_c": {
"type": "number",
"description": "Highest temperature (Celsius)"
},
"temp_low_c": {
"type": "number",
"description": "Lowest temperature (Celsius)"
},
"precipitation_percent": {
"type": "number",
"description": "Precipitation probability (%)",
"minimum": 0,
"maximum": 100
}
},
"required": [
"temp_high_c",
"temp_low_c",
"precipitation_percent"
]
}
}
}'
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": "{\n \"temp_high_c\": 32,\n \"temp_low_c\": 15,\n \"precipitation_percent\": 30\n}"
},
"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": “{\n”},"finishReason": null, "created": 1744710905, "seed": 3284419119, "usage": null}
id: aabdfe-dfgwr-edf-hpqwd-f2asd-g
event: token
data: {"message": {"role": "assistant", "content": “ ”},"finishReason": null, "created": 1744710905, "seed": 3284419119, "usage": null}
...
id: aabdfe-dfgwr-edf-hpqwd-f1asd-g
event: result
data: {"message": {"role": "assistant", "content": “{\n \"temp_high_c\": 32,\n \"temp_low_c\": 15,\n \"precipitation_percent\": 30\n}”}, "finishReason": "stop", "created": 1744710905, "seed": 3284419119, "usage": {"promptTokens": 20, "completionTokens": 5, "totalTokens": 25}}
Failure
The following is a sample response upon a failed call.