零度API 文档
POST

Chat(聊天)

POST /v1/chat/completions — 创建聊天完成

Chat(聊天)

创建聊天完成(非流式)。所有对话模型均可使用此接口,修改 model 参数即可切换模型。

官方指南 · 官方 API 文档

POST https://api000.com/v1/chat/completions

请求参数

参数 类型 必填 说明
model string 必填 模型 ID,如 gpt-4oclaude-sonnet-4-5deepseek-chat
messages array 必填 对话消息列表(见下方说明)
temperature number 可选 采样温度 0-2,越高越随机,默认 1
top_p number 可选 核采样 0-1,与 temperature 二选一,默认 1
max_tokens integer 可选 最大输出 Token 数,默认无限制
n integer 可选 生成候选结果数量,默认 1
stream boolean 可选 是否流式返回,默认 false
stop string/array 可选 最多 4 个停止词
presence_penalty number 可选 -2.0 到 2.0,正值鼓励新话题
frequency_penalty number 可选 -2.0 到 2.0,正值减少重复
response_format object 可选 指定输出格式,如 {"type": "json_object"}
seed integer 可选 随机种子,相同值尽量返回相同结果
tools array 可选 工具/函数列表
tool_choice string/object 可选 控制工具调用策略
user string 可选 终端用户标识符,用于监控

messages 消息格式

每条消息是一个对象,包含 rolecontent

字段 类型 说明
role string system / user / assistant / tool
content stringarray 消息内容(视觉模型时为数组)
name string 可选,参与者名称
tool_calls array assistant 消息中的工具调用
tool_call_id string tool 消息对应的调用 ID

请求示例

cURL

curl https://api000.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxxxxxxxxxxxx" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "介绍一下深度学习的基本原理。"
      }
    ],
    "temperature": 0.7,
    "max_tokens": 1024
  }'

Python

from openai import OpenAI

client = OpenAI(
    base_url="https://api000.com/v1",
    api_key="sk-xxxxxxxxxxxxxxxx"
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "介绍一下深度学习的基本原理。"}
    ],
    temperature=0.7,
    max_tokens=1024
)

print(response.choices[0].message.content)

Node.js

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api000.com/v1",
  apiKey: "sk-xxxxxxxxxxxxxxxx",
});

const response = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "介绍一下深度学习的基本原理。" },
  ],
  temperature: 0.7,
  max_tokens: 1024,
});

console.log(response.choices[0].message.content);

响应示例

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-4o",
  "system_fingerprint": "fp_44709d6fcb",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "深度学习是机器学习的一个子领域,它使用多层神经网络来学习数据的表征..."
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 28,
    "completion_tokens": 120,
    "total_tokens": 148
  }
}

响应字段说明

字段 类型 说明
id string 本次请求唯一 ID,以 chatcmpl- 开头
object string 固定为 "chat.completion"
created integer 创建时间(Unix 时间戳)
model string 实际使用的模型 ID
choices array 模型生成的结果列表(通常只有 1 个)
choices[].message.role string 固定为 "assistant"
choices[].message.content string 模型回复的文本内容
choices[].finish_reason string 生成结束原因(见下表)
usage.prompt_tokens integer 输入消耗 Token 数
usage.completion_tokens integer 输出消耗 Token 数
usage.total_tokens integer 总 Token 数

finish_reason 枚举

说明
stop 模型自然停止(正常结束)
length 达到 max_tokens 限制
tool_calls 模型决定调用工具
content_filter 内容被安全过滤

支持的模型

所有对话模型均可使用此接口,修改 model 参数即可:

厂商 常用模型
OpenAI gpt-4o, gpt-4o-mini, gpt-4-turbo, o1, o3-mini
Anthropic claude-opus-4-5, claude-sonnet-4-5, claude-haiku-3-5
Google gemini-2.5-pro, gemini-2.0-flash
DeepSeek deepseek-chat, deepseek-reasoner
Grok grok-3, grok-2
Qwen qwen-max, qwen-plus, qwen-turbo
Meta Llama llama-3.3-70b-instruct, llama-3.1-8b-instruct

调用 GET /v1/models 获取完整可用模型列表。

零度API 文档