Loading learning content…
Loading learning content…
Use the Perplexity API to build automated research pipelines — market monitoring, report generation, and intelligence feeds.
Read through the lesson, mark it complete when the concept is clear, then move to the next lesson in the sequence or jump back to the module map.
The Perplexity API lets you programmatically query Perplexity's models, enabling:
The API uses OpenAI-compatible format, making integration straightforward.
import requests
response = requests.post(
"https://api.perplexity.ai/chat/completions",
headers={"Authorization": f"Bearer {PERPLEXITY_API_KEY}"},
json={
"model": "llama-3.1-sonar-large-128k-online",
"messages": [
{"role": "user", "content": "What are the latest developments in enterprise AI governance?"}
],
"search_recency_filter": "week",
"return_citations": True
}
)
result = response.json()
answer = result["choices"][0]["message"]["content"]
citations = result["citations"]
| Model | Use Case |
|---|---|
| sonar | Fast, lightweight searches |
| sonar-pro | Deep research, complex queries |
| sonar-reasoning | Multi-step reasoning with citations |
topics = [
"AI governance regulatory updates",
"Enterprise AI adoption trends",
"Key competitor product launches"
]
report = []
for topic in topics:
response = query_perplexity(topic, recency="week")
report.append({"topic": topic, "findings": response})
send_weekly_brief(report)
The search_recency_filter parameter controls how fresh sources must be:
For competitive intelligence, "week" balances freshness with coverage.
The API charges per token. Budget $50–200/month for a moderate automation pipeline. Use caching aggressively — many research queries repeat with minor variations.