You need an API key to access the Writer API. Get an API key by following the steps in the API quickstart.We recommend setting the API key as an environment variable in a
.env file with the name WRITER_API_KEY.Overview
The web search tool enables you to:- Search for current information and news
- Find factual information from reliable sources
- Get real-time data that may not be in your model’s training data
- Filter results by domain, time range, and geographic location
- Control search depth and result comprehensiveness
Request example
Request parameters
Response format
The response contains the search query, generated answer if requested, and an array of sources with their URLs and raw content if requested.Streaming response
When streaming is enabled, the response is delivered as Server-Sent Events (SSE). Each event contains a payload with the query, answer, and sources array. The response is delivered as a stream of events, and the client must listen for each event to receive the complete response. Learn more about streaming responses. Below is an example of a streaming response:Usage examples
General web search
News search with time filtering
Domain-specific search
Best practices
- Use specific queries: More specific queries tend to yield better results
- Choose appropriate topic: Use
newsfor current events andgeneralfor broader searches - Filter by domains: Use
include_domainsandexclude_domainsto focus on reliable sources - Control search depth: Use
basicfor quick searches andadvancedfor comprehensive research - Set time ranges: Use
time_rangeto get current information when needed - Limit results: Use
max_resultsto control response size and processing time