Background responses failures lack a stable code/name that maps to an exception class

未关闭
#3,212 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@alextemn 已经在做这个了。

开始于 2026年8月23日。

  • #3723 来自 @alextemn —— 未关闭

评估

难度
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. incomplete runs surface their reason in incomplete_details.reason instead, 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:

  1. Add a stable, documented field to background-run failure payloads (e.g. error.type or error.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_error does today for HTTP status codes.

  2. Or: publish a documented, versioned mapping from each possible error.code / incomplete_details.reason value 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
  • openai Python SDK version: <fill in>
  • API: POST /v1/responses with background=true, polled via GET /v1/responses/{id}
Additional context

No response

主要语言
Python
星标
32.2k
派生
5.8k
平均合并
12 小时 29 分钟
30 天内合并 PR
112

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

openai/openai-python 的其他 Issue

查看 openai/openai-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。