通用接口
错误码
CokeAPI 全量错误码表,与 HTTP 状态码、OpenAI 风格 error.type 的映射。
所有失败响应统一格式:
{
"error": {
"type": "<错误类型>",
"code": <业务码>,
"message": "<可展示文案>",
"trace_id": "<排障 ID>"
}
}
code 字段:前 3 位与 HTTP 状态码一致,后 3 位为子码。
| code | type | message | HTTP |
|---|
| 400101 | invalid_param | 参数错误 | 400 |
| 400102 | bad_request | 请求格式不正确 | 400 |
| 400103 | body_too_large | 请求体过大 | 413 |
| 400401 | insufficient_points | 点数不足 | 400 |
| code | type | message | HTTP |
|---|
| 401101 | unauthorized | 未登录 | 401 |
| 401102 | token_expired | 登录已过期 | 401 |
| 401103 | token_invalid | 登录凭证无效 | 401 |
| 401104 | api_key_invalid | API Key 无效 | 401 |
| code | type | message | HTTP |
|---|
| 403101 | forbidden | 权限不足 | 403 |
| 403102 | ip_not_allowed | IP 不在白名单 | 403 |
| code | type | message | HTTP |
|---|
| 429101 | rate_limit_exceeded | 操作过于频繁 | 429 |
| 429301 | gen_rate_limited | 创作频次超限 | 429 |
| 429302 | daily_quota_exceeded | 每日调用配额已用尽 | 429 |
| code | type | message | HTTP |
|---|
| 502201 | upstream_unavailable | GPT 服务暂不可用 | 502 |
| 502202 | upstream_unavailable | GROK 服务暂不可用 | 502 |
| 502203 | no_available_account | 暂无可用账号 | 502 |
| code | type | message | HTTP |
|---|
| 500001 | internal | 系统繁忙 | 500 |
| 500002 | db_error | 数据库错误 | 500 |
| 500003 | cache_error | 缓存错误 | 500 |
429xxx:按 Retry-After 头退避重试。
502xxx:指数退避,最多 3 次 (CokeAPI 已在内部做账号池切换,客户端不要短时间内大量重试)。
4xx 业务错误:不要重试,先看 message 修参数。
- 报错时把
trace_id 贴给我们,可在控制台「请求日志」直接搜到全链路。