错误
LLMAPI 会尽量返回 HTTP 状态码和结构化错误信息。不同协议会保留对应协议的错误格式,因此错误响应并不只有一种 JSON 形态。
通用错误格式
Anthropic/OpenAI 兼容接口常见格式:
json
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "Request body is empty"
}
}OpenAI 图片接口常见格式:
json
{
"error": {
"type": "not_found_error",
"message": "Images API is not supported for this platform"
}
}常见 HTTP 状态码
| 状态码 | 说明 | 常见原因 |
|---|---|---|
400 | 请求无效 | JSON 不合法、参数类型错误、平台分组不匹配。 |
401 | 认证失败 | API Key 缺失或无效。 |
403 | 权限不足 | 余额不足、Key 类型错误、分组未启用生图能力、内容风控拦截。 |
404 | 接口或能力不可用 | 非 OpenAI 分组调用 OpenAI 同步图片接口、OpenAI 分组调用 token count。 |
413 | 请求体过大 | 请求体超过服务端配置上限。 |
429 | 限流 | 并发请求过多。 |
500 | 服务错误 | 未预期错误。 |
502 | 服务商错误 | 模型服务商返回错误。 |
503 | 服务不可用 | 无可用账号或必要服务不可用。 |
504 | 超时 | 请求执行超时。 |
平台限制错误
非 OpenAI 分组调用 OpenAI 同步图片接口:
json
{
"error": {
"type": "not_found_error",
"message": "Images API is not supported for this platform"
}
}OpenAI 分组调用 token count:
json
{
"type": "error",
"error": {
"type": "not_found_error",
"message": "Token counting is not supported for this platform"
}
}重试建议
| 错误类型 | 建议 |
|---|---|
400、401、403、404 | 不要原样重试,先修正请求、认证、分组或权限。 |
413 | 缩小请求体或上传资源。 |
429 | 使用指数退避重试,并降低并发数。 |
500、502、503、504 | 使用指数退避重试。 |