Overview
The OpenAI-compatible chat completion interface supports both streaming and non-streaming responses. It is suitable for scenarios where you need to call large language models for dialogue, content generation, and other purposes.
API details
Constraints
- The caller must have an API Key. For more information, see Manage AI API Keys.
Request path
POST {BASE_URL}/api/v1/chat/completions
Request header
Name |
Required |
Example value |
Description |
|---|---|---|---|
| Authorization | Yes | Bearer {token} | Authentication information |
| Content-Type | No | application/json | Request body format |
Request parameters
Path
None
Query
None
Body
Name |
Type |
Required |
Example value |
Description |
|---|---|---|---|---|
| model | string | Yes | gpt-3.5-turbo | Model name |
| messages | array[object] | Yes | [{"role": "user", "content": "Hello!"}] | List of messages |
| stream | boolean | No | false | Whether to enable streaming output |
| max_tokens | integer | No | 2048 | Maximum number of tokens to generate |
| max_completion_tokens | integer | No | 512 | Maximum number of tokens for the completion part |
| temperature | number | No | 1.0 | Sampling temperature, between 0 and 2 |
| top_p | number | No | 1.0 | Core sampling parameter |
| user | string | No | user-123 | Identifier for the end user |
Response
Response parameters
Name |
Type |
Description |
|---|---|---|
| success | boolean | Whether the request was successful |
| code | string | Return code |
| message | string | Return information |
| data | object | Business return data |
data
Name |
Type |
Description |
|---|---|---|
| id | string | Unique ID for the chat completion |
| object | string | Object type, such as "chat.completion" |
| created | integer | Timestamp of creation |
| model | string | Model used |
| choices | array[object] | Generated choices list |
| usage | object | Token usage |
Request example
curl --request POST '{BASE_URL}/api/v1/chat/completions' \
--header 'Authorization: Bearer {token}' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-3.5-turbo",
"messages": [
{"role": "user", "content": "Hello!"}
],
"stream": false,
"max_tokens": 2048,
"temperature": 1.0
}'
Response example
{
"success": true,
"code": "200",
"message": "successful",
"data": {
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "gpt-3.5-turbo",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello there! How can I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}
}
