APIYard
Back to APIs
AI & MLBearer TokenFree tier

Perplexity AI

Perplexity's Sonar models combine real-time web search with LLM reasoning — get grounded, cited answers using an OpenAI-compatible API.

Base URL

https://api.perplexity.ai
searchRAGcitationsreal-timeSonar

Endpoints

POST/chat/completions

Get a grounded answer with real-time web citations.

const response = await fetch("https://api.perplexity.ai/chat/completions", {
  method: "POST",
  headers: {
  "Content-Type": "application/json",
  "Authorization": "Bearer YOUR_ACCESS_TOKEN"
  },
  body: JSON.stringify({
  "model": "sonar",
  "messages": [
    {
      "role": "user",
      "content": "What happened in tech news today?"
    }
  ]
})
});

const data = await response.json();
console.log(data);

Response Preview

{
  "choices": [{
    "message": {
      "role": "assistant",
      "content": "Here are today's top tech stories..."
    }
  }],
  "citations": ["https://techcrunch.com/...", "https://theverge.com/..."]
}