AsyncOpenAI.responses.stream() silently skips input validation due to stale isinstance(input, NotGiven) check
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
问题位于 src/openai/lib/_response_resources.py 的 async_stream() 中:第 587 行附近的 isinstance(input, NotGiven) 检查和第 650 行附近的 isinstance(response_id, Omit) 检查,应与同步版 stream() 已在使用的 is_given() 辅助函数保持一致。请先阅读第 412 行和第 477 行附近的同步版 stream() 以了解该模式。完成标准是:当省略 input 时,AsyncOpenAI 抛出与 OpenAI 相同的 ValueError,并且有测试覆盖两种情况:omit 情况和 NOT_GIVEN 情况。
由索引模型根据 Issue 内容生成。
描述
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
In src/openai/lib/_response_resources.py, async_stream() (backing AsyncOpenAI.responses.stream()) checks:
- Line 587:
if isinstance(input, NotGiven): - Line 650:
if isinstance(response_id, Omit):
However, both input and response_id default to omit (an instance of Omit, not NotGiven), and isinstance(omit, NotGiven) is False.
As a result:
- Calling
async_client.responses.stream(model="gpt-4o-mini")withoutinputsilently bypassesValueError("input must be provided when creating a new response"), returning anAsyncResponseStreamManagerwrapping a liveresource.create(input=omit, ...)coroutine (which dispatches an invalidPOST /v1/responsesrequest when entered, or emitsRuntimeWarning: coroutine 'AsyncResponses.create' was never awaitedif not entered). - Passing legacy
NOT_GIVENasresponse_idsimilarly bypasses line 650 (isinstance(response_id, Omit)), failing only later insideretrieve()upon__aenter__instead of failing fast at call time.
By contrast, sync stream() in the same file uses if not is_given(input): (line 412) and if not is_given(response_id): (line 477), and async_stream() itself uses if not is_given(model): three lines below (line 590).
To Reproduce
- Instantiate both
OpenAIandAsyncOpenAI. - Call
.responses.stream(model="gpt-4o-mini")withoutinput. - Observe that
OpenAIimmediately raisesValueError("input must be provided when creating a new response"), whileAsyncOpenAIreturns anAsyncResponseStreamManagerwithout raising.
Code snippets
from openai import AsyncOpenAI, OpenAI
from openai._types import NOT_GIVEN
sync_client = OpenAI(api_key="test-key")
async_client = AsyncOpenAI(api_key="test-key")
# Sync raises ValueError as expected:
try:
sync_client.responses.stream(model="gpt-4o-mini")
except ValueError as exc:
print("sync:", exc)
# sync: input must be provided when creating a new response
# Async silently bypasses validation because isinstance(omit, NotGiven) is False:
mgr = async_client.responses.stream(model="gpt-4o-mini")
print("async returned:", type(mgr).__name__)
# async returned: AsyncResponseStreamManager
mgr._AsyncResponseStreamManager__api_request.close()
# Same for legacy NOT_GIVEN on response_id:
mgr2 = async_client.responses.stream(response_id=NOT_GIVEN)
print("async response_id=NOT_GIVEN returned:", type(mgr2).__name__)
# async response_id=NOT_GIVEN returned: AsyncResponseStreamManager
mgr2._AsyncResponseStreamManager__api_request.close()
Suggested fix in src/openai/lib/_response_resources.py:
tools = _make_tools(tools)
if len(new_response_args_names) > 0:
- if isinstance(input, NotGiven):
+ if not is_given(input):
raise ValueError("input must be provided when creating a new response")
@@ -647,7 +647,7 @@
starting_after=None,
)
else:
- if isinstance(response_id, Omit):
+ if not is_given(response_id):
raise ValueError("response_id must be provided when streaming an existing response")
OS
macOS
Python version
Python 3.14
Library version
openai v3.57.0 (main@f63f14b)
- 主要语言
- 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