Web Search
Web search allows LLMs to access real-time information from the internet during inference. This enables the model to provide up-to-date answers based on current information rather than relying solely on its training data.
Overview
To enable web search in your LLM requests, you need to:
- Initialize a client with API key authentication
- Add
web_search: trueto theextra_bodyparameter in your chat completion request - The model will automatically search the web and incorporate relevant information into its response
Basic Usage
- Python
- TypeScript
examples/7-web-search.py
loading...
examples/3-web-search.ts
loading...
How It Works
When web search is enabled:
- The model analyzes your query to determine if web search would be beneficial
- If needed, it formulates search queries and retrieves relevant information from the web
- The retrieved information is incorporated into the model's context
- The model generates a response that combines its knowledge with the web-sourced information
Use Cases
Web search is particularly useful for:
- Current events: Getting the latest news and updates
- Real-time data: Accessing current prices, statistics, or live information
- Recent developments: Information about topics that have evolved since the model's training cutoff
- Fact verification: Cross-referencing information with current sources
- Dynamic content: Queries that require up-to-date information
Important Notes
- Web search adds latency to requests as the model needs to fetch and process external information
- The quality of responses depends on the relevance and accuracy of web sources found
- Not all queries will trigger a web search - the model determines when it's necessary
- Web search works with both API key and delegation token authentication flows