错误与故障排查
每个 API 错误——无论来自网关还是上游供应商——都使用统一的机器可读信封格式。request_id 可关联支持工单、日志和用量记录。
统一 ErrorEnvelope
不要解析给人看的 message。请基于 error.code 分支处理,并始终记录 error.request_id。这适用于网关层和上游供应商的所有错误。
ErrorEnvelope
json
{
"error": {
"code": "insufficient_balance",
"message": "Balance is too low",
"request_id": "{request_id}"
}
}追踪头
X-Request-ID
同一个值也会出现在 error.request_id 中,可用于排查上游供应商错误。
Gateway 限流
rate_limited
等到 X-RateLimit-Reset 后再重试。不要立即重试——连续 429 会延长限流窗口。
上游供应商故障
upstream_error
上游供应商返回了非正常响应。平台会自动重试或故障转移到其他模型。
余额不足
insufficient_balance
前往 /console/billing 充值后重试。长上下文请求会消耗更多 Token,建议保留充足余额。
已知错误码
来自 OpenAPI ErrorEnvelope schema 和当前 Go handler 的已知错误码。请使用这些错误码——而非 message 文本——进行编程式错误处理。
| 错误码 | 状态 | 出现条件 | 恢复建议 |
|---|---|---|---|
| invalid_request | 400 | Malformed JSON, unsupported fields, invalid cursor, or an out-of-range value. | Validate request JSON against the endpoint table and retry. |
| unauthorized | 401 | Missing, disabled, deleted, or invalid session/API key. | Create a fresh key or sign in again before retrying. |
| forbidden | 403 | A valid user tries to access an owner-only or admin-only resource. | Use the owning account or remove the restricted call. |
| not_found | 404 | The resource ID exists in the path but is not visible to the caller. | Check the request_id, API key ID, or recharge order ID. |
| payment_required / insufficient_balance | 402 | Wallet balance is too low for a gateway request. | Top up from Billing, then retry the same request. |
| rate_limited | 429 | The gateway rate limit is exhausted for the API key. | Back off until X-RateLimit-Reset before retrying. |
| upstream_error | 5xx | The selected model provider failed after the request reached routing. | Retry with jitter, or pin another model if a provider is degraded. |
| stripe_not_configured | 500 | Checkout was requested while Stripe configuration is missing. | Configure Stripe secrets in the server environment and restart billing services. |
| internal_error | 500 | Unexpected server failure. | Log request_id and contact support with the exact timestamp. |