perplexity-sdk-patterns

Featured

Apply production-ready Perplexity Sonar API patterns for TypeScript and Python. Use when implementing Perplexity integrations, refactoring SDK usage, or establishing team coding standards for search-augmented generation. Trigger with phrases like "perplexity SDK patterns", "perplexity best practices", "perplexity code patterns", "idiomatic perplexity", "perplexity wrapper".

AI & Automation 2,940 stars 439 forks Updated today MIT

Install

View on GitHub

Quality Score: 99/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Perplexity SDK Patterns ## Overview Production-ready patterns for Perplexity Sonar API. Since Perplexity uses the OpenAI wire format, you build wrappers around the `openai` client library with Perplexity-specific response handling (citations, search results, related questions). ## Prerequisites - `openai` package installed (`npm install openai` or `pip install openai`) - API key configured in `PERPLEXITY_API_KEY` - Understanding of OpenAI chat completions format ## Instructions ### Step 1: Typed Client Singleton (TypeScript) ```typescript // src/perplexity/client.ts import OpenAI from "openai"; export interface PerplexityChatCompletion extends OpenAI.ChatCompletion { citations?: string[]; search_results?: Array<{ title: string; url: string; date?: string; snippet: string; }>; related_questions?: string[]; } export interface PerplexityUsage extends OpenAI.CompletionUsage { citation_tokens?: number; num_search_queries?: number; reasoning_tokens?: number; } let instance: OpenAI | null = null; export function getClient(): OpenAI { if (!instance) { if (!process.env.PERPLEXITY_API_KEY) { throw new Error("PERPLEXITY_API_KEY not set"); } instance = new OpenAI({ apiKey: process.env.PERPLEXITY_API_KEY, baseURL: "https://api.perplexity.ai", }); } return instance; } ``` ### Step 2: Search with Full Response Parsing ```typescript // src/perplexity/search.ts import { getClient, PerplexityChatCompletion } from ...

Details

Author
jeremylongshore
Repository
jeremylongshore/claude-code-plugins-plus-skills
Created
1 years ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category