perplexity
π―SkillInstallation
npx skills add g1joshi/agent-skills --skill perplexityRun it in a terminal; it asks which AI coding tools to install it for (Claude Code, Codex, Cursor and more).
Uses skills.sh Β· Node.js 22.20+
After installing
Ask for related work and the agent uses it on its own, or call it yourself.
/perplexityInstall by hand
Copy the whole skill folder from GitHub to the place below. Copying only SKILL.md can leave out files the skill uses.
Open the skill folder β- This project
.claude/skills/perplexity/ - All projects
~/.claude/skills/perplexity/
These paths are for Claude Code. For other tools, the command above puts it in the right place.
SKILL.md
View on GitHub βExpert Perplexity AI API assistance covering sonar online models, search grounding, citations, and real-time web retrieval. Use when building search-augmented AI research and current event query pipelines.
Perplexity
Perplexity is an AI search engine. For developers, the Sonar API provides grounded, cited answers for building search-enabled apps.
When to Use
- Real-Time Web-Augmented Search & Retrieval: Querying fresh, live web data with grounded, verifiable source citations.
- Fact-Checking & Research Automation: Generating comprehensive answers with linked URLs for financial, legal, and tech intelligence.
- Perplexity Sonar Models via API: Accessing
sonar-pro,sonar, and reasoning models for production AI assistants. - Recency-Filtered Search: Restricting search scope to the last day, week, or month for breaking developments.
Quick Start
from openai import OpenAI
# Perplexity uses OpenAI-compatible API format
client = OpenAI(
api_key="your-perplexity-api-key",
base_url="https://api.perplexity.ai"
)
response = client.chat.completions.create(
model="sonar-pro",
messages=[
{"role": "user", "content": "What were the major tech announcements this week?"}
]
)
print(response.choices[0].message.content)
Core Concepts
Consuming Perplexity Sonar API with Citations
Querying live web search intelligence using OpenAI-compatible SDK:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("PERPLEXITY_API_KEY"),
base_url="https://api.perplexity.ai"
)
response = client.chat.completions.create(
model="sonar-pro",
messages=[
{"role": "system", "content": "You are a research analyst. Provide factual answers with explicit citations."},
{"role": "user", "content": "What are the latest developments in quantum computing error correction in 2026?"}
],
temperature=0.2,
)
answer = response.choices[0].message.content
citations = getattr(response, 'citations', [])
print("Answer:\n", answer)
print("\nSources / Citations:")
for i, url in enumerate(citations, 1):
print(f"[{i}] {url}")
Search Domain & Recency Filtering
Restricting search context to authoritative domains and specific timeframes:
import requests
import json
url = "https://api.perplexity.ai/chat/completions"
headers = {
"Authorization": f"Bearer {os.environ.get('PERPLEXITY_API_KEY')}",
"Content-Type": "application/json"
}
payload = {
"model": "sonar",
"messages": [
{"role": "user", "content": "What were the key policy changes announced by the central bank this week?"}
],
"search_domain_filter": ["bloomberg.com", "reuters.com", "ft.com"],
"search_recency_filter": "week" # "day", "week", "month", "year"
}
res = requests.post(url, json=payload, headers=headers)
data = res.json()
print(data['choices'][0]['message']['content'])
Structured Output Formatting with Sonar
Directing the model to output verified markdown data tables:
response = client.chat.completions.create(
model="sonar",
messages=[
{"role": "user", "content": "Compare the top 3 open-source vector databases by license, GitHub stars, and vector indexing algorithm. Output as a Markdown table."}
],
temperature=0.1
)
print(response.choices[0].message.content)
Common Patterns
Domain-Restricted Search Grounding
Problem: Retrieval results include low-quality blogs or outdated forum answers.
Solution:
Filter search sources using search_domain_filter:
response = client.chat.completions.create(
model="sonar",
messages=[{"role": "user", "content": "What is the latest RFC standard for HTTP/3?"}],
extra_body={
"search_domain_filter": ["ietf.org", "mozilla.org", "w3.org"],
"return_citations": True
}
)
print("Answer:", response.choices[0].message.content)
# Access citation URLs if enabled
citations = getattr(response, "citations", [])
print("Citations:", citations)
Best Practices
Do:
- Target
sonar-profor deep analytical research andsonarfor fast, lightweight web queries. - Inspect and parse the
citationsarray to display clickable references in user-facing interfaces. - Apply
search_recency_filterwhen querying time-sensitive or breaking news topics. - Use
search_domain_filterto limit search to trusted corporate, scientific, or government websites.
Don't:
- Use high temperature settings (> 0.3) if exact factual precision and strict web grounding are desired.
- Assume web search is necessary for closed-domain math or pure coding tasks; standard LLMs are faster and cheaper.
- Hardcode
PERPLEXITY_API_KEYin scripts; load securely from environment variables.
Troubleshooting
| Error | Cause | Solution |
|---|---|---|
401 Unauthorized | Invalid or expired Perplexity API key. | Verify API key in Perplexity settings and set PPLX_API_KEY. |
Model not supported: ... | Using deprecated model tag (e.g. llama-3-sonar-8b). | Use active sonar models: sonar or sonar-pro. |
Base URL missing in client | Connecting to default api.openai.com instead of api.perplexity.ai. | Specify base_url="https://api.perplexity.ai". |
References
More from this repository10
A template skill providing a starter framework for creating new agent skills with structured sections for triggers, quick start examples, and capability descriptions.
Skill
Skill
Skill
Skill
Skill
Skill
Skill
Skill
Skill