Skip to main content

Search News Monitor

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
  • Filter results by domain with search_domain_filter (allowlist or denylist)
  • Control recency with search_recency_filter (day, week, month, year)
  • Access structured result fields: title, url, snippet, date
  • 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 SDK reads it automatically:

Usage

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. Each search result contains title, url, snippet, and date fields, which are extracted and formatted.
  4. In watch mode, the tool repeats the search at a configurable interval, displaying only new results since the last poll.
Use the search_recency_filter parameter with values like "day", "week", "month", or "year" to focus on recent news. This is simpler than specifying exact date ranges and works well for monitoring workflows.
Domain filters operate in either allowlist or denylist mode, not both simultaneously. Use --domains for allowlist or --exclude-domains for denylist, but not both in the same request. A maximum of 20 domains can be specified.

Full Code

Example Output

The Search API returns structured results with title, url, snippet, and date fields. Unlike the Agent API or Sonar API, it does not generate AI summaries — it returns raw ranked web results. See the Search API quickstart for full details.

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.