Web Search

Pattern
Web Search Tool
Search the web using OpenAI's tool with real-time results. Includes source verification, citation tracking, and contextual answers.
BeginnerOct 2025View the full pattern on desktop


Problems solved
- Force OpenAI web_search_preview on every query
- Return AI-synthesized answers grounded in web search
- Configure search context size and optional user location
Use cases
- Web search answer boxes
- Research lookup tools
- Local-aware search demos
- OpenAI web search integration samples
AI SDK APIs
generateTexttools:
Tags
aiwebsearchopenai
Requirements
- Node.js
- >=18.0.0
Environment variables
OPENAI_API_KEYGet key
External services
openai
Ready to use?
View the full interactive pattern with live preview and copy the source code.
View the pattern on desktop






