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"

Ouverte
#3,561 16 commentaires 2 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@SparshGarg999 y travaille déjà.

Depuis le 15/8/2026.

  • #2 par @SparshGarg999 — ouverte
  • #3621 par @SparshGarg999 — fermée sans fusion
  • #3942 par @00200200 — fermée sans fusion

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
55/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
python
Domaine
api

Piste de recherche

Commencez par reproduire le flux de l’API Responses en streaming avec client.responses.create(..., stream=True), stream.close() et conversations.items.list(). Suivez la manière dont les événements response.output_item.added sont traités lorsque le flux se ferme, en vous appuyant sur le correctif lié du JavaScript SDK. Le travail est terminé lorsque l’élément function_call est persisté après l’abandon et que le tour function_call_output suivant réussit sans erreur 400.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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

Langage dominant
Python
Étoiles
32k
Forks
7.3k
Merge moyen
16 h 38 min
PR mergées (30 j)
170

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de openai/openai-python

Toutes les issues de openai/openai-python

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.