完全兼容 OpenAI 接口规范,无需修改现有代码。
| Base URL | http://localhost:8000/v1 |
| 认证方式 | Authorization: Bearer sk-xxxx |
| 数据格式 | JSON / SSE 流式 |
POST /v1/chat/completions
curl http://localhost:8000/v1/chat/completions \
-H "Authorization: Bearer sk-你的密钥" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini",
"messages": [{"role":"user","content":"你好"}],
"stream": false
}'
from openai import OpenAI
client = OpenAI(
api_key="sk-你的密钥",
base_url="http://localhost:8000/v1"
)
resp = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "讲个笑话"}]
)
print(resp.choices[0].message.content)
GET /v1/models 返回当前可用模型。
| 401 | API Key 缺失或无效 |
| 402 | 余额不足或额度用尽 |
| 403 | Key 或账号已停用 |
| 503 | 没有可用上游渠道 |