Skip to content

Chat Completions

创建模型聊天补全。

POST /v1/chat/completions

Base URL: https://www.sky-ze.com

请求参数

参数类型必填说明
modelstring模型 ID,见 模型列表
messagesarray消息列表,每条包含 rolecontent
temperaturenumber采样温度 0~2,默认 1
max_tokensinteger最大输出 token 数
streamboolean是否流式输出,默认 false
toolsarrayFunction call 工具定义
tool_choicestring/object工具选择策略

非流式调用

curl

bash
curl https://www.sky-ze.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPT_API_KEY" \
  -d '{
    "model": "qwen3-max-2026-01-23",
    "messages": [
      {"role": "system", "content": "你是一个有帮助的助手。"},
      {"role": "user", "content": "用一句话介绍量子计算。"}
    ],
    "temperature": 0.7,
    "max_tokens": 200
  }'

响应

json
{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "created": 1717008000,
  "model": "qwen3-max-2026-01-23",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "量子计算是一种利用量子力学原理进行信息处理的新型计算方式。"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 28,
    "completion_tokens": 18,
    "total_tokens": 46
  }
}

流式输出

bash
curl https://www.sky-ze.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPT_API_KEY" \
  -d '{
    "model": "qwen3-max-2026-01-23",
    "messages": [{"role": "user", "content": "讲个笑话"}],
    "stream": true
  }'

响应为 SSE 事件流,每个 data 行包含一个 JSON chunk:

data: {"choices":[{"delta":{"content":"为"},"index":0}],...}
data: {"choices":[{"delta":{"content":"什么"},"index":0}],...}
...
data: [DONE]

Function Calling

bash
curl https://www.sky-ze.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPT_API_KEY" \
  -d '{
    "model": "qwen3-max-2026-01-23",
    "messages": [{"role": "user", "content": "北京今天天气怎么样?"}],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "获取指定城市的天气",
          "parameters": {
            "type": "object",
            "properties": {
              "city": {"type": "string", "description": "城市名称"}
            },
            "required": ["city"]
          }
        }
      }
    ]
  }'

OPT 企业级 AI 模型服务平台