Installation
Setup
Set your Perplexity API key as an environment variable:Usage
Streaming
API Reference
ChatPerplexity
Model name to use (e.g.,
sonar, sonar-pro, sonar-reasoning).Sampling temperature. Controls randomness in generation.
Maximum number of tokens to generate.
Timeout for requests to Perplexity completion API.
Maximum number of retries for failed requests.
Perplexity API key. Automatically read from
PPLX_API_KEY environment variable if not provided.Whether to stream the results or not.
Search mode for specialized content:
academic: Search academic papers and researchsec: Search SEC filingsweb: General web search
Reasoning effort level:
low, medium, or high (default).Preferred language for responses.
List of domains to filter search results (max 20 domains).
Additional model parameters valid for create call not explicitly specified.
Supported Models
- Sonar: Fast, search-augmented model for general queries
- Sonar Pro: More capable model with enhanced search
- Sonar Reasoning: Model with advanced reasoning capabilities
Features
- Search-augmented generation (retrieves real-time information)
- Specialized search modes (academic, SEC filings, web)
- Citations and sources
- Reasoning capabilities
- Streaming
- Async support
- Domain filtering
Perplexity models automatically search the web to provide up-to-date, cited answers. This makes them ideal for queries requiring current information or factual verification.