Overview
Generate AI responses with web-grounded knowledge using either the Python or TypeScript SDKs. Both SDKs provide full support for chat completions, streaming responses, async operations, and comprehensive error handling.Quick Start
Example Output
Example Output
Features
Model Selection
Choose from different Sonar models based on your needs:Conversation Context
Build multi-turn conversations with context:Web Search Options
Control how the model searches and uses web information:Response Customization
Customize response format and behavior:Streaming Responses
Get real-time response streaming for better user experience:For comprehensive streaming documentation including metadata collection, error handling, advanced patterns, and raw HTTP examples, see the Streaming Guide.
Async Chat Completions
For long-running or batch processing tasks, use the async endpoints:Creating Async Requests
Checking Request Status
Listing Async Requests
Advanced Usage
Error Handling
Handle chat-specific errors:Custom Instructions
Use system messages for consistent behavior:Concurrent Operations
Handle multiple conversations efficiently:Best Practices
1
Use appropriate models
Choose the right model for your use case:
sonar
for general queries, sonar-pro
for complex analysis, sonar-reasoning
for analytical tasks.2
Implement streaming for long responses
Use streaming for better user experience with lengthy responses.
3
Handle rate limits gracefully
Implement exponential backoff for production applications.
4
Optimize for specific use cases
Configure parameters based on your application’s needs.
Resources
- The Perplexity SDK Guide - The Perplexity SDK guide
- OpenAI Compatibility - OpenAI compatibility guide
- Streaming Responses - Complete streaming guide with advanced patterns
- API Reference - Chat Completions - Chat Completions API Reference
- API Reference - Async Chat Completions - Async API Reference
- Structured Outputs - Formatted response generation