Appearance
对话接口
OpenAI 兼容的文本对话接口。大多数 OpenAI SDK、LangChain、LlamaIndex 和自定义后端都优先接这个端点。
POSThttps://zrapi.org/v1/chat/completions
请求头
| Header | 值 |
|---|---|
Authorization | Bearer sk-YOUR_TOKEN |
Content-Type | application/json |
最小请求体
json
{
"model": "GPT-5.5",
"messages": [
{
"role": "user",
"content": "你好,请用一句话介绍你自己"
}
]
}示例
bash
curl https://zrapi.org/v1/chat/completions \
-H "Authorization: Bearer sk-YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "GPT-5.5",
"messages": [
{ "role": "user", "content": "你好,请用一句话介绍你自己" }
]
}'python
from openai import OpenAI
client = OpenAI(
api_key="sk-YOUR_TOKEN",
base_url="https://zrapi.org/v1",
)
response = client.chat.completions.create(
model="GPT-5.5",
messages=[{"role": "user", "content": "你好,请用一句话介绍你自己"}],
)
print(response.choices[0].message.content)javascript
import OpenAI from 'openai'
const client = new OpenAI({
apiKey: 'sk-YOUR_TOKEN',
baseURL: 'https://zrapi.org/v1',
})
const response = await client.chat.completions.create({
model: 'GPT-5.5',
messages: [{ role: 'user', content: '你好,请用一句话介绍你自己' }],
})
console.log(response.choices[0].message.content)常用字段
| 字段 | 类型 | 说明 |
|---|---|---|
model | string | 模型 ID,见 模型与价格 |
messages | array | 对话消息列表 |
temperature | number | 随机性,通常 0 到 2 |
max_tokens | number | 最大输出 token 数 |
stream | boolean | 是否使用流式输出 |
tools | array | 工具 / 函数调用定义,是否可用取决于模型 |
响应示例
json
{
"id": "chatcmpl_xxx",
"object": "chat.completion",
"created": 1760000000,
"model": "GPT-5.5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好,我是一个可以帮助你处理文本、代码和知识问题的 AI 助手。"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 18,
"completion_tokens": 24,
"total_tokens": 42
}
}常见状态码
| 状态码 | 含义 | 处理方式 |
|---|---|---|
| 200 | 请求成功 | 读取 choices[0].message.content |
| 400 | 请求体格式错误 | 检查 JSON、字段名和模型是否支持该参数 |
| 401 | 认证失败 | 检查 API Key 和 Authorization |
| 402 | 余额不足 | 充值或更换账户 |
| 404 | 端点或模型不存在 | 检查 Base URL 与模型 ID |
| 429 | 请求频率过高 | 降低并发或指数退避 |
| 500 / 502 | 服务端或上游异常 | 稍后重试或切换模型 |