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 asnews_monitor.py or news_monitor.ts.
How It Works
- The CLI accepts a list of topics and optional filtering parameters.
- For each topic, it calls
client.search.create(query=..., max_results=...)with the configured domain and recency filters. - The tool extracts
title,url,snippet,date, andlast_updatedfor JSON output. - 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
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
- Set appropriate intervals. For breaking news, use 60-120 second intervals. For general topic monitoring, 300-600 seconds is sufficient.
- Combine recency with domain filters. Use
--recency daywith trusted news domains for a curated news feed. - Pipe JSON output to other tools. Use
--jsonwith tools likejqor downstream scripts for alerting and aggregation. - 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_filteris relative to the current time and cannot specify exact date ranges. For precise date filtering, usesearch_after_date_filterandsearch_before_date_filterinstead. - Search result availability depends on web indexing. Very recent content (within minutes) may not appear immediately.
- The
snippetfield length varies by result and may be truncated for long pages.