错误处理
理解 Buble API 错误响应与常见修复方式。
错误处理
Buble API 使用统一错误响应格式。
错误格式
{
"error": {
"code": "invalid_api_key",
"message": "Invalid or inactive API key.",
"details": {}
}
}只有存在额外结构化信息时才会返回 details。
鉴权错误
| Code | HTTP | 含义 | 处理方式 |
|---|---|---|---|
missing_api_key | 401 | 未提供 API Key。 | 发送 Authorization: Bearer <key>。 |
invalid_api_key | 401 | API Key 无效、未激活或已删除。 | 检查或轮换 Key。 |
invalid_api_key_owner | 401 | Key 所属用户不存在。 | 使用有效账号重新创建 Key。 |
请求错误
| Code | HTTP | 含义 | 处理方式 |
|---|---|---|---|
invalid_request_body | 400 | JSON 请求体无效或字段类型不匹配。 | 校验请求字段和类型。 |
unsupported_field | 400 | 传入了嵌套结构或内部字段。 | 移除 input、options、scene、sub_mode_id、provider、media type 和内部媒体字段。 |
missing_file | 400 | 上传请求缺少 file 字段。 | 添加 file 表单字段。 |
模型与 mode 错误
| Code | HTTP | 含义 | 处理方式 |
|---|---|---|---|
model_not_found | 404 | 模型不可用。 | 使用 /api/v1/models 返回的模型 key。 |
model_not_api_configured | 422 | 模型没有公开 API 配置。 | 选择其他 API 可用模型。 |
mode_not_supported | 422 | 当前模型不存在该 mode。 | 使用 /api/v1/models 的 operations[].mode。 |
mode_not_api_configured | 422 | mode 存在但没有公开 endpoint。 | 使用列表中的其他 operation。 |
unsupported_input_for_model | 422 | 输入形态不受支持。 | 查看该模型 mode 的输入要求。 |
ambiguous_generation_mode | 422 | 输入同时匹配多个 mode。 | 显式传入 mode。 |
mode_scene_missing | 422 | mode 缺少内部场景映射。 | 联系支持,这是配置问题。 |
文件错误
| Code | HTTP | 含义 | 处理方式 |
|---|---|---|---|
unsupported_file_type | 415 | MIME 类型不是图片、视频或音频。 | 上传支持的媒体文件。 |
unsupported_file_format | 415 | 文件格式不被所选 mode 支持。 | 查看模型参考中的格式限制。 |
file_too_large | 413 | 文件超出大小限制。 | 压缩文件或选择限制更宽的 mode。 |
upload_failed | 502 | 存储上传失败。 | 重试,持续失败请联系支持。 |
unsupported_upload_target | 422 | 配置的上传目标不支持。 | 联系支持,这是配置问题。 |