Control and customize Sonar API search results with filters
Control which websites appear in search results, filter by date and location, target specific languages, and fine-tune search behavior using Sonar API filters.
Control which websites are included or excluded from search results using search_domain_filter. Supports both domain-level and URL-level filtering.Key parameters:
search_domain_filter: Array of domains or URLs (max 20)
Allowlist mode: Include only specified domains (no prefix)
Denylist mode: Exclude domains (prefix with -)
Copy
Ask AI
from perplexity import Perplexityclient = Perplexity()# Allowlist: Only search specific domainscompletion = client.chat.completions.create( model="sonar", messages=[{"role": "user", "content": "Tell me about space discoveries."}], search_domain_filter=["nasa.gov", "wikipedia.org", "space.com"])# Denylist: Exclude specific domainscompletion = client.chat.completions.create( model="sonar", messages=[{"role": "user", "content": "What are renewable energy advances?"}], search_domain_filter=["-reddit.com", "-pinterest.com"])
You can add a maximum of 20 domains or URLs. Use either allowlist OR denylist mode, not both simultaneously.
Filter search results by language using ISO 639-1 language codes.Key parameters:
search_language_filter: Array of 2-letter language codes (max 10)
Copy
Ask AI
from perplexity import Perplexityclient = Perplexity()# Single languagecompletion = client.chat.completions.create( model="sonar", messages=[{"role": "user", "content": "Tell me about AI developments."}], search_language_filter=["en"])# Multiple languagescompletion = client.chat.completions.create( model="sonar-pro", messages=[{"role": "user", "content": "Renewable energy in Europe?"}], search_language_filter=["en", "fr", "de"])
Language codes must be valid ISO 639-1 codes (e.g., "en", "fr", "de"). You can filter by up to 10 languages per request.
Prioritize scholarly sources and peer-reviewed content by setting search_mode to "academic".Key parameters:
search_mode: Set to "academic" to target academic sources
Copy
Ask AI
from perplexity import Perplexityclient = Perplexity()completion = client.chat.completions.create( model="sonar-pro", messages=[{"role": "user", "content": "What is the scientific name of lion's mane mushroom?"}], search_mode="academic", web_search_options={"search_context_size": "low"})# Combine with date filters for recent researchcompletion = client.chat.completions.create( model="sonar", messages=[{"role": "user", "content": "Latest findings on neural networks?"}], search_mode="academic", search_after_date_filter="1/1/2023")
Target U.S. Securities and Exchange Commission filings and official financial documents.Key parameters:
search_mode: Set to "sec" to target SEC filings
Copy
Ask AI
from perplexity import Perplexityclient = Perplexity()completion = client.chat.completions.create( model="sonar-pro", messages=[{"role": "user", "content": "Prepare me for markets opening."}], search_mode="sec")# Combine with date filters for recent filingscompletion = client.chat.completions.create( model="sonar", messages=[{"role": "user", "content": "Summarize latest 10-K filings for Apple Inc."}], search_mode="sec", search_after_date_filter="1/1/2023")