Background responses failures lack a stable code/name that maps to an exception class
维护者通常 1 天内回复
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- python
调研方向
从 openai/_client.py 及其 _make_status_error 方法开始,然后跟踪通过 GET /v1/responses/{id} 对 background=true 的 POST /v1/responses 进行轮询的流程。比较同步 HTTP 状态映射与失败和未完成 Response 的处理方式。选定的稳定映射或已记录的契约涵盖这些后台结果及其可重试性,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Confirm this is a feature request for the Python library and not the underlying OpenAI API.
- This is a feature request for the Python library
Describe the feature or improvement you're requesting
When the Responses API runs in background mode (background=True) and a run terminates in status="failed" (or status="incomplete"), the SDK does not surface a stable, machine-readable identifier that callers can map to an existing exception class.
The failure payload looks like:
{
"status": "failed",
"error": { "code": "server_error", "message": "..." },
"incomplete_details": null
}
The HTTP poll itself returns 200 OK, so the SDK's status-code dispatcher is never invoked and no typed exception is raised. The only signal of what kind of failure occurred is the free-form error.code string, which:
- is not documented as a stable enum,
- does not correspond 1:1 to any SDK exception class (
server_error≠InternalServerError,rate_limit_exceeded≠RateLimitError, etc.), - is not guaranteed to be present or non-null for every failure mode (e.g.
incompleteruns surface their reason inincomplete_details.reasoninstead, with yet another vocabulary), - and may carry values not enumerated anywhere the SDK or callers can rely on.
What exists today (synchronous mode)
For synchronous calls there is a clean, code-driven mapping in openai/_client.py keyed on HTTP status code:
def _make_status_error(self, err_msg, *, body, response):
data = body.get("error", body) if is_mapping(body) else body
if response.status_code == 400: return BadRequestError(...)
if response.status_code == 401: return AuthenticationError(...)
if response.status_code == 403: return PermissionDeniedError(...)
if response.status_code == 404: return NotFoundError(...)
if response.status_code == 409: return ConflictError(...)
if response.status_code == 422: return UnprocessableEntityError(...)
if response.status_code == 429: return RateLimitError(...)
if response.status_code >= 500: return InternalServerError(...)
return APIStatusError(...)
So the synchronous path has a fully deterministic, documented contract: HTTP code → exception class. The background path has no equivalent — neither in the response body (no stable code) nor in the SDK (no dispatcher).
Why this matters
In synchronous mode the SDK gives us a clean contract. In background mode the same root cause surfaces only as an opaque string with no contract. Any retry/backoff logic built around isinstance(e, InternalServerError) or isinstance(e, RateLimitError) simply cannot work for background runs, even though those are exactly the conditions where retry would be most useful.
Suggested feature
Either:
-
Add a stable, documented field to background-run failure payloads (e.g.
error.typeorerror.class) whose values directly correspond to existing SDK exception classes — e.g.internal_server_error,rate_limit_error,bad_request_error,content_filter_error, etc. The SDK can then mechanically map this field to the right exception class, mirroring what_make_status_errordoes today for HTTP status codes. -
Or: publish a documented, versioned mapping from each possible
error.code/incomplete_details.reasonvalue to the SDK exception class (or "no class") and to a retryable flag. Treat it as part of the public API contract.
Either approach gives background runs the same deterministic contract synchronous calls already enjoy.
Environment
openaiPython SDK version:<fill in>- API:
POST /v1/responseswithbackground=true, polled viaGET /v1/responses/{id}
Additional context
No response
- 主要语言
- Python
- 星标
- 32.2k
- 派生
- 5.8k
- 平均合并
- 12 小时 29 分钟
- 30 天内合并 PR
- 112
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
openai/openai-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
openai/openai-python#4338 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 65/100
openai/openai-python#4337 ·
维护者通常 1 天内回复
-
`BaseClient._prepare_url()` corrupts relative endpoint URLs when `base_url` contains query parameters可能已有人在做 @Rewaskc02-lang 于 2 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
openai/openai-python#4311 · 4 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
openai/openai-python#4310 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
openai/openai-python#4309 · 1 条评论 ·
维护者通常 1 天内回复
查看 openai/openai-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 86/100
bad-antics/lateralus-lang#1140 ·
维护者通常 4 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 3 天内回复
-
fixture good first issue help wanted vendor:cisco
难度 1/5 1-3 小时 新手友好度 85/100