Hey folks!
I’ve been playing around with OpenAI’s new responses
API, which supports the web search tool.
That means GPT can look up fresh info on the internet when it needs to — so it’s not stuck in the past.
I thought I’d put together a Google Colab notebook you can run yourself if you have an OpenAI API key, plus walk you through the code here step by step, in case you’re curious what’s happening under the hood.
Here’s the notebook you can copy & play with:
Open in Google Colab
It’s designed so even if you’re not a Python person, you can still follow along.
What we’re building
Basically we’ll:
load your OpenAI API key securely,
create a client to talk to GPT-4.1,
give it permission to do a web search,
ask for something like “pizza places in the Bastille area of Paris”,
and then print out (and nicely format) its answer.
This is ridiculously powerful — imagine using it to build travel helpers, local guides, or just get more current info than GPT’s old 2023 data.
Step 1. Get your API key & store it in Colab
Before we do anything, we need your OpenAI API key.
Here’s the quickest way:
Get your key
Log into your OpenAI account and go to https://platform.openai.com/account/api-keys.
Click “Create new secret key”.
Store it in Colab
In your Colab notebook, click the key icon on the left sidebar called Secrets. (It has a 🔑 icon).
Click + Add new secret.
Set the name to
OPENAI_API_KEY
and paste in your key.
Then run this in a cell to make the API key available in the notebook:
from google.colab import userdata
OPENAI_API_KEY = userdata.get('OPENAI_API_KEY')
Step 2. Import the OpenAI library
We’ll start by importing the official Python library so we can talk to OpenAI easily.
from openai import OpenAI
Step 3. Set up your OpenAI client
This connects your notebook to OpenAI’s servers using your secret API key.
OPENAI_API_KEY = userdata.get('OPENAI_API_KEY')
client = OpenAI(api_key=OPENAI_API_KEY)
Step 4. Ask GPT for info — with web search
Here’s the really cool part.
We’ll use GPT-4.1-mini (a smaller but still smart model) and give it a web search preview tool, plus a rough location (Paris) so it can tailor results.
response = client.responses.create(
model="gpt-4.1-mini",
tools=[
{
"type": "web_search_preview",
"user_location": {
"type": "approximate",
"country": "FR",
"city": "Paris",
},
}
],
input="Give me some pizza places in the Bastille area",
)
Try changing that input to anything you like, e.g.
"What are the best coffee shops to work from in Lisbon?"
or"Upcoming tech events in Berlin?"
Step 5. Print the plain text result
GPT puts the final answer into response.output_text
.
Let’s print it out:
chatbot_response = response.output_text
print(chatbot_response)
Step 6. Show it as rich Markdown
If you are using Jupyter Notebook, Google Colab, or Deepnote, you can add another cell to view the output nicely formatted.
from IPython.display import Markdown
display(Markdown(chatbot_response))
Now your answer will look just like a little web page inside your notebook:
Quick note on pricing
We used gpt-4.1-mini
here, which is pretty affordable.
You can use the bigger models too — but note that the new web search tool is only available on the mini
and full
GPT models. The nano
models don’t support web search.
You can check out OpenAI’s pricing for built-in tools like this here:
https://platform.openai.com/docs/pricing#built-in-tools
Run or copy my Colab notebook here to try it yourself.
If you play with it, I’d love to hear what fun prompts you tried.
Reply to this email or comment on the post!
More soon,
— Ardit