Skip to main content
Deprecation notice: The web search API endpoint at /v1/tools/web-search is deprecated and will be removed on December 22, 2025.Migration path: Use the web search tool in chat completions to perform web searches during conversations. The web search tool provides the same search capabilities within a chat completion workflow. See the migration guide for detailed instructions.
The Web Search API allows you to search the web for information and get real-time results. This tool is useful for finding current information, news, and facts that may not be available in your model’s training data or in your Knowledge Graphs.
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

News search with time filtering

Best practices

  • Use specific queries: More specific queries tend to yield better results
  • Choose appropriate topic: Use news for current events and general for broader searches
  • Filter by domains: Use include_domains and exclude_domains to focus on reliable sources
  • Control search depth: Use basic for quick searches and advanced 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

Next steps

Learn about other tools and capabilities available in the Writer API: