🏠 Home

The Perplexity Advantage

OpenAI Compatibility and Unique Controls

Effortless Migration from OpenAI

OpenAI

from openai import OpenAI

client = OpenAI(api_key="sk-...")

response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello"}],
    temperature=0.7,
    max_tokens=150
)

Perplexity

from openai import OpenAI

client = OpenAI(
    api_key="pplx-...",
    base_url="https://api.perplexity.ai"
)

response = client.chat.completions.create(
    model="llama-3.1-sonar-large-128k-online",
    messages=[{"role": "user", "content": "Hello"}],
    temperature=0.7,
    max_tokens=150
)

✓ Just change the base URL and API key - all your existing code works!

Choose Your API: Search vs Grounded LLM

🔍 Search API

Direct search with structured results

  • ✓ Raw search results access
  • ✓ Multiple search queries
  • ✓ Structured JSON responses
  • ✓ Direct source URLs
  • ✓ No LLM processing
POST /search
{
  "query": "latest AI news",
  "search_type": "news",
  "limit": 10
}
Search API Docs

🤖 Grounded LLM API

AI-powered answers with citations

  • ✓ Natural language answers
  • ✓ Automatic web search
  • ✓ Citation links included
  • ✓ OpenAI compatible
  • ✓ Context-aware responses
POST /chat/completions
{
  "model": "sonar-pro",
  "messages": [{
    "role": "user",
    "content": "What's new in AI?"
  }]
}
LLM API Docs

All Standard OpenAI Parameters Supported

model

Select from Perplexity's model lineup

messages

Standard conversation array format

temperature

Control response randomness (0-2)

max_tokens

Set response length limits

top_p

Nucleus sampling control

stream

Real-time streamed responses

frequency_penalty

Control word repetition

presence_penalty

Manage topic diversity

Perplexity-Exclusive Search Superpowers

🎯

search_domain_filter

Include or exclude specific domains

["include:arxiv.org", "exclude:reddit.com"]
📅

search_recency_filter

Filter by content freshness

"month", "week", "day", "hour"
📊

search_context_size

Control search depth

"low" | "medium" | "high"
🎓

search_mode

Web or academic sources

"web" | "academic"

🧠 How Perplexity Works: The Intelligence Pipeline

📝

1. Query Analysis

Parse intent and context

🎯

2. Mode Selection

Choose search strategy

🔍

3. Search Execution

Retrieve relevant data

4. Synthesis

Generate final answer

Perplexity's multi-stage pipeline ensures accurate, relevant, and up-to-date responses

📝 Stage 1: Intelligent Query Analysis

Intent Classification

Factual Query "What is the capital of France?" → May skip search
Current Events "Latest AI news today" → Requires fresh search
Research "Compare quantum computing approaches" → Deep search needed
Creative "Write a poem about coding" → No search required

Signals Analyzed

  • 🕐 Temporal markers ("today", "latest", "2024")
  • 🎓 Academic indicators ("research", "study", "paper")
  • 📊 Data needs (statistics, numbers, metrics)
  • 🌍 Geographic context (locations, regions)
  • 🏢 Domain specificity (tech, finance, health)

🎯 Stage 2: Dynamic Search Mode Selection

Query Received

Select Mode Based On:

Academic Terms Detected?

Academic Mode

Search: arXiv, PubMed, Google Scholar

search_mode="academic"
Time-Sensitive?

Real-time Web

Priority: Recent results

search_recency_filter="hour"
Domain-Specific?

Targeted Search

Filter: Specific domains

search_domain_filter=[...]
General Knowledge?

No Search

Use: Model knowledge only

disable_search=True

🔍 Stage 3: Intelligent Search Execution

🌐 Web Coverage Strategy

Broad Search:

  • Multiple search engines queried
  • 20-50 sources evaluated
  • Cross-referenced for accuracy

Targeted Search:

  • Domain-filtered queries
  • 5-10 authoritative sources
  • Deep content extraction

📚 Source Ranking Algorithm

