openai / openai/openai-python

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"

Open
#3,561 11 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
31.6k
Forks
5.7k
Avg merge
1d 6h
Merged PRs (30d)
96

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the streaming Responses API flow with client.responses.create(..., stream=True), stream.close(), and conversations.items.list(). Trace how response.output_item.added events are handled when the stream closes, using the linked JavaScript SDK fix as context. Done means the function_call item is persisted after abort and the following function_call_output turn succeeds without a 400 error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.