Appearance
Chat Completions
创建模型聊天补全。
POST /v1/chat/completionsBase URL: https://www.sky-ze.com
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | ✓ | 模型 ID,见 模型列表 |
messages | array | ✓ | 消息列表,每条包含 role 和 content |
temperature | number | 采样温度 0~2,默认 1 | |
max_tokens | integer | 最大输出 token 数 | |
stream | boolean | 是否流式输出,默认 false | |
tools | array | Function call 工具定义 | |
tool_choice | string/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"]
}
}
}
]
}'