Skip to content

错误码参考

HTTP 状态码

状态码说明解决方案
200成功-
400请求参数错误检查请求格式
401认证失败检查 API Key
403权限不足检查用户权限
404资源不存在检查 URL
429请求过于频繁降低请求频率
500服务器错误联系客服
503服务不可用等待恢复

错误响应格式

json
{
  "error": {
    "message": "Invalid API key",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}

错误类型

invalid_request_error

请求参数错误。

错误代码说明解决方案
invalid_api_keyAPI Key 无效检查 API Key 格式
model_not_found模型不存在检查模型名称
insufficient_quota余额不足及时充值
invalid_request请求格式错误检查请求参数

rate_limit_error

请求频率超限。

错误代码说明解决方案
rate_limit_exceeded请求过于频繁降低请求频率

api_error

服务器错误。

错误代码说明解决方案
internal_error内部错误等待恢复或联系客服
service_unavailable服务不可用等待恢复

常见错误示例

401 - 认证失败

json
{
  "error": {
    "message": "Invalid API key",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}

解决方案:

  • 检查 API Key 是否正确
  • 确保 Authorization 头格式正确:Bearer sk-你的密钥

400 - 模型不存在

json
{
  "error": {
    "message": "Model not found",
    "type": "invalid_request_error",
    "code": "model_not_found"
  }
}

解决方案:

429 - 请求过于频繁

json
{
  "error": {
    "message": "Rate limit exceeded",
    "type": "rate_limit_error",
    "code": "rate_limit_exceeded"
  }
}

解决方案:

  • 降低请求频率
  • 添加请求间隔
  • 使用队列控制请求速度

403 - 余额不足

json
{
  "error": {
    "message": "Insufficient quota",
    "type": "invalid_request_error",
    "code": "insufficient_quota"
  }
}

解决方案:

下一步

基于 New API 开源项目