Diagnose and fix Perplexity common errors and exceptions.
Use when encountering Perplexity errors, debugging failed requests,
or troubleshooting integration issues.
Trigger with phrases like "perplexity error", "fix perplexity",
"perplexity not working", "debug perplexity".
Quick reference for the most common Perplexity Sonar API errors, their root causes, and fixes. All Perplexity errors follow the OpenAI error format since the API is OpenAI-compatible.
Prerequisites
PERPLEXITY_API_KEY environment variable set
curl available for diagnostic commands
Error Reference
401 Unauthorized — Invalid API Key
{"error": {"message": "Invalid API key", "type": "authentication_error", "code": 401}}
Causes: Key missing, expired, revoked, or doesn't start with pplx-.
Fix:
set -euo pipefail
# Verify key is set and has correct prefix
echo "${PERPLEXITY_API_KEY:0:5}" # Should print "pplx-"
# Test key directly
curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: Bearer $PERPLEXITY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"sonar","messages":[{"role":"user","content":"test"}],"max_tokens":5}' \
https://api.perplexity.ai/chat/completions
# 200 = valid, 401 = invalid key
{"error": {"message": "search_domain_filter must contain at most 20 domains"}}
Cause: Exceeding the 20-domain limit, or mixing allowlist (no prefix) with denylist (- prefix).
Fix: Use either allowlist OR denylist mode, not both:
// Allowlist: only these domains
search_domain_filter: ["python.org", "docs.python.org"]
// Denylist: exclude these domains
search_domain_filter: ["-reddit.com", "-quora.com"]
Empty Citations Array
Not an error, but a common surprise.
Causes: Query too abstract, non-factual question, or model couldn't find relevant sources.
Fix:
// BAD: abstract query yields no citations
"Tell me about technology"
// GOOD: specific factual query
"What are the key features of TypeScript 5.5 released in 2025?"
Use sonar-pro for more citations (2x average citation count vs sonar).
Timeout / Hanging Request
Causes: Complex query with sonar-pro or sonar-deep-research. Sonar: 1-3s typical. Sonar-pro: 3-8s. Deep research: 10-60s.
set -euo pipefail
# Quick API health check
curl -s -w "\nHTTP %{http_code} in %{time_total}s\n" \
-H "Authorization: Bearer $PERPLEXITY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"sonar","messages":[{"role":"user","content":"ping"}],"max_tokens":5}' \
https://api.perplexity.ai/chat/completions
# Check if key env var is set
env | grep PERPLEXITY
# Test DNS resolution
dig api.perplexity.ai +short
Error Handling
HTTP Code
Error Type
Retry?
Action
400
invalid_request_error
No
Fix request parameters
401
authentication_error
No
Regenerate API key
402
billing_error
No
Add credits
429
rate_limit_error
Yes
Exponential backoff
500+
server_error
Yes
Retry after 2-5 seconds
Output
Identified error cause from HTTP status and error type