35% Relevance Score
25% Source Authority
20% Content Freshness
20% Information Density

Context Size Impact

Low

3-5 sources • Fast • Cost-effective

Medium

10-15 sources • Balanced • Standard

High

20+ sources • Comprehensive • Research-grade

✨ Stage 4: Intelligent Answer Synthesis

1. Information Extraction

Pull key facts from each source

Source 1: "GDP grew 3.2% in Q3" Source 2: "Inflation at 2.1%" Source 3: "Fed signals rate pause"

2. Fact Verification

Cross-reference and validate claims

✓ Consistent across sources ⚠ Conflicting data resolved [1][2] Citations added

3. Coherent Generation

Compose natural, accurate response

📝 Natural language flow 🔗 Source attribution 📊 Structured if requested

Output Adaptation - Same Data, Three Ways

Standard: Conversational with citations
Structured: JSON/Schema compliant
Enhanced: With images and related questions

Standard Response

Apple's Q4 2024 revenue reached $94.8 billion, representing an 8.1% year-over-year increase. iPhone sales grew 6% to $46.2 billion, while Services revenue hit a record $22.3 billion. China sales declined 2.5% due to increased competition.

[1] Apple Inc. Q4 2024 Earnings [2] Reuters Financial Report

Structured JSON

{
  "company": "Apple Inc.",
  "quarter": "Q4 2024",
  "total_revenue": 94800000000,
  "growth_rate": "8.1%",
  "segments": {
    "iphone": {
      "revenue": 46200000000,
      "growth": "6%"
    },
    "services": {
      "revenue": 22300000000,
      "record": true
    }
  },
  "regional_performance": {
    "china": {
      "change": "-2.5%",
      "reason": "increased competition"
    }
  }
}

Enhanced Response

Apple's Q4 2024 revenue reached $94.8 billion, up 8.1% year-over-year. iPhone sales grew 6% while Services hit record highs.

📊 Q4 Revenue Chart 📱 iPhone Sales Graph

🎬 Real Example: "Latest breakthroughs in quantum computing"

1️⃣ Query Analysis

✓ Temporal marker: "latest", "2024"

✓ Technical domain: "quantum computing"

✓ Research intent: "breakthroughs"

→ Decision: Fresh academic + tech search needed

2️⃣ Search Configuration

{
  "search_mode": "web",  // Not purely academic
  "search_recency_filter": "month",
  "search_domain_filter": [
    "include:arxiv.org",
    "include:nature.com",
    "include:ieee.org",
    "include:quantumcomputing.com"
  ],
  "search_context_size": "high"
}

3️⃣ Sources Found

📄 arXiv: "Logical quantum processor based on..." [Nov 2024]
📰 Nature: "IBM demonstrates 1000+ qubit processor" [Oct 2024]
🔬 Google Research: "Willow chip achieves..." [Dec 2024]
📊 IEEE: "Error correction breakthrough..." [Sep 2024]

4️⃣ Synthesized Answer

"The latest quantum computing breakthroughs in 2024 include Google's Willow chip achieving below-threshold error correction [1], IBM's Condor processor exceeding 1000 qubits [2], and Harvard's demonstration of logical qubits with 99.5% fidelity [3]..."

Intelligent Search Controls

🤖 enable_search_classifier

Let AI automatically decide when web search is needed

response = client.chat.completions.create(
    model="llama-3.1-sonar-large-128k-online",
    messages=messages,
    enable_search_classifier=True  # Smart search activation
)

🔌 disable_search

Turn off web search for deterministic, offline responses

response = client.chat.completions.create(
    model="llama-3.1-sonar-large-128k-online",
    messages=messages,
    disable_search=True  # Pure model knowledge only
)

Rich, Multimodal Results

🖼️

return_images

Include relevant image URLs in responses

return_images=True

→ Adds visual evidence and context to your answers

💡

return_related_questions

Generate intelligent follow-up questions

return_related_questions=True

→ Boost user engagement and discovery

