If you ask the OpenAI system a question using the programmatic API, it will answer to the best of its ability using the information that the underlying LLM (GPT-4o, etc.) was trained on. But if you ask about recent events, the system won’t know the correct answer.
To deal with this possibility, I put together a demo where a question is submitted and if a good response is found, it’s displayed, but if a good answer isn’t found, a fallback Web search is used.
For my demo, I asked OpenAI about the score of a recent baseball game, one where it couldn’t know the result. The demo correctly switched over to a Web search and found the correct score.
Begin OpenAI standard + Web fallback demo The question is: What was the score of the Mariners baseball game that was played on September 3, 2025? Give only the score with the winning team listed first, like 'Mariners 5, Angels 2'. Do not add additional information. If you do not know the answer, respond with the text 'CODE 999' in your response. Web search result: Rays 9, Mariners 4 End demo
Behind the scenes, the initial response was:
Response(id='resp_066a72068fb91f920068c607672258819aa1e0ac8
da9a7e180', created_at=1757808487.0, error=None, incomplete
_details=None, instructions=None, metadata={}, model='gpt-
4.1-2025-04-14', object='response', output=[ResponseOutput
Message(id='msg_066a72068fb91f920068c60767a298819a8805697b6
dc4edec', content=[ResponseOutputText(annotations=[], text=
'CODE 999', type='output_text', logprobs=[])], role='assist
. . .
key=None, safety_identifier=None, store=True)
Notice the ‘CODE 999’ in the response. This was used to trigger a Web search. Also, notice that the GPT 4.1 model was built on April 14, 2025 and so it doesn’t know about a baseball game that was played on Sept. 3, 2025.
I set up an info dictionary to pass to the Responses API create() function:
info = {
"model": "gpt-4.1",
"tools": [],
"input": [
{ "role": "developer",
"content": "You use the Web only if necessary." },
{ "role": "user", "content": question },
],
"temperature": 0.3, # not creative. default top_p
"max_output_tokens": 100,
}
Then I passed this to create(), using the special Python ** syntax to unpack the dictionary keys to function arguments:
response = client.responses.create(**info) # Python unpack
if str(response).find("CODE 999") >= 0:
# could not answer so try Web search
info["tools"] = [{"type": "web_search_preview"}]
response = client.responses.create(**info)
print("\nWeb search result: ")
print(response.output_text)
else: # got a result
print("\nStandard (no Web) result: ")
print(response.output_text)
If the 999 code is in the initial response, I add the “web_search_preview” tool and fire off a second request.
There are a ton of things that need to be investigated further. I think I can remove the “add CODE 999” from the question/context and place it in the “instructions” parameter of the response.create() method and then check str(response.output_text) instead of str(response). And there is a reasoning effort parameter I haven’t looked at yet.
In short, there are many OpenAI API features that might enhance this demo. The situation reminds me a lot of the time when I was first learning the PyTorch code library — there were literally hundreds of details to learn about, and the only way for me to learn them was by creating one demo example at a time.
An interesting experiment.

It seems clear that the rise of AI is going to dramatically change the world in unexpected ways. For fun, I sometimes look at old Popular Science magazine covers to see what some of the predictions were. On the left is the cover of the June 1933 issue, which speculated about a huge flying wing design bomber aircraft, with enclosed engines. Just 55 years later, in 1998, the Northrup B-2 Spirit stealth bomber flew over the U.S. — absolutely incredible.
Demo program:
# web_enhanced_search_openai.py
# regular response with Web search fallback
from openai import OpenAI
print("\nBegin OpenAI standard + Web fallback demo ")
try:
key = "sk-proj-_AX7bGTXUwg-qojh2T5Z2CVXrox" + \
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + \
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + \
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
client = OpenAI(api_key=key)
question = "What was the score of the Mariners" + \
" baseball game that was played on September 3," + \
" 2025? Give only the score with the winning" + \
" team listed first, like 'Mariners 5, Angels 2'." + \
" Do not add additional information." + \
" If you do not know the answer, respond" + \
" with the text 'CODE 999' in your response."
print("\nThe question is: ")
print(question)
info = {
"model": "gpt-4.1",
"tools": [],
"input": [
{ "role": "developer",
"content": "You use the Web only if necessary." },
{ "role": "user", "content": question },
],
"temperature": 0.3, # not creative. default top_p
"max_output_tokens": 100,
}
response = client.responses.create(**info) # Python unpack
if str(response).find("CODE 999") >= 0:
# could not answer so try Web search
info["tools"] = [{"type": "web_search_preview"}]
response = client.responses.create(**info)
print("\nWeb search result: ")
print(response.output_text)
else: # got a result
print("\nStandard (no Web) result: ")
print(response.output_text)
except Exception as e:
print("Fatal error " + str(e))
print("\nEnd demo ")

.NET Test Automation Recipes
Software Testing
SciPy Programming Succinctly
Keras Succinctly
R Programming
2026 Visual Studio Live
2025 Summer MLADS Conference
2025 DevIntersection Conference
2025 Machine Learning Week
2025 Ai4 Conference
2025 G2E Conference
2025 iSC West Conference
You must be logged in to post a comment.