| name | perplexity-observability |
| description | Set up monitoring for Perplexity Sonar API with latency, cost, citation quality, and error tracking.
Use when implementing monitoring dashboards, setting up alerts,
or tracking Perplexity API health in production.
Trigger with phrases like "perplexity monitoring", "perplexity metrics",
"perplexity observability", "monitor perplexity", "perplexity dashboard".
|
| allowed-tools | Read, Write, Edit |
| version | 1.12.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","perplexity","monitoring","observability","dashboard"] |
| compatibility | Designed for Claude Code, also compatible with Codex and OpenClaw |
Perplexity Observability
Overview
Monitor Perplexity Sonar API performance, cost, and quality. Key signals unique to Perplexity: citation count per response (quality indicator), search latency variability (web search is non-deterministic), and per-model cost differences.
Key Metrics
| Metric | sonar (typical) | sonar-pro (typical) | Alert Threshold |
|---|
| Latency p50 | 1-2s | 3-5s | p95 > 15s |
| Citations/response | 3-5 | 5-10 | 0 for 10min |
| Error rate | <1% | <1% | >5% |
| Cost/query | $0.005 | $0.02 | >$0.10 |
Prerequisites
- Perplexity API integration running
- Metrics backend (Prometheus, Datadog, or custom)
- Alerting system configured
Instructions
Step 1: Instrument the Perplexity Client
import OpenAI from "openai";
interface SearchMetrics {
model: string;
latencyMs: number;
status: "success" | "error";
citationCount: number;
totalTokens: number;
cached: boolean;
errorCode?: number;
}
const metrics: SearchMetrics[] = [];
async function instrumentedSearch(
client: OpenAI,
: ,
: = ,
: =
): <{ : ; : }> {
start = performance.();
: ;
{
response = client...({
model,
: [{ : , : query }],
});
searchMetrics = {
model,
: performance.() - start,
: ,
: (response ).?. || ,
: response.?. || ,
cached,
};
metrics.(searchMetrics);
{ response, : searchMetrics };
} (: ) {
searchMetrics = {
model,
: performance.() - start,
: ,
: ,
: ,
cached,
: err.,
};
metrics.(searchMetrics);
err;
}
}