Currently, it appears that web search tool call history cannot be manually passed back into the Responses API. I’ve written a minimal reproducible example below:
from openai import OpenAI
client = OpenAI()
# Ask a simple question to trigger web search
history = [{"role": "user", "content": "What is the most recent version of Python? Output one sentence."}]
# Call responses API as usual
response = client.responses.create(
model="gpt-4o",
tools=[{"type": "web_search_preview"}],
input=history,
store=False
)
# View response with web search
print(response)
# Add the response to the conversation
# NOTE: This includes the "web_search_call" type, which is causing the issue.
history += [el.model_dump() for el in response.output]
# Add new user message
history.append({"role": "user", "content": "Thanks!"})
# THIS WILL ALWAYS ERROR!
# Web search history cannot be passed into the model?
second_response = client.responses.create(
model="gpt-4o",
tools=[{"type": "web_search_preview"}],
input=history,
store=False
)
print(second_response)
Here is the error returned by the API:
Traceback (most recent call last):
File "C:\...\test_openai_web_search.py", line 22, in <module>
second_response = client.responses.create(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\...\site-packages\openai\_utils\_utils.py", line 279, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\...\site-packages\openai\resources\responses\responses.py", line 602, in create
return self._post(
^^^^^^^^^^^
File "C:\Users\dlhs_42\AppData\Local\anaconda3\envs\chatdl_205\Lib\site-packages\openai\_base_client.py", line 1242, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\...\site-packages\openai\_base_client.py", line 919, in request
return self._request(
^^^^^^^^^^^^^^
File "C:\...\site-packages\openai\_base_client.py", line 1023, in _request
raise self._make_status_error_from_response(err.response) from None
openai.NotFoundError: Error code: 404 - {'error': {'message': "Item with id 'ws_67dd76373c188191aa60e4370d6a64a80e369dcf59cc7265' not found.", 'type': 'invalid_request_error', 'param': 'input', 'code': None}}
From what I can see, this looks like either a bug, or a bad error. The web search ID the model just generated is not retrievable directly afterwards.
The only solution is to not pass the web search call into the chat history. As a result, the model has no recollection that it used web search, and this causes the model to perform terribly at follow-up questions, or it needs to re-search the web for each user message.
If web search results/usage cannot be passed in as input, that should really be in the documentation. Hopefully this is just a bug.
Has anybody else encountered this?