- 文档
- 参考
错误码
错误响应的格式、HTTP 状态码与建议的处理方式。
错误响应采用调用方所用协议的格式,现有 SDK 可以直接识别:OpenAI 系列接口返回 OpenAI 格式,/v1/messages 返回 Anthropic 格式。
OpenAI 格式示例
{ "error": { "message": "Balance is insufficient for this request: it may cost up to $0.0420 (up to 4096 output tokens) but $0.0100 is available. Lower the output token limit or add funds.", "type": "insufficient_quota", "code": "insufficient_quota" }}code 是稳定的机器可读错误码,可以放心用于程序判断;message 仅供阅读,可能调整。
| 状态码 | code |
含义 | 建议 |
|---|---|---|---|
| 400 | bad_request / validation_failed |
请求格式或参数有误 | 按 message 修正请求,不要重试 |
| 401 | invalid_api_key / unauthenticated |
缺少 Key、Key 无效、已吊销或已过期 | 检查 Key |
| 402 | insufficient_quota |
余额或 Key 额度不足以覆盖本次预扣 | 充值,或设置更小的 max_tokens |
| 403 | forbidden |
Key 无权使用该模型 | 在控制台调整 Key 的模型白名单 |
| 404 | model_not_found |
模型不存在或未上线 | 核对模型列表 |
| 429 | rate_limited |
超出 Key 的每分钟请求数 | 按 Retry-After 响应头等待后重试 |
| 502 | upstream_error |
所有可用渠道都返回了错误 | 稍后重试 |
| 503 | no_available_upstream |
该模型暂时没有可用渠道 | 稍后重试,或换用其他模型 |
| 504 | upstream_timeout |
上游响应超时 | 稍后重试;长任务建议使用流式输出 |
| 500 | internal |
服务内部错误 | 稍后重试;持续出现请联系我们 |
对 429、5xx 建议使用指数退避重试。网关在向你返回首字节之前已经自动在多个渠道之间重试,无需过于频繁地重试。