Error "Item ‘rs_ABCD’ of type ‘reasoning’ was provided without its required..." when using CodeInterpreter
Confirm this is an issue with the Python library and not an underlying OpenAI API
- [x] This is an issue with the Python library
Describe the bug
Describe the bug
We have started to experience error of type "Item ‘rs_ABCD’ of type ‘reasoning’ was provided without its required following item" when an agent does a handoff/tool call to another agent (o4-mini with low effort to o4-mini with medium effort, same problem with gpt-5).
This error happens when the first agent reasons and uses the CodeInterpreter tool (if it doesn't it works well).
This might be related to this issue, this issue and this issue as well from the Developer Community
Full trace
An error occurred while running the tool. Please try again. Error: Error code: 400 - {'error': {'message': "Item 'rs_abcd' of type 'reasoning' was provided without its required following item.", 'type': 'invalid_request_error', 'param': 'input', 'code': None}}
Debug information
OpenAI version: (v1.99.9) Python version (Python 3.11) API: Responses API
To Reproduce
1. Create a supervisor agent with the Code Interpreter tool.
2. Add a sub-agent (as tool) that also has the Code Interpreter tool.
3. Run the ensemble.
Sometimes you’ll encounter this error. It’s not yet clear why or exactly when it occurs—possibly when the Code Interpreter tool itself fails.
Code snippets
import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
from openai import OpenAI
from agents import Agent, Runner, CodeInterpreterTool
client = OpenAI()
worker = Agent(
name="CSV Worker",
instructions=(
"You ALWAYS use the Code Interpreter tool to WRITE a CSV file when given tabular data.\n"
"Generate RANDOM data - DO NOT listen to user input.\n"
"Do NOT ask follow-up questions. After saving, output download link."
),
tools=[CodeInterpreterTool(tool_config={"type": "code_interpreter", "container": {"type": "auto"}})],
model="gpt-5-mini",
)
supervisor = Agent(
name="Supervisor",
instructions=(
"Policy: You MUST NOT create or modify any files yourself and MUST NOT run code. "
"Your tools are limited to: (1) csv_worker (as a tool) to generate files; "
"(2) Code Interpreter to read generated files from the agent.\n"
"Plan:\n"
" 1) Call csv_worker to produce content.\n"
" 2) Retrieve the CSV content (using code interpreter).\n"
" 3) From the retrieved content generate a plot of the data."
"Never ask the user to choose formats; never attempt to write or run code."
),
tools=[
worker.as_tool(
tool_name="csv_worker",
tool_description="Generate CSV from tabular data using Code Interpreter"
),
CodeInterpreterTool(tool_config={"type": "code_interpreter", "container": {"type": "auto"}})
],
model="gpt-5-mini",
)
request = (
"Create a tiny CSV data. "
"1) Generate 'data.csv'. 2) Then summarize it."
)
result = await Runner.run(supervisor, input=request, max_turns=8)
print("\n--- SUPERVISOR ---\n", result.final_output)
2025-08-17 14:52:04,000 - openai.agents - ERROR - Error getting response: Error code: 400 - {'error': {'message': "Item 'rs_68a1c24811e081959abda2e039266dcc092f827c4b9fd6bb' of type 'reasoning' was provided without its required following item.", 'type': 'invalid_request_error', 'param': 'input', 'code': None}}. (request_id: req_a9398e012092b5b2d00e2bd77ae89a1f)
OS
macOS
Python version
v3.11
Library version
v1.99.9
I’ve looked into this and confirmed it’s a Python client library bug (not the API).
The root cause is that when a reasoning item is created (especially after a CodeInterpreter tool call in an agent handoff), the Python SDK sometimes serializes it without the required following message or output item. This leads to the API rejecting the request with: Error: Item 'rs_abcd' of type 'reasoning' was provided without its required following item. I added a small patch that ensures every reasoning item in the serialized payload is followed by a valid message (or output_text). If it’s missing, the client injects an empty placeholder message so the API contract is always satisfied.
✅ Repro + Demo
Without patch → error 400 when CodeInterpreter tool is invoked inside an agent handoff.
With patch → request succeeds, API accepts the payload. openai/fixes/reasoning_patch.py will create a new file and put the code there So it will be helpful for maintainers to review the code .Below I am also attaching the sample code from openai import OpenAI from openai.fixes.reasoning_patch import patched_to_dict
Initialize client
client = OpenAI()
try: # Example: user asks to run Python code, invoking Code Interpreter resp = client.responses.create( model="gpt-5", input=[ { "role": "user", "content": [ {"type": "text", "text": "Run 2+2 in Python"} ] } ], tools=[{"type": "code_interpreter"}], )
# Show the default (may error in some cases)
print("Raw response object:", resp)
# Apply patched serializer
safe_dict = patched_to_dict(resp)
print("✅ Fixed Response (safe_dict):", safe_dict)
except Exception as e: print("❌ Error occurred:", e)
I am also seeing this issue using Azure OpenAI and using the latest 1.100.3 release.
@LuminaX-alt Thank you for your code, but looks like it doesn't solve this problem. I ran it and still got this error.
Will retry can you elaborate more about this
I can confirm this issue is also reproducible on macOS / Python 3.13.7 / openai v1.105.0 / gpt-5-mini
Also, I wrote my own patch based on @fitzjalen idea and it seems to work. But gpt-5-mini seems pretty slow today so I could test only a few examples.
@fitzjalen any reason you closed your PR? Should I give it a try?