1. Getting Started
Sign up at perplexity.ai, navigate to API settings, and generate an API key. Perplexity uses a pay-per-token model similar to OpenAI. The API is OpenAI-compatible.
2. Making Search Requests
Use the chat completions endpoint with online models for search capabilities. The response includes citations so you can verify sources.
from openai import OpenAI
client = OpenAI(
api_key="your-perplexity-key",
base_url="https://api.perplexity.ai"
)
response = client.chat.completions.create(
model="llama-3.1-sonar-large-128k-online",
messages=[{"role": "user", "content": "What are the latest AI developments?"}]
)3. Use Cases
Perplexity excels at: research assistants, fact-checking workflows, competitive intelligence gathering, news monitoring, and any application needing current information with sources.
Wrap-up
Perplexity is ideal when you need AI with access to current information and verifiable sources. Consider it as a search tool for your AI agents.