接口文档
完全兼容 OpenAI Chat Completions 协议,用官方 SDK 即可调用
Base URL:
认证方式:请求头
https://api.zaizaituandui.cn/v1认证方式:请求头
Authorization: Bearer <你的 sk- 密钥>
认证
所有接口都需要在请求头带上你的密钥。密钥在控制台创建,只在创建时完整显示一次。
Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
密钥无效或已吊销时返回 401,响应体为 {"detail":"Not authenticated"}。
对话补全
POST https://api.zaizaituandui.cn/v1/chat/completions
请求参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型名称,见下方列表 |
| messages | array | 是 | 消息数组,每项含 role 与 content |
| stream | bool | 否 | 为 true 时以 SSE 流式返回 |
| temperature | float | 否 | 采样温度,默认 0.7 |
| max_tokens | int | 否 | 最大生成 token 数 |
响应结构
推理模型的思考过程在 message.reasoning_content,正式回答在 message.content。业务代码请取 content。
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"created": 1794018300,
"model": "deepseek-r1:1.5b",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好,我是……",
"reasoning_content": "用户问的是……"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 75,
"total_tokens": 87
}
}
调用示例
from openai import OpenAI
client = OpenAI(
api_key="你的 sk- 密钥",
base_url="https://api.zaizaituandui.cn/v1",
)
resp = client.chat.completions.create(
model="deepseek-r1:1.5b",
messages=[
{"role": "system", "content": "你是一个简洁的助手"},
{"role": "user", "content": "介绍一下你自己"},
],
temperature=0.7,
)
print(resp.choices[0].message.content)
curl https://api.zaizaituandui.cn/v1/chat/completions \
-H "Authorization: Bearer 你的 sk- 密钥" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-r1:1.5b",
"messages": [{"role":"user","content":"你好"}],
"stream": false
}'
from openai import OpenAI
client = OpenAI(api_key="你的 sk- 密钥", base_url="https://api.zaizaituandui.cn/v1")
stream = client.chat.completions.create(
model="deepseek-r1:1.5b",
messages=[{"role": "user", "content": "讲个笑话"}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta
# 正文
if getattr(delta, "content", None):
print(delta.content, end="", flush=True)
# 思考过程(推理模型才有),不想显示就跳过
if getattr(delta, "reasoning_content", None):
pass
模型列表
GET https://api.zaizaituandui.cn/v1/models
{
"object": "list",
"data": [
{ "id": "deepseek-r1:1.5b", "object": "model", "owned_by": "library" }
]
}
错误码
| 状态码 | 含义 | 处理建议 |
|---|---|---|
| 401 | 密钥缺失、错误或已吊销 | 检查请求头;到控制台确认密钥状态 |
| 404 | 路径不对 | 确认 Base URL 带 /v1 |
| 429 | 请求过于频繁 | 退避重试 |
| 500 / 502 | 上游推理服务异常 | 稍后重试;持续出现请联系管理员 |
| 504 | 推理超时 | 调大客户端超时到 300 秒以上 |
注意事项
- · 该模型跑在无 GPU 的 CPU 上,生成速度约 10~15 token/秒,单次请求请把超时设到 300 秒以上。
- · 密钥等同于密码:不要写进前端、不要提交到 Git、不要发在群里。
- · 所有调用都会记账,控制台可以查最近记录。
- · 如果密钥可能泄露,立刻到控制台吊销并重建。