Skip to content

Chat Completions

创建一次对话补全请求。

请求地址

http
POST /v1/chat/completions

请求头

http
Authorization: Bearer YOUR_NEXUSMODELS_API_KEY
Content-Type: application/json

请求参数

参数类型必填说明
modelstring模型名称
messagesarray对话消息列表
temperaturenumber控制输出随机性
max_tokensinteger最大输出 Token 数
streamboolean是否使用流式输出

messages 参数

字段类型必填说明
rolestringsystemuserassistant
contentstring消息内容

普通请求

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
  }
}