Help us improve
Share bugs, ideas, or general feedback.
From perplexity-pack
Generates minimal Perplexity Sonar search examples with citations in TypeScript and Python for new integrations, setup testing, or basic patterns.
npx claudepluginhub jeremylongshore/claude-code-plugins-plus-skills --plugin perplexity-packHow this skill is triggered — by the user, by Claude, or both
Slash command
/perplexity-pack:perplexity-hello-worldThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Minimal working example demonstrating Perplexity's core value: web-grounded answers with citations. Unlike standard LLMs, Perplexity searches the web for every query and returns cited sources.
Implements Perplexity Sonar API patterns in TypeScript and Python using OpenAI client wrappers for typed singletons, search with citations, and response parsing.
Performs AI-powered web searches with real-time, source-cited answers using Perplexity models via LiteLLM and OpenRouter. Use for current information, recent scientific literature, or facts beyond model training cutoff.
Generates runnable TypeScript examples for Exa API: basic search, search with contents/highlights/summary, find similar pages, and get contents for URLs.
Share bugs, ideas, or general feedback.
Minimal working example demonstrating Perplexity's core value: web-grounded answers with citations. Unlike standard LLMs, Perplexity searches the web for every query and returns cited sources.
perplexity-install-auth setupopenai package installedPERPLEXITY_API_KEY environment variable setimport OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.PERPLEXITY_API_KEY,
baseURL: "https://api.perplexity.ai",
});
async function main() {
const response = await client.chat.completions.create({
model: "sonar",
messages: [
{
role: "system",
content: "Be precise and cite your sources.",
},
{
role: "user",
content: "What are the latest features in Node.js 22?",
},
],
});
const answer = response.choices[0].message.content;
console.log("Answer:", answer);
// Citations are returned as a top-level array on the response
const citations = (response as any).citations || [];
console.log("\nSources:");
citations.forEach((url: string, i: number) => {
console.log(` [${i + 1}] ${url}`);
});
// Usage breakdown
console.log("\nUsage:", {
prompt_tokens: response.usage?.prompt_tokens,
completion_tokens: response.usage?.completion_tokens,
total_tokens: response.usage?.total_tokens,
});
}
main().catch(console.error);
import os
from openai import OpenAI
client = OpenAI(
api_key=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 cite your sources."},
{"role": "user", "content": "What are the latest features in Node.js 22?"},
],
)
answer = response.choices[0].message.content
print("Answer:", answer)
# Citations from the raw response
raw = response.model_dump()
citations = raw.get("citations", [])
print("\nSources:")
for i, url in enumerate(citations, 1):
print(f" [{i}] {url}")
print(f"\nTokens: {response.usage.total_tokens}")
// Restrict search to specific domains
const response = await client.chat.completions.create({
model: "sonar",
messages: [
{ role: "user", content: "What is the latest Python release?" },
],
// Perplexity-specific parameters (pass as extra body)
search_domain_filter: ["python.org", "docs.python.org"],
search_recency_filter: "month",
} as any);
const stream = await client.chat.completions.create({
model: "sonar",
messages: [
{ role: "user", content: "Explain quantum computing breakthroughs in 2025" },
],
stream: true,
});
for await (const chunk of stream) {
const text = chunk.choices[0]?.delta?.content || "";
process.stdout.write(text);
// Citations arrive in the final chunk
if ((chunk as any).citations) {
console.log("\n\nSources:", (chunk as any).citations);
}
}
| Error | Cause | Solution |
|---|---|---|
401 Unauthorized | Invalid API key | Verify key at perplexity.ai/settings/api |
| Empty citations array | Query too abstract | Ask a specific, factual question |
429 Too Many Requests | Rate limit exceeded | Wait and retry with backoff |
| Timeout | Complex search query | Use sonar instead of sonar-pro |
Proceed to perplexity-local-dev-loop for development workflow setup.