Chat Completions
创建一次对话补全请求。
请求地址
http
POST /v1/chat/completions请求头
http
Authorization: Bearer YOUR_NEXUSMODELS_API_KEY
Content-Type: application/json请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型名称 |
messages | array | 是 | 对话消息列表 |
temperature | number | 否 | 控制输出随机性 |
max_tokens | integer | 否 | 最大输出 Token 数 |
stream | boolean | 否 | 是否使用流式输出 |
messages 参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
role | string | 是 | system、user 或 assistant |
content | string | 是 | 消息内容 |
普通请求
bash
curl https://api.nexusmodels.cn/v1/chat/completions \
-H "Authorization: Bearer YOUR_NEXUSMODELS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"messages": [
{
"role": "system",
"content": "你是一个专业的助手"
},
{
"role": "user",
"content": "请用三句话介绍人工智能"
}
]
}'流式请求
bash
curl https://api.nexusmodels.cn/v1/chat/completions \
-H "Authorization: Bearer YOUR_NEXUSMODELS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"messages": [
{
"role": "user",
"content": "请介绍人工智能"
}
],
"stream": true
}'响应示例
json
{
"id": "chatcmpl-example",
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "人工智能是一种让计算机执行智能任务的技术。"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 20,
"total_tokens": 32
}
}