Skip to main content
A command-line tool that uses Perplexity’s Search API (client.search.create(...)) to monitor real-time news across multiple topics. Configure topics, domain filters, and recency windows to build a continuous news monitoring pipeline.

Features

  • Monitor multiple topics in a single run using the Search API
  • Include or exclude domains in the same request with search_domain_filter
  • Control recency with search_recency_filter (hour, day, week, month, year)
  • Access structured result fields: title, url, snippet, date, last_updated
  • Configurable polling interval for continuous monitoring
  • Output as formatted text or JSON for downstream processing

Installation

API Key Setup

Set your Perplexity API key as an environment variable. The Perplexity Python library and the TypeScript SDK read it automatically:

Usage

Save the Python or TypeScript code below as news_monitor.py or news_monitor.ts.

How It Works

  1. The CLI accepts a list of topics and optional filtering parameters.
  2. For each topic, it calls client.search.create(query=..., max_results=...) with the configured domain and recency filters.
  3. The tool extracts title, url, snippet, date, and last_updated for JSON output.
  4. In watch mode, the tool repeats the search at a configurable interval, displaying only new results since the last poll.
--recency sets search_recency_filter to hour, day, week, month, or year. Pass --domains to include domains, --exclude-domains to exclude them, or both. Both scripts send one search_domain_filter array with include entries first and --prefixed exclude entries after them.

Full Code

The Python and TypeScript tabs contain the full monitor. The cURL tab shows a single request with the same topic and domain filters as the combined CLI example above.

Example Output

Excerpt from a run on November 19, 2026, showing two of the five results for each topic. Snippets keep the line breaks from the extracted page text.
The Search API returns ranked web results with title, url, snippet, date, and last_updated, and omits date when the publication date is unknown. Unlike the Agent API, the Search API does not generate summaries. See the Search API reference for every parameter.

Continuous Monitoring Tips

  1. Set appropriate intervals. For breaking news, use 60-120 second intervals. For general topic monitoring, 300-600 seconds is sufficient.
  2. Combine recency with domain filters. Use --recency day with trusted news domains for a curated news feed.
  3. Pipe JSON output to other tools. Use --json with tools like jq or downstream scripts for alerting and aggregation.
  4. Track seen URLs. The watch mode automatically deduplicates results across polling cycles using URL tracking.

Limitations

  • The Search API charges per request. Frequent polling across many topics will increase costs.
  • The search_recency_filter is relative to the current time and cannot specify exact date ranges. For precise date filtering, use search_after_date_filter and search_before_date_filter instead.
  • Search result availability depends on web indexing. Very recent content (within minutes) may not appear immediately.
  • The snippet field length varies by result and may be truncated for long pages.