| name | perplexity-performance-tuning |
| description | Optimize Perplexity Sonar API performance with caching, streaming, model routing, and batching.
Use when experiencing slow API responses, implementing caching strategies,
or optimizing request throughput for Perplexity integrations.
Trigger with phrases like "perplexity performance", "optimize perplexity",
"perplexity latency", "perplexity caching", "perplexity slow".
|
| allowed-tools | Read, Write, Edit |
| version | 1.12.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","perplexity","api","performance"] |
| compatibility | Designed for Claude Code, also compatible with Codex and OpenClaw |
Perplexity Performance Tuning
Overview
Optimize Perplexity Sonar API for latency, throughput, and cost. Key insight: every Perplexity call performs a live web search, so response times are inherently variable. Typical latencies: sonar 1-3s, sonar-pro 3-8s, sonar-deep-research 10-60s.
Latency Benchmarks
| Model | Typical Latency | Max Tokens | Best For |
|---|
sonar | 1-3s | 4096 | Quick answers, simple facts |
sonar-pro | 3-8s | 8192 | Deep research, many citations |
sonar-reasoning-pro | 5-15s | 8192 | Multi-step analysis |
sonar-deep-research | 10-60s | 8192 | Comprehensive reports |
Prerequisites
- Perplexity API key configured
- Understanding of search-augmented generation latency patterns
- Cache infrastructure (Redis or in-memory LRU)
Instructions
Step 1: Smart Model Routing
import OpenAI from "openai";
const perplexity = new OpenAI({
apiKey: process.env.PERPLEXITY_API_KEY,
baseURL: "https://api.perplexity.ai",
});
type QueryComplexity = "simple" | "standard" | "deep";
function classifyQuery(query: string): QueryComplexity {
const words = query.split().;
simplePatterns = [, , , , ];
deepPatterns = [, , , , ];
(simplePatterns.( p.(query)) && words < ) ;
(deepPatterns.( p.(query)) || words > ) ;
;
}
(): { : ; : } {
(complexity) {
: { : , : };
: { : , : };
: { : , : };
}
}
() {
complexity = (query);
{ model, maxTokens } = (complexity);
perplexity...({
model,
: [{ : , : query }],
: maxTokens,
});
}