Skip to content

Bad Request 400 : Reasoning model issue while store is True #1611

@ashish-auditorsdesk

Description

@ashish-auditorsdesk

A BadRequestError (400) occurs because the request includes a reasoning item (rs_68b14140...) without its required subsequent item. This indicates the input structure is incomplete or incorrectly formatted from the backend in Responses API.

## Issue Output
---------------------------------------------------------------------------
BadRequestError                           Traceback (most recent call last)
Cell In[273], [line 1](vscode-notebook-cell:?execution_count=273&line=1)
----> [1](vscode-notebook-cell:?execution_count=273&line=1) response = client.responses.create(
      2                 model="gpt-5",
      3                 input=[
      4                     {
      5                         "role": "user",
      6                         "content": [{"type": "input_text", "text": "Not ab,e to download the file you have shared"}],
      7                     }
      8                 ],
      9                 previous_response_id="resp_68b140cf2c9c8193a6417aabd97428b40b003345362caed7"
     10 
     11             )

File ~/Library/Python/3.9/lib/python/site-packages/openai/resources/responses/responses.py:795, in Responses.create(self, background, include, input, instructions, max_output_tokens, max_tool_calls, metadata, model, parallel_tool_calls, previous_response_id, prompt, prompt_cache_key, reasoning, safety_identifier, service_tier, store, stream, stream_options, temperature, text, tool_choice, tools, top_logprobs, top_p, truncation, user, extra_headers, extra_query, extra_body, timeout)
    759 def create(
    760     self,
    761     *,
   (...)
    793     timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
    794 ) -> Response | Stream[ResponseStreamEvent]:
--> [795](https://file+.vscode-resource.vscode-cdn.net/Users/ashishsapra/Downloads/~/Library/Python/3.9/lib/python/site-packages/openai/resources/responses/responses.py:795)     return self._post(
    796         "/responses",
    797         body=maybe_transform(
    798             {
    799                 "background": background,
    800                 "include": include,
    801                 "input": input,
    802                 "instructions": instructions,
    803                 "max_output_tokens": max_output_tokens,
    804                 "max_tool_calls": max_tool_calls,
    805                 "metadata": metadata,
    806                 "model": model,
    807                 "parallel_tool_calls": parallel_tool_calls,
    808                 "previous_response_id": previous_response_id,
    809                 "prompt": prompt,
    810                 "prompt_cache_key": prompt_cache_key,
    811                 "reasoning": reasoning,
    812                 "safety_identifier": safety_identifier,
    813                 "service_tier": service_tier,
    814                 "store": store,
    815                 "stream": stream,
    816                 "stream_options": stream_options,
    817                 "temperature": temperature,
    818                 "text": text,
    819                 "tool_choice": tool_choice,
    820                 "tools": tools,
    821                 "top_logprobs": top_logprobs,
    822                 "top_p": top_p,
    823                 "truncation": truncation,
    824                 "user": user,
    825             },
    826             response_create_params.ResponseCreateParamsStreaming
    827             if stream
    828             else response_create_params.ResponseCreateParamsNonStreaming,
    829         ),
    830         options=make_request_options(
    831             extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
    832         ),
    833         cast_to=Response,
    834         stream=stream or False,
    835         stream_cls=Stream[ResponseStreamEvent],
    836     )

File ~/Library/Python/3.9/lib/python/site-packages/openai/_base_client.py:[1259](https://file+.vscode-resource.vscode-cdn.net/Users/ashishsapra/Downloads/~/Library/Python/3.9/lib/python/site-packages/openai/_base_client.py:1259), in SyncAPIClient.post(self, path, cast_to, body, options, files, stream, stream_cls)
   1245 def post(
   1246     self,
   1247     path: str,
   (...)
   1254     stream_cls: type[_StreamT] | None = None,
   1255 ) -> ResponseT | _StreamT:
   1256     opts = FinalRequestOptions.construct(
   1257         method="post", url=path, json_data=body, files=to_httpx_files(files), **options
   1258     )
-> 1259     return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))

File ~/Library/Python/3.9/lib/python/site-packages/openai/_base_client.py:[1047](https://file+.vscode-resource.vscode-cdn.net/Users/ashishsapra/Downloads/~/Library/Python/3.9/lib/python/site-packages/openai/_base_client.py:1047), in SyncAPIClient.request(self, cast_to, options, stream, stream_cls)
   1044             err.response.read()
   1046         log.debug("Re-raising status error")
-> 1047         raise self._make_status_error_from_response(err.response) from None
   1049     break
   1051 assert response is not None, "could not resolve response (should never happen)"

BadRequestError: Error code: 400 - {'error': {'message': "Item 'rs_68b14140d5848193a4a6d51d06d2ff9d0b003345362caed7' of type 'reasoning' was provided without its required following item.", 'type': 'invalid_request_error', 'param': 'input', 'code': None}}

Debug information

  • Python 3.12.3
  • OpenAI 1.99.9

Repro steps

Use this code with any file with any prompt:

response = client.responses.create(
  model="gpt-5",
  input=[
    {
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "Give me items which are in books but not in 2B"
        }
      ]
    }
  ],
  text={
    "format": {
      "type": "text"
    },
    "verbosity": "medium"
  },
  reasoning={
    "effort": "medium"
  },
  tools=[
    {
      "type": "code_interpreter",
      "container": {
        "type": "auto",
        "file_ids": [
          "file-4vLY8h****",
          "file-3xAy2*****"
        ]
      }
    }
  ],
  store=True,
  include=[
    "code_interpreter_call.outputs",
    "reasoning.encrypted_content",
    "web_search_call.action.sources"
  ]
)
  • Store the send the response_id as previous_response_id in next call, input_text it can be anything
response = client.responses.create(
                model="gpt-5",
                input=[
                    {
                        "role": "user",
                        "content": [{"type": "input_text", "text": "Not ab,e to download the file you have shared"}],
                    }
                ],
                previous_response_id="resp_68b1****"
            )
  • This will trigger this error

Expected behavior

It should give explanation

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions