Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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"

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

维护者通常 1 天内回复

@SparshGarg999 已经在做这个了。

开始于 2026年8月15日。

  • #2 来自 @SparshGarg999 —— 未关闭
  • #3621 来自 @SparshGarg999 —— 已关闭,未合并
  • #3942 来自 @00200200 —— 已关闭,未合并

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python
领域
api

调研方向

首先使用 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 内容生成。

描述

bug
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
  1. client.conversations.create() → keep conv_id.
  2. Stream a responses.create(..., conversation=conv_id, tools=[...], stream=True) whose prompt triggers the tool.
  3. On the response.output_item.added event for the function_call item, close the stream (stream.close()).
  4. Verify the conversation's items: conversations.items.list(conversation_id=conv_id) → empty, the function_call was never committed.
  5. Send the next turn on the same conversation with the tool's function_call_output + a user message.
  6. 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

环境准备

在 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 摘要。