Aborting a streaming Responses API request drops the function_call item, breaking the next turn with 400 "No tool call found for function call output"
维护者通常 1 天内回复
@SparshGarg999 已经在做这个了。
开始于 2026年8月15日。
评估
调研方向
首先使用 client.responses.create(..., stream=True)、stream.close() 和 conversations.items.list() 重现 Responses API 的流式流程。参考链接的 JavaScript SDK 修复,跟踪流关闭时如何处理 response.output_item.added 事件。完成标准是:中止后 function_call 项被持久化,且后续的 function_call_output 轮次在没有 400 错误的情况下成功。
由索引模型根据 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
When a Responses API request is aborted mid-stream (client closes the stream) after a function_call item has already been streamed back, that item is never persisted to the conversation. The next turn on the same conversation that sends the matching function_call_output fails with:
400 No tool call found for function call output with call_id call_q7hr5y6HlCZkOvJ4t5cYPZM9.
The caller executes the tool locally after the abort, so the output exists and is valid — but the remote conversation has no record of the tool call it belongs to. The API gives no signal at abort time that the streamed items were discarded.
Additional context
Same issue has been fixed in the js sdk in https://github.com/openai/openai-agents-js/pull/1241
To Reproduce
client.conversations.create()→ keepconv_id.- Stream a
responses.create(..., conversation=conv_id, tools=[...], stream=True)whose prompt triggers the tool. - On the
response.output_item.addedevent for thefunction_callitem, close the stream (stream.close()). - Verify the conversation's items:
conversations.items.list(conversation_id=conv_id)→ empty, thefunction_callwas never committed. - Send the next turn on the same conversation with the tool's
function_call_output+ a user message. - See
400 No tool call found for function call output with call_id ....
Code snippets
import openai
client = openai.OpenAI()
tools = [{
"type": "function",
"name": "get_weather",
"description": "Get the current weather for a location",
"parameters": {"type": "object", "properties": {"location": {"type": "string"}}, "required": ["location"]},
}]
conv = client.conversations.create()
conv_id = conv.id
# 1) streaming turn that triggers a tool call
stream = client.responses.create(
model="gpt-4.1-mini",
input="What is the weather in Amsterdam?",
conversation=conv_id,
tools=tools,
stream=True,
)
call_id = None
for event in stream:
if event.type == "response.output_item.added" and event.item.type == "function_call":
call_id = event.item.call_id
print("captured:", call_id)
stream.close() # abort mid-stream
break
# 2) the function_call was NOT persisted
items = client.conversations.items.list(conversation_id=conv_id)
print("persisted items:", [i.type for i in items.data]) # -> []
# 3) next turn on the SAME conversation
client.responses.create(
model="gpt-4.1-mini",
input=[
{"type": "function_call_output", "call_id": call_id, "output": '{"temp": 18, "condition": "cloudy"}'},
{"type": "message", "role": "user", "content": "Is it cold?"},
],
conversation=conv_id,
tools=tools,
)
# -> BadRequestError 400: No tool call found for function call output with call_id call_q7hr5y6HlCZkOvJ4t5cYPZM9.
OS
Windows 10
Python version
Python v3.11.5
Library version
openai v2.45.0
- 主要语言
- Python
- 星标
- 31.8k
- 派生
- 7.3k
- 平均合并
- 1 天 3 小时
- 30 天内合并 PR
- 131
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
openai/openai-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
openai/openai-python#4022 · 19 条评论 ·
维护者通常 1 天内回复
-
fix(auth): SubjectTokenProviderError drops response and duplicates error message in workload identity providers可能已有人在做 @mohmedmm 于 9 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
openai/openai-python#4017 · 3 条评论 ·
维护者通常 1 天内回复
-
Querystring drops explicit empty-string scalar values可能已有人在做 @sylvesterkaczmarek 于 31 天前认领。 未关闭sdk-breaking-change v4
难度 2/5 1-3 小时 新手友好度 86/100
openai/openai-python#3837 ·
维护者通常 1 天内回复
-
Define + export `ServiceTiers` string literal可能已有人在做 @SparshGarg999 于 57 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
openai/openai-python#3556 · 3 条评论 ·
维护者通常 1 天内回复
-
Empty OPENAI_BASE_URL prevents fallback to default API endpoint可能已有人在做 @Sehastrajit-S 于 24 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 68/100
openai/openai-python#2927 · 6 条评论 ·
维护者通常 1 天内回复
查看 openai/openai-python 的全部 Issue
相似的 Issue
-
namespace operations
难度 1/5 1 小时以内 新手友好度 72/100
EclipseFdn/open-vsx.org#14043 ·
维护者通常 1 天内回复
-
netbox status: needs triage type: bug
难度 2/5 1-3 小时 新手友好度 76/100
netbox-community/netbox#23376 ·
维护者通常 1 天内回复
-
feedback simulation workshop
难度 2/5 1-3 小时 新手友好度 73/100
githubnext/gh-aw-workshop#4455 ·
维护者通常 1 天内回复
-
Triage 🩺
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
[BUG] Container scenario crashes without expected_recovery_time, kube DNS example uses retry_wait未关闭needs-triage
难度 2/5 1-3 小时 新手友好度 77/100
krkn-chaos/krkn#1627 · 1 条评论 ·
维护者通常 1 天内回复