Structured Outputs - Guaranteed Formats

Define Your Schema

schema = {
    "type": "object",
    "properties": {
        "company": {"type": "string"},
        "revenue": {"type": "number"},
        "growth_rate": {
            "type": "string",
            "pattern": "^\\d+\\.\\d+%$"
        },
        "key_metrics": {
            "type": "array",
            "items": {"type": "string"}
        }
    },
    "required": ["company", "revenue"]
}

response = client.chat.completions.create(
    model="llama-3.1-sonar-large-128k-online",
    messages=[{
        "role": "user",
        "content": "Analyze Apple's earnings"
    }],
    response_format={
        "type": "json_object",
        "schema": schema
    }
)

Get Machine-Readable Results

{
    "company": "Apple Inc.",
    "revenue": 94800000000,
    "growth_rate": "8.1%",
    "key_metrics": [
        "iPhone sales up 6%",
        "Services revenue $22.3B",
        "China sales declined 2.5%"
    ]
}

Benefits:

  • ✓ Guaranteed format compliance
  • ✓ Direct database integration
  • ✓ No manual parsing needed
  • ✓ Type-safe data extraction

Advanced Document Processing

Supported Formats

📄 PDF 📝 DOCX 📃 TXT 🔤 MD
import base64

# Upload and analyze documents
with open("report.pdf", "rb") as file:
    file_content = base64.b64encode(file.read()).decode()

response = client.chat.completions.create(
    model="llama-3.1-sonar-large-128k-online",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Summarize key findings"},
                {"type": "document", "document": {"data": file_content, "type": "pdf"}}
            ]
        }
    ]
)

Asynchronous API for Complex Tasks

1

Submit Job

job = client.async_jobs.create(
    model="llama-3.1-sonar-large-128k-online",
    messages=messages
)
2

Check Status

status = client.async_jobs.get(job.id)
# Status: pending → processing → complete
3

Retrieve Results

if status.status == "complete":
    results = status.result

Perfect for batch processing, complex research, and long-running analysis tasks

🔒 Zero Data Retention Guarantee

What We Keep

  • ✓ API key IDs
  • ✓ Token counts for billing
  • ✓ Timestamp metadata

What We Never Store

  • ✗ Your prompts
  • ✗ AI responses
  • ✗ Uploaded documents
  • ✗ Search queries
  • ✗ Any conversation content

Enterprise Security Features

🔑 API Key Rotation 📊 Audit Trails 🛡️ SOC 2 Compliance 🔐 End-to-End Encryption

Real-World Applications

📰 Real-time News Analysis

search_recency_filter="hour"
search_domain_filter=[
  "include:reuters.com",
  "include:bloomberg.com"
]

🔬 Academic Research

search_mode="academic"
search_context_size="high"
return_related_questions=True

💰 Financial Dashboard

response_format={
  "type": "json_object",
  "schema": financial_schema
}
search_domain_filter=["include:sec.gov"]

📋 Document Intelligence

# Upload and extract data
{"type": "document",
 "document": {"data": contract_pdf}}
response_format={
  "type": "json_object",
  "schema": extraction_schema
}

Build Smarter with Perplexity

OpenAI-compatible for instant migration

Advanced search controls unique to Perplexity

Structured outputs and file processing

Zero data retention guarantee

Enterprise security and compliance

🚀 Get Started with Perplexity API

💻

Official SDKs

Get started quickly with our official Python, TypeScript, and JavaScript SDKs with full documentation and examples.

View All SDKs
🎮

API Playground

Test and explore Perplexity's API capabilities interactively before writing any code.

Try Playground
🔧

Perplexity MCP Server

Connect Perplexity to your tools and workflows with our official MCP server implementation.

Setup MCP Server
🎯

Quick Start Guide

Step-by-step tutorial to migrate from OpenAI and explore Perplexity's unique features.

Start Building
Use arrow keys to navigate • SPACE for audio • Press F for fullscreen • ESC to exit fullscreen