perplexity-api
Perplexity API for real-time web-search-augmented LLM responses. Use when you need up-to-date information in AI responses, research assistants, fact-checking, current events coverage, or any task requiring knowledge beyond an LLM's training cutoff. Returns cited sources alongside answers.
What this skill does
# Perplexity API
## Overview
Perplexity AI provides LLM inference augmented with real-time web search. Unlike standard LLMs limited to training data, Perplexity's online models fetch and synthesize current web information on every query. Responses include citations to source URLs. The API is fully OpenAI-compatible — use the `openai` SDK with a custom `base_url`.
## Setup
```bash
pip install openai # Perplexity uses OpenAI-compatible API
```
```bash
export PERPLEXITY_API_KEY=pplx-...
```
## Available Models
| Model | Type | Best For |
|---|---|---|
| `sonar` | Online | Fast web-augmented answers |
| `sonar-pro` | Online | Deep research, complex queries |
| `sonar-reasoning` | Online | Step-by-step reasoning + search |
| `sonar-reasoning-pro` | Online | Advanced reasoning + deep search |
| `r1-1776` | Offline | No search, uncensored reasoning |
**Online models** search the web on every request. **Offline models** use only training data.
## Instructions
### Basic Query with Web Search
```python
from openai import OpenAI
client = OpenAI(
api_key="pplx-...", # or os.environ["PERPLEXITY_API_KEY"]
base_url="https://api.perplexity.ai",
)
response = client.chat.completions.create(
model="sonar",
messages=[
{
"role": "system",
"content": "Be precise and concise. Always cite your sources.",
},
{
"role": "user",
"content": "What are the latest developments in quantum computing as of today?",
},
],
)
print(response.choices[0].message.content)
```
### Accessing Citations
```python
from openai import OpenAI
client = OpenAI(
api_key="pplx-...",
base_url="https://api.perplexity.ai",
)
response = client.chat.completions.create(
model="sonar-pro",
messages=[{"role": "user", "content": "What is the current price of Bitcoin?"}],
)
# Main answer
print(response.choices[0].message.content)
# Citations are in the extra_fields / model_extra
if hasattr(response, "citations"):
for i, citation in enumerate(response.citations, 1):
print(f"[{i}] {citation}")
# Or access via model_extra
citations = getattr(response, "citations", [])
for url in citations:
print(f"Source: {url}")
```
### Streaming with Citations
```python
from openai import OpenAI
client = OpenAI(
api_key="pplx-...",
base_url="https://api.perplexity.ai",
)
stream = client.chat.completions.create(
model="sonar",
messages=[{"role": "user", "content": "Summarize the top tech news today."}],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
print()
```
### Deep Research with sonar-pro
```python
from openai import OpenAI
client = OpenAI(
api_key="pplx-...",
base_url="https://api.perplexity.ai",
)
# sonar-pro performs more web searches for comprehensive answers
response = client.chat.completions.create(
model="sonar-pro",
messages=[
{
"role": "system",
"content": "You are a research analyst. Provide detailed, well-sourced analysis.",
},
{
"role": "user",
"content": (
"Provide a comprehensive analysis of the current state of "
"AI regulation globally, including recent legislation and upcoming proposals."
),
},
],
max_tokens=2000,
)
print(response.choices[0].message.content)
```
### Reasoning with sonar-reasoning
```python
from openai import OpenAI
client = OpenAI(
api_key="pplx-...",
base_url="https://api.perplexity.ai",
)
# sonar-reasoning shows chain-of-thought + searches web
response = client.chat.completions.create(
model="sonar-reasoning",
messages=[
{
"role": "user",
"content": (
"Based on current market data, should I invest in NVIDIA or AMD stock? "
"Consider recent earnings and market trends."
),
}
],
)
print(response.choices[0].message.content)
# Response includes <think> blocks with reasoning process
```
### Multi-Turn Research Session
```python
from openai import OpenAI
client = OpenAI(
api_key="pplx-...",
base_url="https://api.perplexity.ai",
)
messages = [
{
"role": "system",
"content": "You are a research assistant with access to current web information. "
"Always cite sources and indicate when information may be time-sensitive.",
}
]
def research_chat(user_message: str) -> str:
messages.append({"role": "user", "content": user_message})
response = client.chat.completions.create(
model="sonar-pro",
messages=messages,
)
answer = response.choices[0].message.content
messages.append({"role": "assistant", "content": answer})
return answer
# Multi-turn research
print(research_chat("What are the main AI labs releasing models in 2025?"))
print(research_chat("Which of those models are available via API right now?"))
print(research_chat("Compare their pricing per million tokens."))
```
### Rate Limiting & Error Handling
```python
from openai import OpenAI, RateLimitError
import time
client = OpenAI(
api_key="pplx-...",
base_url="https://api.perplexity.ai",
)
def search_with_retry(query: str, retries: int = 3) -> str:
for attempt in range(retries):
try:
response = client.chat.completions.create(
model="sonar",
messages=[{"role": "user", "content": query}],
timeout=30,
)
return response.choices[0].message.content
except RateLimitError:
wait = 2 ** attempt
print(f"Rate limited. Retrying in {wait}s...")
time.sleep(wait)
raise Exception("Max retries exceeded")
```
## Online vs Offline Models
| Feature | Online (sonar*) | Offline (r1-1776) |
|---|---|---|
| Web search | ✅ Real-time | ❌ Training data only |
| Citations | ✅ URL sources | ❌ Not applicable |
| Current events | ✅ Up to today | ❌ Training cutoff |
| Latency | Higher (~2–5s) | Lower (~0.5s) |
| Cost | Higher | Lower |
Use **online models** when freshness matters. Use **offline models** for tasks that don't need current data (reasoning, creative writing, code).
## Guidelines
- Online models search the web on every request — expect 2–5 second latency.
- Citations appear in the `response.citations` list (URLs).
- `sonar` is fastest for simple lookups; `sonar-pro` does multiple searches for complex topics.
- Perplexity's search is English-centric but supports other languages.
- For real-time price data or stock quotes, combine Perplexity with direct API calls for accuracy.
- The system prompt cannot disable web search for online models — use offline models if you need pure LLM responses.
- Token costs include search overhead — budget accordingly for high-volume use.
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.