How to Use Web Search in ChatGPT API
In this tutorial, we will explore how to use web search in OpenAI API. Installation Step : Please make sure to install the openai library using the command - pip install openai. Python Code from op...
Source: ListenData
In this tutorial, we will explore how to use web search in OpenAI API. Installation Step : Please make sure to install the openai library using the command - pip install openai. Python Code from openai import OpenAI client = OpenAI(api_key="sk-xxxxxxxxx") # Replace with your actual API key response = client.responses.create( model="gpt-5.4", tools=[{"type": "web_search_preview"}], input="Apple (AAPL) most recent stock price" ) print(response.output_text) Output As of the latest available data (April 2, 2026), Apple Inc. (AAPL) stock is trading at $255.92 per share, reflecting an increase of $0.29 (approximately 0.11%) from the previous close. Search Detail Level In the openai latest models, the search_context_size setting controls how much information the tool gathers from the web to answer your question. A higher setting gives better answers but is slower and costs more while a lower setting is faster and cheaper but might not be as ac