Perplexity API Build AI applications with real-time web search and grounded responses. Quick Navigation - Models & pricing: - Search API patterns: - Chat completions guide: - Browser sessions API: - Embeddings API: - Structured outputs: - Filters (domain/language/date/location): - Media (images/videos/attachments): - Pro Search: - Prompting best practices: When to Use - Need AI responses grounded in current web data - Building search-powered applications - Research tools requiring citations - Real-time Q&A with source verification - Document/image analysis with web context Installation Instal…

, code))\n\n# Must be lowercase: \"en\" not \"EN\"\n# Maximum: 10 language codes per request\n```\n\n## Date/Time Filtering\n\n### Recency Filter (Simple)\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar\",\n messages=[{\"role\": \"user\", \"content\": \"AI news\"}],\n search_recency_filter=\"week\" # day, week, month, year\n)\n```\n\n### Date Range Filtering (Precise)\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar\",\n messages=[{\"role\": \"user\", \"content\": \"climate research\"}],\n search_after_date_filter=\"01/01/2024\", # Format: %m/%d/%Y\n search_before_date_filter=\"12/31/2024\"\n)\n```\n\n### Last Updated Filters\n\n```python\n# Filter by when content was last updated (not published)\ncompletion = client.chat.completions.create(\n model=\"sonar\",\n messages=[{\"role\": \"user\", \"content\": \"API documentation\"}],\n last_updated_after_filter=\"01/01/2024\",\n last_updated_before_filter=\"06/30/2024\"\n)\n```\n\n## User Location Filtering\n\nRefine results by geographic context.\n\n### Full Location (Recommended)\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"coffee shops nearby\"}],\n web_search_options={\n \"user_location\": {\n \"country\": \"US\",\n \"region\": \"California\",\n \"city\": \"San Francisco\",\n \"latitude\": 37.7749,\n \"longitude\": -122.4194\n }\n }\n)\n```\n\n### Country Only\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"political news\"}],\n web_search_options={\n \"user_location\": {\"country\": \"US\"}\n }\n)\n```\n\n### Location Rules\n\n- `latitude`/`longitude` REQUIRE `country` parameter\n- ISO 3166-1 alpha-2 country codes (US, GB, DE)\n- `city` and `region` significantly improve accuracy\n- Latitude: -90 to 90; Longitude: -180 to 180\n\n## Search Context Size\n\nControl how much web content is retrieved.\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar\",\n messages=[{\"role\": \"user\", \"content\": \"simple fact question\"}],\n web_search_options={\"search_context_size\": \"low\"} # low, medium, high\n)\n```\n\n| Size | Cost | Best For |\n| ------ | ------- | --------------------------------- |\n| low | Lowest | Simple facts, cost-critical |\n| medium | Default | General queries |\n| high | Highest | Deep research, citations critical |\n\n## Search Modes\n\n### Academic Mode\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"neural network research\"}],\n search_mode=\"academic\" # Prioritizes scholarly sources\n)\n```\n\n### SEC Filings Mode\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"Apple 10-K filing\"}],\n search_mode=\"sec\" # Prioritizes SEC EDGAR database\n)\n```\n\n## Search Control\n\n### Search Classifier\n\nLet AI decide when to search:\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"What is 2+2?\"}],\n enable_search_classifier=True # Skips search for math\n)\n```\n\n### Disable Search\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"Write a poem\"}],\n disable_search=True # Uses only training data\n)\n```\n\n## Combining Filters\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"climate policy\"}],\n search_domain_filter=[\"nature.com\", \".gov\"],\n search_language_filter=[\"en\", \"de\"],\n search_recency_filter=\"month\",\n web_search_options={\n \"search_context_size\": \"high\",\n \"user_location\": {\"country\": \"US\"}\n }\n)\n```\n\n## Filter Limits Summary\n\n| Filter | Limit |\n| ------------------- | ------------ |\n| domain_filter | 20 entries |\n| language_filter | 10 languages |\n| image_domain_filter | 10 entries |\n| image_format_filter | 10 entries |\n","content_type":"text/markdown; charset=utf-8","language":"markdown","size":6579,"content_sha256":"a82168b675ddf32fe39eca9f829f2245e3ce5eeae9c1ceda22576a548b106968"},{"filename":"references/media.md","content":"# Perplexity Media Handling\n\nGuide to images, videos, and file attachments.\n\n## Returning Images\n\n### Enable Image Returns\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar\",\n messages=[{\"role\": \"user\", \"content\": \"Mount Everest images\"}],\n return_images=True\n)\n```\n\n### Image Domain Filtering\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar\",\n messages=[{\"role\": \"user\", \"content\": \"historical images\"}],\n return_images=True,\n image_domain_filter=[\"wikimedia.org\"], # Allow only\n # OR\n image_domain_filter=[\"-gettyimages.com\", \"-shutterstock.com\"] # Exclude\n)\n```\n\n### Image Format Filtering\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar\",\n messages=[{\"role\": \"user\", \"content\": \"funny cat gif\"}],\n return_images=True,\n image_format_filter=[\"gif\"] # gif, jpg, png, webp\n)\n```\n\n### Image Limits\n\n- Maximum 30 images per response\n- Maximum 10 entries in `image_domain_filter`\n- Maximum 10 entries in `image_format_filter`\n- Formats: lowercase, no dot prefix (`gif` not `.gif`)\n\n### Common Stock Photo Exclusions\n\n```python\nimage_domain_filter=[\n \"-gettyimages.com\",\n \"-shutterstock.com\",\n \"-istockphoto.com\",\n \"-pinterest.com\"\n]\n```\n\n## Returning Videos\n\n### Enable Video Returns\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"2024 Olympics highlights\"}],\n media_response={\n \"overrides\": {\n \"return_videos\": True\n }\n }\n)\n```\n\n### Combined Media Response\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"Mars rover discoveries\"}],\n media_response={\n \"overrides\": {\n \"return_videos\": True,\n \"return_images\": True\n }\n }\n)\n```\n\n### Video Response Structure\n\n```json\n{\n \"videos\": [\n {\n \"url\": \"https://www.youtube.com/watch?v=...\",\n \"duration\": null,\n \"thumbnail_width\": 480,\n \"thumbnail_height\": 360,\n \"thumbnail_url\": \"...\"\n }\n ]\n}\n```\n\n## Image Attachments (Input)\n\nAnalyze images by uploading them.\n\n### Via HTTPS URL\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\n \"role\": \"user\",\n \"content\": [\n {\"type\": \"text\", \"text\": \"Describe this image\"},\n {\n \"type\": \"image_url\",\n \"image_url\": {\n \"url\": \"https://example.com/image.jpg\"\n }\n }\n ]\n }]\n)\n```\n\n### Via Base64\n\n```python\nimport base64\n\nwith open(\"image.png\", \"rb\") as f:\n image_data = base64.b64encode(f.read()).decode()\n\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\n \"role\": \"user\",\n \"content\": [\n {\"type\": \"text\", \"text\": \"What text is in this screenshot?\"},\n {\n \"type\": \"image_url\",\n \"image_url\": {\n \"url\": f\"data:image/png;base64,{image_data}\"\n }\n }\n ]\n }]\n)\n```\n\n### Image Attachment Limits\n\n- Maximum size: **50 MB** per image\n- Supported formats: PNG, JPEG, WEBP, GIF\n- **NOT supported**: `sonar-deep-research` model\n\n### Image Pricing Formula\n\n$\ntokens = \\frac{width\\ px \\times height\\ px}{750}\n$\n\nExamples:\n\n- 1024×768 image = 1,048 tokens\n- 512×512 image = 349 tokens\n\n## File Attachments\n\nAnalyze documents (PDF, DOC, DOCX, TXT, RTF).\n\n### Via URL\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\n \"role\": \"user\",\n \"content\": [\n {\"type\": \"text\", \"text\": \"Summarize this document\"},\n {\n \"type\": \"file_url\",\n \"file_url\": {\n \"url\": \"https://example.com/document.pdf\"\n }\n }\n ]\n }]\n)\n```\n\n### Via Base64\n\n```python\nimport base64\n\nwith open(\"report.pdf\", \"rb\") as f:\n file_data = base64.b64encode(f.read()).decode()\n\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\n \"role\": \"user\",\n \"content\": [\n {\"type\": \"text\", \"text\": \"Extract key findings\"},\n {\n \"type\": \"file_url\",\n \"file_url\": {\n \"url\": file_data # No prefix for base64\n },\n \"file_name\": \"report.pdf\"\n }\n ]\n }]\n)\n```\n\n### File Attachment Limits\n\n- Maximum size: **50 MB** per file\n- Maximum files: **30** per request\n- Maximum processing time: 60 seconds\n- Supported: PDF, DOC, DOCX, TXT, RTF\n- **NOT supported**: Scanned images (not OCR)\n\n### Base64 Important Notes\n\n- For files: provide **only** the base64 string, **no** `data:` URI prefix\n- For images: use full data URI format `data:image/png;base64,...`\n\n## Common Use Cases\n\n### Screenshot Analysis\n\n```python\nmessages=[{\n \"role\": \"user\",\n \"content\": [\n {\"type\": \"text\", \"text\": \"Extract all text from this screenshot\"},\n {\"type\": \"image_url\", \"image_url\": {\"url\": \"...\"}}\n ]\n}]\n```\n\n### PDF Summarization\n\n```python\nmessages=[{\n \"role\": \"user\",\n \"content\": [\n {\"type\": \"text\", \"text\": \"Summarize key points and recommendations\"},\n {\"type\": \"file_url\", \"file_url\": {\"url\": \"https://example.com/report.pdf\"}}\n ]\n}]\n```\n\n### Combining Document with Web Search\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\n \"role\": \"user\",\n \"content\": [\n {\"type\": \"text\", \"text\": \"Compare this paper's findings with recent studies\"},\n {\"type\": \"file_url\", \"file_url\": {\"url\": \"https://example.com/paper.pdf\"}}\n ]\n }]\n)\n```\n\n## Error Handling\n\n| Error | Cause | Solution |\n| ------------------ | ----------------------- | ----------------------------------------- |\n| Invalid URL | URL not accessible | Verify URL returns file directly |\n| File too large | Exceeds 50MB | Compress or split document |\n| Processing timeout | Document too complex | Simplify question or use smaller sections |\n| Invalid base64 | Malformed base64 string | Check encoding, no prefix for files |\n| Invalid format | Unsupported file type | Use PDF, DOC, DOCX, TXT, or RTF |\n","content_type":"text/markdown; charset=utf-8","language":"markdown","size":6438,"content_sha256":"01ac26381e779469489bee271a8adbc2a3a2d8db7c62a60ac9bc92f5e3bf312b"},{"filename":"references/models.md","content":"# Perplexity Models Reference\n\n## Available Models\n\n### Sonar (sonar)\n\n- **Purpose:** Lightweight, cost-effective web search\n- **Best for:** Quick facts, news updates, simple Q&A, high-volume applications\n- **Pricing:** $1/1M input tokens, $1/1M output tokens\n\n### Sonar Pro (sonar-pro)\n\n- **Purpose:** Advanced search with deeper content understanding\n- **Best for:** Complex queries, competitive analysis, detailed research\n- **Pricing:** $3/1M input tokens, $15/1M output tokens\n\n### Sonar Reasoning Pro (sonar-reasoning-pro)\n\n- **Purpose:** Enhanced multi-step reasoning with web search\n- **Best for:** Complex problem-solving, research analysis, strategic planning\n- **Pricing:** $2/1M input tokens, $8/1M output tokens\n\n### Sonar Deep Research (sonar-deep-research)\n\n- **Purpose:** Exhaustive research and detailed report generation\n- **Best for:** Academic research, market analysis, comprehensive reports\n- **Pricing:** $2/1M input, $8/1M output, $2/1M citation tokens, $5/1K search queries, $3/1M reasoning tokens\n- **Note:** Async-only model via `client.async_.chat.completions.create()`\n\n## Model Selection Decision Tree\n\n```\nQuick factual query? → sonar\nComplex analysis needed? → sonar-pro\nMulti-step reasoning? → sonar-reasoning-pro\nComprehensive research report? → sonar-deep-research\n```\n\n## Request Pricing by Search Context Size\n\n| Model | Low | Medium | High |\n| ------------------- | ----- | ------ | ------ |\n| sonar | $5/1K | $8/1K | $12/1K |\n| sonar-pro | $6/1K | $10/1K | $14/1K |\n| sonar-reasoning-pro | $6/1K | $10/1K | $14/1K |\n\n- **Low:** (default) Fastest, cheapest\n- **Medium:** Balanced cost/quality\n- **High:** Maximum search depth\n\n## Pro Search (sonar-pro only)\n\nEnables automated multi-step tool usage for complex queries.\n\n```python\ncompletion = client.chat.completions.create(\n messages=[...],\n model=\"sonar-pro\",\n stream=True, # Required for Pro Search\n web_search_options={\"search_type\": \"pro\"}\n)\n```\n\n**Search Types:**\n\n- `fast` — Standard behavior (default)\n- `pro` — Multi-step tool usage ($14-$22/1K requests)\n- `auto` — Automatic classification\n\n## Cost Examples\n\n### Sonar (500 input + 200 output tokens, Low context)\n\n- Input: $0.0005\n- Output: $0.0002\n- Request fee: $0.005\n- **Total: $0.0057**\n\n### Sonar Deep Research (typical query)\n\n- Input: ~$0.00\n- Output: ~$0.03-$0.06\n- Citation tokens: ~$0.04-$0.12\n- Reasoning tokens: ~$0.22-$1.02\n- Search queries: ~$0.09-$0.15\n- **Total: $0.40-$1.32**\n\n## Configuration Presets\n\n### Factual Q&A (Low creativity)\n\n```python\nconfig = {\n \"temperature\": 0.1,\n \"top_p\": 0.9,\n \"search_recency_filter\": \"month\"\n}\n```\n\n### Creative Writing (Higher creativity)\n\n```python\nconfig = {\n \"temperature\": 0.8,\n \"top_p\": 0.95,\n \"presence_penalty\": 0.1,\n \"frequency_penalty\": 0.1\n}\n```\n\n## Search API Pricing\n\n**$5 per 1,000 requests** — No token-based costs.\n","content_type":"text/markdown; charset=utf-8","language":"markdown","size":2928,"content_sha256":"d99052194614caaeccfb285709bf892e641a7005fb12c4d7c9c34e4c6397d889"},{"filename":"references/pro-search.md","content":"# Perplexity Pro Search\n\nAdvanced multi-step reasoning with built-in tools.\n\n## Overview\n\nPro Search enables complex research queries with:\n\n- Multi-step reasoning visible in responses\n- Built-in tools: `web_search`, `fetch_url_content`\n- Automatic tool orchestration (no configuration needed)\n\n## Basic Usage\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"Research solar panel ROI for California homes\"}],\n search_type=\"pro\", # \"pro\", \"fast\", or \"auto\"\n stream=True # REQUIRED for Pro Search\n)\n\nfor chunk in completion:\n print(chunk.choices[0].delta.content or \"\", end=\"\")\n```\n\n## Search Types\n\n| Type | Description | Use Case |\n| ---- | ------------------------- | ---------------------------- |\n| pro | Full multi-step reasoning | Complex research, reports |\n| fast | Quick search, fewer steps | Simple queries, speed needed |\n| auto | AI decides | Mixed workloads |\n\n## CRITICAL: Streaming Required\n\nPro Search **REQUIRES** `stream=True`. Non-streaming requests will fail.\n\n```python\n# ✅ CORRECT\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n search_type=\"pro\",\n stream=True,\n messages=[...]\n)\n\n# ❌ WRONG - will fail\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n search_type=\"pro\",\n stream=False, # Pro Search doesn't support this\n messages=[...]\n)\n```\n\n## Built-in Tools\n\nPro Search automatically uses two tools:\n\n### web_search\n\nConducts web searches for current information.\n\n```json\n{\n \"thought\": \"I need current EV market data\",\n \"type\": \"web_search\",\n \"web_search\": {\n \"search_keywords\": [\"EV Statistics 2024\", \"electric vehicle sales\"],\n \"search_results\": [\n {\n \"title\": \"Trends in electric cars\",\n \"url\": \"https://www.iea.org/...\",\n \"date\": \"2024-03-15\",\n \"snippet\": \"Electric car sales neared 14 million...\",\n \"source\": \"web\"\n }\n ]\n }\n}\n```\n\n### fetch_url_content\n\nRetrieves full content from specific URLs.\n\n```json\n{\n \"thought\": \"This paper has detailed methodology I need\",\n \"type\": \"fetch_url_content\",\n \"fetch_url_content\": {\n \"contents\": [\n {\n \"title\": \"Research Paper Title\",\n \"url\": \"https://arxiv.org/pdf/...\",\n \"snippet\": \"The dominant sequence transduction models...\"\n }\n ]\n }\n}\n```\n\n## Multi-Tool Workflows\n\nPro Search automatically chains tools:\n\n1. **User asks**: \"Research solar panel options for California homes\"\n2. **web_search** → finds incentives and costs\n3. **fetch_url_content** → reads policy documents\n4. **web_search** → verifies electricity rates\n\n## Reasoning Steps\n\nAccess tool executions in `reasoning_steps`:\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n search_type=\"pro\",\n stream=True,\n messages=[{\"role\": \"user\", \"content\": \"AI startup funding 2024\"}]\n)\n\nfull_response = \"\"\nreasoning_steps = []\n\nfor chunk in completion:\n if chunk.choices[0].delta.content:\n full_response += chunk.choices[0].delta.content\n\n # Collect reasoning steps from streaming response\n if hasattr(chunk, 'reasoning_steps'):\n reasoning_steps.extend(chunk.reasoning_steps)\n\nprint(\"Final answer:\", full_response)\nprint(\"Research steps:\", reasoning_steps)\n```\n\n## Pricing\n\n| Search Type | Per 1K Requests |\n| ----------- | --------------- |\n| Pro Search | $14–$22 |\n| Fast Search | $6–$14 |\n\nPrices vary by search context size (Low/Medium/High).\n\n## Pro Search vs Standard Sonar Pro\n\n| Feature | Standard Sonar Pro | Pro Search |\n| ---------------- | ------------------ | ------------ |\n| Model | sonar-pro | sonar-pro |\n| Streaming | Optional | **Required** |\n| Multi-step | No | Yes |\n| Tool visibility | No | Yes |\n| Complex research | Limited | Excellent |\n| Cost | Lower | Higher |\n\n## Best Practices\n\n### Use Pro Search When\n\n- Complex, multi-step research needed\n- Want visibility into search process\n- Building research/analysis tools\n- Need comprehensive answers\n\n### Use Standard Search When\n\n- Simple factual queries\n- Speed is priority\n- Cost-sensitive applications\n- Don't need reasoning visibility\n\n### Combine with Filters\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n search_type=\"pro\",\n stream=True,\n messages=[{\"role\": \"user\", \"content\": \"Latest AI research papers\"}],\n search_domain_filter=[\"arxiv.org\", \"nature.com\"],\n search_recency_filter=\"month\"\n)\n```\n\n## Error Handling\n\n```python\nfrom perplexity import BadRequestError\n\ntry:\n completion = client.chat.completions.create(\n model=\"sonar-pro\",\n search_type=\"pro\",\n stream=False, # This will fail\n messages=[...]\n )\nexcept BadRequestError as e:\n if \"stream\" in str(e).lower():\n print(\"Pro Search requires stream=True\")\n```\n\n## sonar-deep-research\n\nFor exhaustive research, use `sonar-deep-research`:\n\n```python\n# Deep research is async-only\nasync def deep_research():\n async with AsyncPerplexity() as client:\n completion = await client.chat.completions.create(\n model=\"sonar-deep-research\",\n messages=[{\"role\": \"user\", \"content\": \"Comprehensive analysis of...\"}],\n stream=True\n )\n async for chunk in completion:\n print(chunk.choices[0].delta.content or \"\", end=\"\")\n```\n\n### Deep Research Limitations\n\n- **Async only** — use `AsyncPerplexity`\n- **No image input** — doesn't support image attachments\n- **Longer response time** — can take minutes\n- **Highest cost** — use sparingly\n","content_type":"text/markdown; charset=utf-8","language":"markdown","size":5803,"content_sha256":"018b09a47b6b5c522252ee1d4c069de193fee5b5594b826be20491f47eb6c7e5"},{"filename":"references/prompting.md","content":"# Perplexity Prompting Guide\n\nBest practices for prompting web-search models.\n\n## System vs User Prompt\n\n### System Prompt\n\n- Controls style, tone, language of response\n- **NOT used** by real-time search component\n- Good for formatting instructions\n\n```python\nmessages=[\n {\n \"role\": \"system\",\n \"content\": \"\"\"You are a helpful AI assistant.\nRules:\n1. Provide only the final answer without explaining steps.\n2. Format as a list if multiple items.\"\"\"\n },\n {\"role\": \"user\", \"content\": \"Best sushi restaurants in Tokyo\"}\n]\n```\n\n### User Prompt\n\n- Used to kick off real-time web search\n- Should contain the actual query\n- Be specific and contextual\n\n## Key Differences from Traditional LLMs\n\nWeb search models behave differently from standard LLMs:\n\n| Aspect | Traditional LLM | Perplexity Web Search |\n| ------------------- | ---------------------- | ----------------------------- |\n| Few-shot prompting | Works well | **Avoid** — confuses search |\n| Generic questions | Often acceptable | **Too broad** — poor results |\n| Multi-part requests | Handled reasonably | **Break apart** — one topic |\n| URL requests | Can hallucinate anyway | **Never ask** — use citations |\n\n## Best Practices\n\n### Be Specific\n\n```python\n# ✅ GOOD - specific context\n\"Explain recent advances in climate prediction models for urban planning\"\n\n# ❌ BAD - too generic\n\"Tell me about climate models\"\n```\n\n### Avoid Few-Shot Prompting\n\n```python\n# ✅ GOOD\n\"Summarize current research on mRNA vaccine technology\"\n\n# ❌ BAD - examples confuse search\n\"Here's an example summary: [example]. Now summarize mRNA vaccines.\"\n```\n\n### Use Search-Friendly Terms\n\n```python\n# ✅ GOOD - terms experts would use\n\"Compare energy efficiency ratings of heat pumps vs traditional HVAC for residential use\"\n\n# ❌ BAD - vague\n\"Tell me which home heating is better\"\n```\n\n### One Topic Per Query\n\n```python\n# ✅ GOOD\n\"Explain quantum computing principles that might impact cryptography in the next decade\"\n\n# ❌ BAD - multiple unrelated topics\n\"Explain quantum computing, regenerative agriculture, and stock market predictions\"\n```\n\n## Handling URLs and Sources\n\n### NEVER ask for URLs in prompts\n\nThe model cannot see actual URLs from search and will **hallucinate** them.\n\n```python\n# ❌ WRONG - URLs will be hallucinated\nmessages=[{\n \"role\": \"user\",\n \"content\": \"Find Canadian news. For each, include headline, summary, and source link.\"\n}]\n\n# ✅ CORRECT - get URLs from response metadata\nmessages=[{\n \"role\": \"user\",\n \"content\": \"Find Canadian news. For each, include headline and why it matters.\"\n}]\n\n# Then access URLs from search_results field in response\nfor citation in completion.citations:\n print(f\"Source: {citation.url}\")\n```\n\n### Use Citations Field\n\nURLs are in `search_results` / `citations`:\n\n```python\ncompletion = client.chat.completions.create(...)\n\n# Access accurate sources\nfor citation in completion.citations:\n print(f\"{citation.title}: {citation.url}\")\n```\n\n## Preventing Hallucination\n\n### Set Clear Boundaries\n\n```python\nmessages=[{\n \"role\": \"user\",\n \"content\": \"\"\"Search for renewable energy developments.\nIf you cannot find relevant information, state that clearly\nrather than providing speculative information.\"\"\"\n}]\n```\n\n### Request Source Transparency\n\n```python\nmessages=[{\n \"role\": \"user\",\n \"content\": \"\"\"Find Tesla's latest earnings report.\nOnly provide information from your search results.\nClearly state if certain details are not available.\"\"\"\n}]\n```\n\n### Avoid Inaccessible Sources\n\nThese often lead to hallucination:\n\n- LinkedIn posts (private/auth required)\n- Paywalled content\n- Private documents\n- Very recent unindexed content\n\n## Use API Parameters, Not Prompts\n\n### DON'T control search via prompts\n\n```python\n# ❌ INEFFECTIVE\nmessages=[{\n \"role\": \"user\",\n \"content\": \"Search only Wikipedia for climate change. Only use sources from past month.\"\n}]\n```\n\n### DO use built-in parameters\n\n```python\n# ✅ EFFECTIVE\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"Climate change policies\"}],\n search_domain_filter=[\"wikipedia.org\"],\n search_recency_filter=\"month\"\n)\n```\n\n## Query Type Tips\n\n| Query Type | Best Practices |\n| ---------------- | ------------------------------------------------------ |\n| Factual Research | Use domain filters, high search context |\n| Creative Content | Style guidelines in system prompt, disable_search=True |\n| Technical | Include language/framework, use docs domains |\n| Analysis | Request step-by-step reasoning |\n\n## Examples\n\n### Technical Documentation\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"FastAPI dependency injection patterns\"}],\n search_domain_filter=[\"fastapi.tiangolo.com\", \"docs.python.org\"],\n web_search_options={\"search_context_size\": \"medium\"}\n)\n```\n\n### Current Events\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\n \"role\": \"user\",\n \"content\": \"Latest AI policy developments in European Union this week\"\n }],\n search_recency_filter=\"week\"\n)\n```\n\n### Creative (No Search)\n\n```python\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[\n {\"role\": \"system\", \"content\": \"You are a creative writing assistant.\"},\n {\"role\": \"user\", \"content\": \"Write a short sci-fi story about time travel\"}\n ],\n disable_search=True,\n temperature=0.8\n)\n```\n\n## Parameter Recommendations\n\n- **Do NOT tune** `temperature` — defaults are optimized\n- **Do use** `search_domain_filter` for trusted sources\n- **Do use** `search_context_size` appropriately:\n - `low` — simple facts\n - `medium` — general use (default)\n - `high` — comprehensive research\n","content_type":"text/markdown; charset=utf-8","language":"markdown","size":6007,"content_sha256":"df85624742408752a42754e8cf477dd7b6deb8bf70a5dc084ecc44e1c9f7d106"},{"filename":"references/search-api.md","content":"# Search API Reference\n\nReal-time ranked web search results with advanced filtering.\n\n## Basic Search\n\n```python\nfrom perplexity import Perplexity\n\nclient = Perplexity()\n\nsearch = client.search.create(\n query=\"latest AI developments 2024\",\n max_results=5,\n max_tokens_per_page=2048\n)\n\nfor result in search.results:\n print(f\"{result.title}: {result.url}\")\n print(f\"Snippet: {result.snippet[:200]}...\")\n print(f\"Date: {result.date}\")\n```\n\n## Response Structure\n\n```json\n{\n \"results\": [\n {\n \"title\": \"Article Title\",\n \"url\": \"https://example.com/article\",\n \"snippet\": \"Content excerpt...\",\n \"date\": \"2024-01-15\",\n \"last_updated\": \"2024-01-20\"\n }\n ],\n \"id\": \"request-uuid\"\n}\n```\n\n## Parameters\n\n| Parameter | Type | Default | Description |\n| ------------------------ | ----------- | -------- | -------------------------------------- |\n| `query` | string/list | required | Search query (up to 5 for multi-query) |\n| `max_results` | int | 10 | Results per query (1-20) |\n| `max_tokens_per_page` | int | 2048 | Content extraction per page |\n| `max_tokens` | int | 25000 | Total content budget (max 1M) |\n| `country` | string | - | ISO 3166-1 alpha-2 code |\n| `search_domain_filter` | list | - | Domain allow/denylist (max 20) |\n| `search_language_filter` | list | - | ISO 639-1 codes (max 10) |\n\n## Regional Search\n\n```python\nsearch = client.search.create(\n query=\"government renewable energy policies\",\n country=\"US\", # ISO country code\n max_results=5\n)\n```\n\nCommon codes: `US`, `GB`, `DE`, `JP`, `FR`, `CA`, `AU`\n\n## Multi-Query Search\n\nExecute up to 5 queries in single request:\n\n```python\nsearch = client.search.create(\n query=[\n \"artificial intelligence trends 2024\",\n \"machine learning breakthroughs recent\",\n \"AI applications in healthcare\"\n ],\n max_results=5\n)\n\n# Results grouped by query\nfor i, query_results in enumerate(search.results):\n print(f\"Query {i+1}:\")\n for result in query_results:\n print(f\" {result.title}\")\n```\n\n**Note:** Single query returns flat list; multi-query returns nested lists.\n\n## Domain Filtering\n\n### Allowlist Mode (include only)\n\n```python\nsearch = client.search.create(\n query=\"climate change research\",\n search_domain_filter=[\n \"science.org\",\n \"nature.com\",\n \"pnas.org\"\n ]\n)\n```\n\n### Denylist Mode (exclude)\n\n```python\nsearch = client.search.create(\n query=\"renewable energy innovations\",\n search_domain_filter=[\n \"-pinterest.com\",\n \"-reddit.com\",\n \"-quora.com\"\n ]\n)\n```\n\n**Rules:**\n\n- Max 20 domains per filter\n- Cannot mix allowlist and denylist in same request\n- Prefix with `-` for denylist\n\n## Language Filtering\n\n```python\nsearch = client.search.create(\n query=\"latest AI news\",\n search_language_filter=[\"en\", \"fr\", \"de\"],\n max_results=10\n)\n```\n\nMax 10 language codes per request.\n\n## Content Extraction Control\n\n```python\n# Comprehensive extraction (slower)\ndetailed = client.search.create(\n query=\"AI research methodology\",\n max_results=5,\n max_tokens_per_page=2048,\n max_tokens=50000\n)\n\n# Quick extraction (faster)\nbrief = client.search.create(\n query=\"AI news headlines\",\n max_results=10,\n max_tokens_per_page=512,\n max_tokens=5000\n)\n```\n\n**Recommendations:**\n\n- `max_tokens_per_page`: 256-512 for quick retrieval\n- `max_tokens_per_page`: 2048+ for deep analysis\n- Lower values = faster processing\n\n## Async Search\n\n```python\nimport asyncio\nfrom perplexity import AsyncPerplexity\n\nasync def batch_search(queries, batch_size=3, delay_ms=1000):\n async with AsyncPerplexity() as client:\n results = []\n\n for i in range(0, len(queries), batch_size):\n batch = queries[i:i + batch_size]\n tasks = [\n client.search.create(query=q, max_results=5)\n for q in batch\n ]\n batch_results = await asyncio.gather(*tasks)\n results.extend(batch_results)\n\n if i + batch_size \u003c len(queries):\n await asyncio.sleep(delay_ms / 1000)\n\n return results\n```\n\n## Rate-Limited Concurrent Search\n\n```python\nimport asyncio\nfrom perplexity import AsyncPerplexity\n\nclass SearchManager:\n def __init__(self, max_concurrent=5):\n self.semaphore = asyncio.Semaphore(max_concurrent)\n\n async def search_single(self, client, query):\n async with self.semaphore:\n return await client.search.create(query=query, max_results=5)\n\n async def search_many(self, queries):\n async with AsyncPerplexity() as client:\n tasks = [self.search_single(client, q) for q in queries]\n return await asyncio.gather(*tasks, return_exceptions=True)\n```\n\n## Caching Pattern\n\n```python\nimport time\nfrom typing import Dict, Tuple, Optional\n\nclass SearchCache:\n def __init__(self, ttl_seconds=3600):\n self.cache: Dict[str, Tuple[any, float]] = {}\n self.ttl = ttl_seconds\n\n def get(self, query: str) -> Optional[any]:\n if query in self.cache:\n result, timestamp = self.cache[query]\n if time.time() - timestamp \u003c self.ttl:\n return result\n del self.cache[query]\n return None\n\n def set(self, query: str, result: any):\n self.cache[query] = (result, time.time())\n\n# Usage\ncache = SearchCache(ttl_seconds=1800)\n\ndef cached_search(client, query):\n cached = cache.get(query)\n if cached:\n return cached\n result = client.search.create(query=query)\n cache.set(query, result)\n return result\n```\n\n## Error Handling\n\n```python\nfrom perplexity import RateLimitError, APIStatusError\n\ndef resilient_search(client, query, max_retries=3):\n for attempt in range(max_retries):\n try:\n return client.search.create(query=query)\n except RateLimitError:\n if attempt \u003c max_retries - 1:\n time.sleep(2 ** attempt)\n else:\n raise\n except APIStatusError as e:\n print(f\"API error: {e}\")\n return None\n```\n\n## Best Practices\n\n1. **Be specific:** \"AI medical diagnosis accuracy 2024\" > \"AI medical\"\n2. **Use multi-query:** Break research into related sub-queries\n3. **Request only needed results:** More results = longer response\n4. **Cache static queries:** Don't repeat unchanged searches\n5. **Implement backoff:** Handle rate limits gracefully\n","content_type":"text/markdown; charset=utf-8","language":"markdown","size":6657,"content_sha256":"97f0a9aa7057541127f22080f7b86d2aa8d87231707ff7506760f1958c8d6554"},{"filename":"references/structured-outputs.md","content":"# Structured Outputs Reference\n\nEnforce JSON response formats using JSON Schema.\n\n## Basic Usage\n\n```python\nfrom perplexity import Perplexity\nfrom pydantic import BaseModel\n\nclass ContactInfo(BaseModel):\n email: str\n phone: str\n\nclient = Perplexity()\n\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"Find Tesla IR contact info\"}],\n response_format={\n \"type\": \"json_schema\",\n \"json_schema\": {\n \"schema\": ContactInfo.model_json_schema()\n }\n }\n)\n\ncontact = ContactInfo.model_validate_json(completion.choices[0].message.content)\nprint(f\"Email: {contact.email}\")\n```\n\n## Response Format Structure\n\n```json\n{\n \"response_format\": {\n \"type\": \"json_schema\",\n \"json_schema\": {\n \"schema\": {\n /* your JSON schema */\n }\n }\n }\n}\n```\n\n## Financial Analysis Example\n\n```python\nfrom typing import List, Optional\nfrom pydantic import BaseModel\n\nclass FinancialMetrics(BaseModel):\n company: str\n quarter: str\n revenue: float\n net_income: float\n eps: float\n revenue_growth_yoy: Optional[float] = None\n key_highlights: Optional[List[str]] = None\n\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\n \"role\": \"user\",\n \"content\": \"Analyze Apple's latest quarterly earnings. Extract key metrics.\"\n }],\n response_format={\n \"type\": \"json_schema\",\n \"json_schema\": {\"schema\": FinancialMetrics.model_json_schema()}\n }\n)\n\nmetrics = FinancialMetrics.model_validate_json(\n completion.choices[0].message.content\n)\nprint(f\"Revenue: ${metrics.revenue}B\")\n```\n\n## Perplexity vs Other Providers\n\n**Simplified syntax** — no `name` or `strict` fields required:\n\n```json\n// Other providers\n{\n \"response_format\": {\n \"type\": \"json_schema\",\n \"json_schema\": {\n \"name\": \"my_schema\",\n \"strict\": true,\n \"schema\": { ... }\n }\n }\n}\n\n// Perplexity\n{\n \"response_format\": {\n \"type\": \"json_schema\",\n \"json_schema\": {\n \"schema\": { ... }\n }\n }\n}\n```\n\n## Reasoning Models\n\nWith `sonar-reasoning-pro`, response includes `\u003cthink>` section:\n\n```\n\u003cthink>\nI need to provide information about France...\nLet me format this information as required.\n\u003c/think>\n{\"country\":\"France\",\"capital\":\"Paris\",\"population\":67750000}\n```\n\n**Parse manually** to extract JSON after `\u003c/think>`.\n\n## Cold Start Warning\n\n**First request with new schema takes 10-30 seconds** to prepare.\n\n- May cause timeout errors on first call\n- Subsequent requests with same schema are fast\n- Consider pre-warming schemas in production\n\n## Improve Compliance\n\nAdd hints in prompts:\n\n```python\nmessages = [{\n \"role\": \"user\",\n \"content\": \"\"\"Find the contact information for Apple investor relations.\n Return as JSON with email and phone fields.\"\"\"\n}]\n```\n\n## Unsupported Schemas\n\n```python\n# ❌ UNSUPPORTED: Recursive schema\nclass RecursiveJson(BaseModel):\n value: str\n child: list[\"RecursiveJson\"]\n\n# ❌ UNSUPPORTED: Unconstrained dict\nfrom typing import Any\n\nclass UnconstrainedDict(BaseModel):\n data: dict[str, Any]\n```\n\n## Links in JSON Responses\n\n**Do NOT request links in JSON structured outputs.**\n\n- May result in hallucinations or broken URLs\n- Use `citations` or `search_results` from API response instead\n\n```python\n# ❌ BAD: Links in schema\nclass ResultWithLink(BaseModel):\n title: str\n url: str # May be hallucinated\n\n# ✅ GOOD: Get links from citations\ncompletion = client.chat.completions.create(...)\ncitations = completion.citations # Valid URLs\n```\n\n## Best Practices\n\n1. **Use Pydantic** — Generate schemas with `model_json_schema()`\n2. **Keep schemas simple** — Avoid deep nesting\n3. **No recursion** — Flatten recursive structures\n4. **Type everything** — Use specific types, not `Any`\n5. **Pre-warm schemas** — First request is slow\n6. **Get links from citations** — Don't request URLs in JSON\n7. **Add prompt hints** — Improve schema compliance\n","content_type":"text/markdown; charset=utf-8","language":"markdown","size":3982,"content_sha256":"8db8d9105c5390ec44f71a70875499261e382e5f5c8fdc8778cca3303ca1b595"}],"content_json":{"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"text":"Perplexity API","type":"text"}]},{"type":"paragraph","content":[{"text":"Build AI applications with real-time web search and grounded responses.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Quick Navigation","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Models & pricing: ","type":"text"},{"text":"references/models.md","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Search API patterns: ","type":"text"},{"text":"references/search-api.md","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Chat completions guide: ","type":"text"},{"text":"references/chat-completions.md","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Browser sessions API: ","type":"text"},{"text":"references/browser.md","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Embeddings API: ","type":"text"},{"text":"references/embeddings.md","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Structured outputs: ","type":"text"},{"text":"references/structured-outputs.md","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Filters (domain/language/date/location): ","type":"text"},{"text":"references/filters.md","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Media (images/videos/attachments): ","type":"text"},{"text":"references/media.md","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Pro Search: ","type":"text"},{"text":"references/pro-search.md","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Prompting best practices: ","type":"text"},{"text":"references/prompting.md","type":"text","marks":[{"type":"code_inline"}]}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"When to Use","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Need AI responses grounded in current web data","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Building search-powered applications","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Research tools requiring citations","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Real-time Q&A with source verification","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Document/image analysis with web context","type":"text"}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Installation","type":"text"}]},{"type":"paragraph","content":[{"text":"Install: ","type":"text"},{"text":"pip install perplexityai","type":"text","marks":[{"type":"code_inline"}]},{"text":" (Python) or ","type":"text"},{"text":"npm install @perplexityai/perplexity","type":"text","marks":[{"type":"code_inline"}]},{"text":" (TypeScript/JavaScript).","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Authentication","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"# macOS/Linux\nexport PERPLEXITY_API_KEY=\"your_api_key_here\"\n\n# Windows\nsetx PERPLEXITY_API_KEY \"your_api_key_here\"","type":"text"}]},{"type":"paragraph","content":[{"text":"SDK auto-reads ","type":"text"},{"text":"PERPLEXITY_API_KEY","type":"text","marks":[{"type":"code_inline"}]},{"text":" environment variable.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Quick Start — Chat Completion","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"from perplexity import Perplexity\n\nclient = Perplexity()\n\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"What is the latest news on AI?\"}]\n)\n\nprint(completion.choices[0].message.content)","type":"text"}]},{"type":"paragraph","content":[{"text":"Note (v0.28.0):","type":"text","marks":[{"type":"strong"}]},{"text":" The Python client includes a custom JSON encoder to support additional types in request payloads.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Quick Start — Search API","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"from perplexity import Perplexity\n\nclient = Perplexity()\n\nsearch = client.search.create(\n query=\"artificial intelligence trends 2024\",\n max_results=5\n)\n\nfor result in search.results:\n print(f\"{result.title}: {result.url}\")","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Model Selection Guide","type":"text"}]},{"type":"table","attrs":{"layout":null},"content":[{"type":"tr","content":[{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Model","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Use Case","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Cost","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"sonar","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Quick facts, simple Q&A","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Lowest","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"sonar-pro","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Complex queries, research","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Medium","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"sonar-reasoning-pro","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Multi-step reasoning, analysis","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Medium","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"sonar-deep-research","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Exhaustive research, reports","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Highest","type":"text"}]}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Key Patterns","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Streaming Responses","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"stream = client.chat.completions.create(\n messages=[{\"role\": \"user\", \"content\": \"Explain quantum computing\"}],\n model=\"sonar\",\n stream=True\n)\n\nfor chunk in stream:\n if chunk.choices[0].delta.content:\n print(chunk.choices[0].delta.content, end=\"\")","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Multi-Turn Conversation","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"messages = [\n {\"role\": \"system\", \"content\": \"You are a research assistant.\"},\n {\"role\": \"user\", \"content\": \"What causes climate change?\"},\n {\"role\": \"assistant\", \"content\": \"Climate change is caused by...\"},\n {\"role\": \"user\", \"content\": \"What are the solutions?\"}\n]\n\ncompletion = client.chat.completions.create(messages=messages, model=\"sonar\")","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Web Search Options","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"completion = client.chat.completions.create(\n messages=[{\"role\": \"user\", \"content\": \"Latest renewable energy news\"}],\n model=\"sonar\",\n web_search_options={\n \"search_recency_filter\": \"week\",\n \"search_domain_filter\": [\"energy.gov\", \"iea.org\"]\n }\n)","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Pro Search (Multi-Step Research)","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"# REQUIRES stream=True\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"Research solar panel ROI\"}],\n search_type=\"pro\",\n stream=True\n)\n\nfor chunk in completion:\n print(chunk.choices[0].delta.content or \"\", end=\"\")","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Image Attachment","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"completion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\n \"role\": \"user\",\n \"content\": [\n {\"type\": \"text\", \"text\": \"Describe this image\"},\n {\"type\": \"image_url\", \"image_url\": {\"url\": \"https://example.com/image.jpg\"}}\n ]\n }]\n)","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"File Attachment (PDF Analysis)","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"completion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\n \"role\": \"user\",\n \"content\": [\n {\"type\": \"text\", \"text\": \"Summarize this document\"},\n {\"type\": \"file_url\", \"file_url\": {\"url\": \"https://example.com/report.pdf\"}}\n ]\n }]\n)","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Return Images in Response","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"completion = client.chat.completions.create(\n model=\"sonar\",\n messages=[{\"role\": \"user\", \"content\": \"Mount Everest photos\"}],\n return_images=True,\n image_format_filter=[\"jpg\", \"png\"]\n)","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Domain Filtering (Search API)","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"# Allowlist: include only these domains\nsearch = client.search.create(\n query=\"climate research\",\n search_domain_filter=[\"science.org\", \"nature.com\"]\n)\n\n# Denylist: exclude these domains\nsearch = client.search.create(\n query=\"tech news\",\n search_domain_filter=[\"-reddit.com\", \"-pinterest.com\"]\n)","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Multi-Query Search","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"search = client.search.create(\n query=[\n \"AI trends 2024\",\n \"machine learning healthcare\",\n \"neural networks applications\"\n ],\n max_results=5\n)\n\nfor i, query_results in enumerate(search.results):\n print(f\"Query {i+1} results:\")\n for result in query_results:\n print(f\" {result.title}\")","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Structured Outputs (JSON Schema)","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"from pydantic import BaseModel\n\nclass ContactInfo(BaseModel):\n email: str\n phone: str\n\ncompletion = client.chat.completions.create(\n model=\"sonar-pro\",\n messages=[{\"role\": \"user\", \"content\": \"Find contact for Tesla IR\"}],\n response_format={\n \"type\": \"json_schema\",\n \"json_schema\": {\"schema\": ContactInfo.model_json_schema()}\n }\n)\n\ncontact = ContactInfo.model_validate_json(completion.choices[0].message.content)","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Async Operations","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"import asyncio\nfrom perplexity import AsyncPerplexity\n\nasync def main():\n async with AsyncPerplexity() as client:\n tasks = [\n client.search.create(query=\"AI news\"),\n client.search.create(query=\"tech trends\")\n ]\n results = await asyncio.gather(*tasks)\n\nasyncio.run(main())","type":"text"}]},{"type":"heading","attrs":{"level":3},"content":[{"text":"Rate Limit Handling","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"import time\nfrom perplexity import RateLimitError\n\ndef search_with_retry(client, query, max_retries=3):\n for attempt in range(max_retries):\n try:\n return client.search.create(query=query)\n except RateLimitError:\n if attempt \u003c max_retries - 1:\n time.sleep(2 ** attempt)\n else:\n raise","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Response Parameters","type":"text"}]},{"type":"table","attrs":{"layout":null},"content":[{"type":"tr","content":[{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Parameter","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Default","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Description","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"temperature","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"0.7","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Creativity (0-2)","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"max_tokens","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"varies","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Response length limit","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"top_p","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"0.9","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Nucleus sampling","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"presence_penalty","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"0","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Reduce repetition (-2 to 2)","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"frequency_penalty","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"0","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Reduce word frequency (-2 to 2)","type":"text"}]}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Search API Parameters","type":"text"}]},{"type":"table","attrs":{"layout":null},"content":[{"type":"tr","content":[{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Parameter","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Description","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"max_results","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"1-20 results per query","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"max_tokens_per_page","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Content extraction depth (default 2048)","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"country","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"ISO country code for regional results","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"search_domain_filter","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Domain allowlist/denylist (max 20)","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"search_language_filter","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"ISO 639-1 language codes (max 10)","type":"text"}]}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Pricing Quick Reference","type":"text"}]},{"type":"paragraph","content":[{"text":"Search API:","type":"text","marks":[{"type":"strong"}]},{"text":" $5/1K requests (no token costs)","type":"text"}]},{"type":"paragraph","content":[{"text":"Sonar Models (per 1M tokens):","type":"text","marks":[{"type":"strong"}]}]},{"type":"table","attrs":{"layout":null},"content":[{"type":"tr","content":[{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Model","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Input","type":"text"}]}]},{"type":"th","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"Output","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"sonar","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"$1","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"$1","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"sonar-pro","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"$3","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"$15","type":"text"}]}]}]},{"type":"tr","content":[{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"sonar-reasoning-pro","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"$2","type":"text"}]}]},{"type":"td","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"alignment":""},"content":[{"type":"paragraph","content":[{"text":"$8","type":"text"}]}]}]}]},{"type":"paragraph","content":[{"text":"Request fees","type":"text","marks":[{"type":"strong"}]},{"text":" (per 1K requests): $5-$14 depending on search context size.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Critical Prohibitions","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Do NOT request links/URLs in prompts (use ","type":"text"},{"text":"citations","type":"text","marks":[{"type":"code_inline"}]},{"text":" field instead — model will hallucinate URLs)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Do NOT use recursive JSON schemas (not supported)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Do NOT use ","type":"text"},{"text":"dict[str, Any]","type":"text","marks":[{"type":"code_inline"}]},{"text":" in Pydantic models for structured outputs","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Do NOT mix allowlist and denylist in ","type":"text"},{"text":"search_domain_filter","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Do NOT exceed 5 queries in multi-query search","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Do NOT expect first request with new JSON schema to be fast (10-30s warmup)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Do NOT use Pro Search without ","type":"text"},{"text":"stream=True","type":"text","marks":[{"type":"code_inline"}]},{"text":" (will fail)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Do NOT send images to ","type":"text"},{"text":"sonar-deep-research","type":"text","marks":[{"type":"code_inline"}]},{"text":" (not supported)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Do NOT include ","type":"text"},{"text":"data:","type":"text","marks":[{"type":"code_inline"}]},{"text":" prefix for file attachments base64 (only for images)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Do NOT try to control search via prompts (use API parameters instead)","type":"text"}]}]}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Error Handling","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"python"},"content":[{"text":"import perplexity\n\ntry:\n completion = client.chat.completions.create(...)\nexcept perplexity.BadRequestError as e:\n print(f\"Invalid parameters: {e}\")\nexcept perplexity.RateLimitError:\n print(\"Rate limited, retry later\")\nexcept perplexity.APIStatusError as e:\n print(f\"API error: {e.status_code}\")","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"OpenAI SDK Compatibility","type":"text"}]},{"type":"paragraph","content":[{"text":"Perplexity supports OpenAI Chat Completions format. Use OpenAI client by pointing to Perplexity endpoint.","type":"text"}]},{"type":"heading","attrs":{"level":2},"content":[{"text":"Links","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"API Portal","type":"text","marks":[{"type":"link","attrs":{"href":"https://www.perplexity.ai/settings/api","title":null}}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Documentation","type":"text","marks":[{"type":"link","attrs":{"href":"https://docs.perplexity.ai/","title":null}}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Python SDK (PyPI)","type":"text","marks":[{"type":"link","attrs":{"href":"https://pypi.org/project/perplexityai/","title":null}}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"TypeScript SDK (npm)","type":"text","marks":[{"type":"link","attrs":{"href":"https://www.npmjs.com/package/@perplexityai/perplexity","title":null}}]}]}]}]},{"type":"hr","attrs":{"markup":"---"}}]},"metadata":{"date":"2026-06-05","name":"perplexity","author":"@skillopedia","source":{"stars":17,"repo_name":"llm-code","origin_url":"https://github.com/itechmeat/llm-code/blob/HEAD/skills/perplexity/SKILL.md","repo_owner":"itechmeat","body_sha256":"3756b727c289594a0a8ffc36399aa5a077ec300d716b05128d0b5fe4330774a1","cluster_key":"59e341d088871579bd21f76ea0d116d6e36e6c1ea00bf10478b904c51b05241b","clean_bundle":{"format":"clean-skill-bundle-v1","source":"itechmeat/llm-code/skills/perplexity/SKILL.md","attachments":[{"id":"7a3f99dc-0e14-5d04-a242-1a89d58967cd","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/7a3f99dc-0e14-5d04-a242-1a89d58967cd/attachment.md","path":"references/browser.md","size":970,"sha256":"bdfcd81e86980bd5f4f8579311403952f0a8dbf8bb49cfb36e5be2896c7d8cb7","contentType":"text/markdown; charset=utf-8"},{"id":"b4bab682-9937-50fd-af79-467a4f2af12e","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/b4bab682-9937-50fd-af79-467a4f2af12e/attachment.md","path":"references/chat-completions.md","size":6402,"sha256":"4cca9073facc46c85c5aea4e088f7e92f1f763bd6b3e0a6842e2c6cc11b8cb5a","contentType":"text/markdown; charset=utf-8"},{"id":"e364fb21-8074-59ac-b869-f7c34201dec4","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/e364fb21-8074-59ac-b869-f7c34201dec4/attachment.md","path":"references/embeddings.md","size":2299,"sha256":"3303d9f6341a59ea6c34249948135751d7a23ce80fa5ea4783bd2f71ca3abfc1","contentType":"text/markdown; charset=utf-8"},{"id":"a5dfcd32-2107-5091-98ec-6710ba738e64","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/a5dfcd32-2107-5091-98ec-6710ba738e64/attachment.md","path":"references/filters.md","size":6579,"sha256":"a82168b675ddf32fe39eca9f829f2245e3ce5eeae9c1ceda22576a548b106968","contentType":"text/markdown; charset=utf-8"},{"id":"eaf4a2a8-2d41-58ad-9b7a-325a0af690f0","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/eaf4a2a8-2d41-58ad-9b7a-325a0af690f0/attachment.md","path":"references/media.md","size":6438,"sha256":"01ac26381e779469489bee271a8adbc2a3a2d8db7c62a60ac9bc92f5e3bf312b","contentType":"text/markdown; charset=utf-8"},{"id":"2437bbbf-1be2-56ae-a4fa-bf3917742e15","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/2437bbbf-1be2-56ae-a4fa-bf3917742e15/attachment.md","path":"references/models.md","size":2928,"sha256":"d99052194614caaeccfb285709bf892e641a7005fb12c4d7c9c34e4c6397d889","contentType":"text/markdown; charset=utf-8"},{"id":"7b11a3f7-04dc-575f-a568-df5f041742c8","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/7b11a3f7-04dc-575f-a568-df5f041742c8/attachment.md","path":"references/pro-search.md","size":5803,"sha256":"018b09a47b6b5c522252ee1d4c069de193fee5b5594b826be20491f47eb6c7e5","contentType":"text/markdown; charset=utf-8"},{"id":"39ac6d7a-58d5-5151-8dd0-ba3e721c2a98","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/39ac6d7a-58d5-5151-8dd0-ba3e721c2a98/attachment.md","path":"references/prompting.md","size":6007,"sha256":"df85624742408752a42754e8cf477dd7b6deb8bf70a5dc084ecc44e1c9f7d106","contentType":"text/markdown; charset=utf-8"},{"id":"59dc0554-6c97-504e-98db-6cb4a5daac99","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/59dc0554-6c97-504e-98db-6cb4a5daac99/attachment.md","path":"references/search-api.md","size":6657,"sha256":"97f0a9aa7057541127f22080f7b86d2aa8d87231707ff7506760f1958c8d6554","contentType":"text/markdown; charset=utf-8"},{"id":"43c94155-9f35-55cd-a27d-6139c9c42187","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/43c94155-9f35-55cd-a27d-6139c9c42187/attachment.md","path":"references/structured-outputs.md","size":3982,"sha256":"8db8d9105c5390ec44f71a70875499261e382e5f5c8fdc8778cca3303ca1b595","contentType":"text/markdown; charset=utf-8"}],"bundle_sha256":"4050ced67bef98ae7e5dc445c84ebf8a7129df0823b09b7b78dbf084b307f434","attachment_count":10,"text_attachments":10,"attachment_storage":"skillopedia-attachments-v1","binary_attachments":0,"excluded_attachments":[]},"cluster_size":1,"skill_md_path":"skills/perplexity/SKILL.md","import_metadata":{"date":"2026-06-05","author":"@skillopedia","version":"v1","category":"documents-office","category_label":"Documents"},"exact_dupes_collapsed_into_this":0},"version":"v1","category":"documents-office","metadata":{"version":"0.34.0","release_date":"2026-05-13"},"import_tag":"clean-skills-v1","description":"Perplexity API for web-grounded AI and search. Covers Sonar models, chat/search APIs, streaming, structured outputs, filters, and attachments. Keywords: Perplexity, Sonar, search API, grounded LLM."}},"renderedAt":1782986512914}

Perplexity API Build AI applications with real-time web search and grounded responses. Quick Navigation - Models & pricing: - Search API patterns: - Chat completions guide: - Browser sessions API: - Embeddings API: - Structured outputs: - Filters (domain/language/date/location): - Media (images/videos/attachments): - Pro Search: - Prompting best practices: When to Use - Need AI responses grounded in current web data - Building search-powered applications - Research tools requiring citations - Real-time Q&A with source verification - Document/image analysis with web context Installation Instal…