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
Parameter | Type | Required | Description |
---|---|---|---|
query | string | Yes | The search query to execute |
topic | string | No | The search topic category. Use news for current events and news articles, or general for broader web search. Default: general |
search_depth | string | No | Controls search comprehensiveness. Use basic for fewer but highly relevant results, or advanced for deeper search with more results. Default: basic |
chunks_per_source | integer | No | Only applies when search_depth is advanced . Specifies how many text segments to extract from each source. Limited to 3 chunks maximum |
max_results | integer | No | Limits the number of search results returned. Cannot exceed 20 sources |
time_range | string | No | Filters results to content published within the specified time range. Options: day , week , month , year , d , w , m , y |
days | integer | No | For news topic searches, specifies how many days of news coverage to include |
include_raw_content | string | Boolean | No | Controls how raw content is included. Options: text , markdown , true (same as markdown), false (not included). Default: false |
include_answer | Boolean | No | Whether to include a generated answer to the query in the response. Default: true |
include_domains | array | No | Domains to include in the search |
exclude_domains | array | No | Domains to exclude from the search |
country | string | No | Localizes search results to a specific country. Only applies to general topic searches |
stream | Boolean | No | Enables streaming of search results as they become available. Default: false |
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.Parameter | Type | Description |
---|---|---|
query | string | The search query that was submitted |
answer | string | Generated answer based on the search results. null if include_answer is false |
sources | array | The search results found |
sources[].url | string | URL of the search result |
sources[].raw_content | string | Raw content from the source URL. null if include_raw_content is false |
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
news
for current events andgeneral
for broader searches - Filter by domains: Use
include_domains
andexclude_domains
to focus on reliable sources - Control search depth: Use
basic
for quick searches andadvanced
for comprehensive research - Set time ranges: Use
time_range
to get current information when needed - Limit results: Use
max_results
to control response size and processing time