#Force GPT to use a web search

1 messages · Page 1 of 1 (latest)

polar kayak
#

Is there a way to force GPT to use a web search? Or rather, to force GPT to always retrieve the web page it uses? My code roughly looks like:

instructions = '''
You must search through the following web domain to find relevant results: (URL HERE)
'''

response = gpt_client.responses.create(
    model="gpt-4o", 
    instructions=instructions,
    input=prompt,
    tools=[{"type": "web_search_preview"}],
)
annotations = response.output[1].content[0].annotations

And although it does use the URL I provide in the instructions to find information, occasionally the annotations list is just empty for whatever reason. I am completely new to using the API and programming in general so I'd like to avoid making this too complex.