Skip to content

错误码详解

401 Unauthorized

原因:API Key 无效或已过期。

json
{"error": {"message": "Invalid API key", "code": 401}}

排查:确认 key 拼写正确、未过期。


403 Forbidden

原因:余额不足或权限不足。


429 Rate Limit Exceeded

原因:超出 RPM 或 TPM 限制。

python
import time
for attempt in range(3):
    try:
        return client.chat.completions.create(...)
    except RateLimitError:
        time.sleep(2 ** attempt)  # 指数退避

400 Bad Request

常见场景:

  • model 模型名不支持
  • messages 缺少 role
  • stream: trueresponse_format 不兼容

500 / 502 / 503

上游服务错误,等待后重试或切换 channel。


速查表

错误信息HTTP原因处理
Invalid API key401key 无效检查拼写
Insufficient credits403余额不足充值
Rate limit exceeded429超限等待/切换 channel
context_length_exceeded400输入超长缩短或换 32k 模型
model_not_found400模型不存在检查模型名