Skip to main content

Overview

The Perplexity SDKs provide several features to optimize performance for high-throughput applications. This guide covers async operations, connection pooling, raw response access, and other performance optimization techniques.

Async Support

Basic Async Usage

For applications that need to handle multiple requests concurrently:

Concurrent Requests

Process multiple requests simultaneously for better throughput:

Batch Processing with Rate Limiting

Process large numbers of requests while respecting rate limits:

Raw Response Access

Access headers, status codes, and raw response data for advanced use cases:

Response Streaming

For Agent API responses, use streaming to get partial results as they arrive:
The fields used by the example look like this; the full event also includes sequence and output metadata:

Connection Pooling

Optimized Connection Settings

Configure connection pooling for better performance:

Performance Monitoring

Request Timing and Metrics

Monitor performance metrics to identify bottlenecks:

Memory Optimization

Efficient Data Processing

Process large datasets efficiently with streaming and pagination:

Best Practices

1

Use async for concurrent operations

Always use async clients when you need to process multiple requests simultaneously.
For CPU-bound processing after API calls, consider using worker threads or processes.
2

Implement connection pooling

Configure appropriate connection limits based on your application’s needs.
3

Monitor and tune performance

Use metrics to identify bottlenecks and optimize accordingly.
Don’t optimize prematurely - measure first, then optimize based on actual performance data.
4

Handle backpressure

Implement proper rate limiting and backpressure handling for high-throughput applications.

Configuration

Optimize connection pooling and timeouts

Error Handling

Handle errors in async operations