Authentication
所有 API 请求需要在 Header 中携带 API 密钥。
鉴权请求头
Authorization: Bearer <YOUR_UNIGATEWAY_API_KEY>
验证
curl https://api.unigateway.ai/v1/models \
-H "Authorization: Bearer $UNIGATEWAY_API_KEY"
返回模型列表说明鉴权生效。
安全提示:API 密钥保存在服务端环境变量中,不要暴露在前端代码或公开仓库中。
JSON POST 请求
Example request
Run it in your stack
Pick the SDK style that matches your app and copy the snippet directly into your project.
from openai import OpenAI
client = OpenAI(
api_key="<YOUR_UNIGATEWAY_API_KEY>",
base_url="https://api.unigateway.ai/v1",
)POST 请求还需要 Content-Type 请求头:
curl https://api.unigateway.ai/v1/chat/completions \
-H "Authorization: Bearer $UNIGATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"messages": [{"role": "user", "content": "你好"}]
}'
常见错误
| 状态码 | 原因 | 处理方式 |
|---|---|---|
401 | 密钥缺失、无效或已过期 | 检查 Authorization 请求头格式 |
403 | 密钥存在但权限不足 | 检查账户权限 |
429 | 超过频率或额度 | 增加退避重试 |
排查
Authorization格式必须为Bearer <token>- Base URL 必须为
https://api.unigateway.ai/v1 model值必须来自GET /v1/models
密钥管理
- 测试环境与生产环境使用不同的密钥
- 疑似泄露时立即轮换密钥