Join the 12‑Week Cohort
Profile
V3 AI
Hands-On with OpenAI's GPT-4.1 Web Search: Building HUNTER
ProjectApril 15, 2025

Hands-On with OpenAI's GPT-4.1 Web Search: Building HUNTER

Here's what I learned about these new search tools and how they change what's possible for AI applications.

Hands-On with OpenAI's GPT-4.1 Web Search: Building HUNTER. 🎯

OpenAI just dropped GPT-4.1 with built-in web search capabilities, and I've been testing it with a new open-source project called HUNTER. Here's what I learned about these new search tools and how they change what's possible for AI applications.

Why Web Search Changes Everything

____TAVILY - SERPAPI - SEARXNG - OH MY!!! _____

Until now, building AI systems that needed current information meant cobbling together third-party search APIs with LLMs. OpenAI's native web search integration changes the game by:

  1. Providing current information directly through the model
  2. Including proper citations and references
  3. Allowing seamless integration of search results within the context window

This fundamentally shifts what AI tools can do without complex integrations.

Meet HUNTER: A Test Case for GPT-4.1's Search

Ive been perpetually building this app----It's a sales intelligence system that gathers and synthesizes information about prospects and their companies.

The core functionality is straightforward:

  • Upload a CSV of prospects with their company info
  • HUNTER scrapes their websites and uses GPT-4.1 to search for additional context
  • The system synthesizes this information into comprehensive profiles

What's interesting is how much more capable this becomes with GPT-4.1's native search compared to previous approaches.

The Basics: How It Works Now

The GPT-4.1 web search integration lets you make real-time web searches directly through the API:

from langchain_openai import ChatOpenAI

search_llm = ChatOpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),
    model="gpt-4.1"
)
search_tool = search_llm.bind_tools([{"type": "web_search_preview"}])
response = search_tool.invoke("Search for information about: Acme Corp")

Behind the scenes, OpenAI:

  1. Takes your query
  2. Generates search terms
  3. Fetches results from search engines
  4. Embeds the results in the model's context
  5. Generates a response with citations

Web Search Implementation: In my Hunter APP -

The implementation of web search in the GPT-4.1 model is surprisingly straightforward:

from langchain_openai import ChatOpenAI

# Initialize OpenAI ChatModel with web search
search_llm = ChatOpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),
    model="gpt-4.1"
)
# Bind the web search tool
search_tool = search_llm.bind_tools([{"type": "web_search_preview"}])

# Use it for queries
response = search_tool.invoke("Search for information about: Specific company details")

This simplicity masks some powerful capabilities:

  1. Citation Handling: GPT-4.1 properly maintains source attributions
  2. Content Extraction: The model extracts relevant information rather than just returning raw search results
  3. Synthesis: Results are coherently woven into responses rather than tacked on

Real-World Testing: Search Accuracy

Testing with several hundred companies through HUNTER, I've found GPT-4.1's search provides notably accurate information:

  • Company descriptions match current websites
  • Leadership changes are correctly identified
  • Recent press releases and news are incorporated
  • Industry classifications are more precise

Since its a good model - I can index on the system prompt/user prompt using XML delimiters <<>> to really strengthen guardrails sections - so if I dont have a lot of info - Ive prompted the AI to not hallucinate and just do what it can with what it has -

Key Challenges and Solutions

Working with the new search capabilities isn't without challenges:

Content Truncation. 🏄‍♂️

Challenge: The search results are length-limited, sometimes cutting off important information.

Solution: HUNTER implements a custom content extraction approach that:

  • Captures the beginning of each search result
  • Preserves the ending for conclusion statements
  • Identifies when a company name appears in the middle of content to retain those sections

This gives a more comprehensive view when information is spread across long results.

Search Query Formulation

Challenge: The quality of results depends heavily on search query construction.

Solution: Instead of single generic searches, HUNTER uses a staged approach:

  1. Initial search to identify basic company information
  2. Follow-up searches targeting specific aspects based on initial findings
  3. Final searches to fill information gaps

This produces more comprehensive results than single-pass searching.

Architectural Approach for GPT-4.1 Web Search

HUNTER uses a Streamlit interface on top of a LangGraph workflow that coordinates:

Data Ingestion → Query Formulation → Web Search →
Information Synthesis → Profile Generation

The system is built entirely in Python with:

  • Streamlit for UI
  • LangGraph for orchestration
  • OpenAI's GPT-4.1 for search and analysis
  • Asyncio for parallel processing

Key Takeaways for Developers

After building with GPT-4.1's web search capabilities, here are the key insights:

  1. Query formulation matters: How you structure search queries dramatically affects result quality

  2. Multi-turn searches yield better results: Using initial search results to inform follow-up queries creates more comprehensive outputs

  3. Processing search results requires care: Handling content truncation and preserving context is critical

  4. Caching is essential: Implement robust caching to avoid redundant searches and reduce costs

Try It Yourself

HUNTER is open source and available on GitHub if you want to explore GPT-4.1's web search capabilities yourself:

git clone https://github.com/williavs/hunter-2.git
cd hunter-2
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

Add your OpenAI key to a .env file:

OPENAI_API_KEY=your_openai_api_key

Run the app:

streamlit run streamlit_app.py

The addition of web search to GPT-4.1 opens up possibilities that were previously complex to implement, and I'm just scratching the surface of what's possible.

-Willy Out. 🏄‍♂️

gpt-4.1ai codingweb_search_tool
Back to Blog