What is the Perplexity sonar API?
Perplexity's sonar API provides real-time, search-grounded AI responses via an OpenAI-compatible REST API. Every response includes citations from live web sources.
Quick Start
```javascript
const response = await fetch("https://api.perplexity.ai/chat/completions", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.PERPLEXITY_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "sonar",
messages: [{ role: "user", content: "What are today's top AI news stories?" }],
}),
});
const data = await response.json();
console.log(data.choices[0].message.content);
```
Available Models
- **sonar** — Fast, search-grounded responses
- **sonar-pro** — Deeper reasoning with more citations
- **sonar-reasoning** — Extended chain-of-thought with search
Use Cases
Best for: real-time news summaries, competitive research, fact-checking pipelines, and any task requiring up-to-date information.