Perplexity API Guide 2026: Base URL, URL Scheme and Which Model to Call
The Perplexity API looks OpenAI-compatible until it isn't - different base URL, different model names, search grounding in the response. This guide maps the URL scheme and the model lineup.
💡 What You Will Learn
The Perplexity API looks OpenAI-compatible until it isn't - different base URL, different model names, search grounding in the response. This guide maps the URL scheme and the model lineup.
📜 Table of Contents
The URL Scheme
Perplexity's API is OpenAI-compatible in shape but has its own host. The base URL is https://api.perplexity.ai and the chat endpoint is /chat/completions, so a full request goes to:
POST https://api.perplexity.ai/chat/completions
Authorization: Bearer <key>
Content-Type: application/json
The request body mirrors OpenAI's: model, messages, max_tokens, temperature. That means any OpenAI SDK can target Perplexity by overriding base_url - a one-line change in most clients.
What Makes the Response Different
Perplexity's differentiator is search grounding: enable search mode and the API runs a live web search, then the model answers with citations. The response includes a citations array with source URLs, which is why it is popular for research bots and news aggregators. In OpenAI's plain chat format you would have to build that grounding yourself.
The Model Lineup (2025-2026)
Perplexity's models belong to the sonar family. The general model launched at $1 per million input tokens and $5 per million output tokens, with a reasoning variant priced higher and aimed at multi-step research. The exact list changes as they iterate, so the reliable move is to check the models endpoint (GET /models) - it returns the current names and is the same pattern OpenAI uses.
A Minimal Call
from openai import OpenAI
client = OpenAI(api_key="pplx-...", base_url="https://api.perplexity.ai")
resp = client.chat.completions.create(
model="sonar",
messages=[{"role": "user", "content": "List 2026 open source RAG frameworks with stars"}],
)
print(resp.choices[0].message.content)
One SDK, one base_url override, and the response carries citations you can render as links.
When to Use It vs a Raw LLM API
Choose Perplexity when the answer needs freshness (current events, product comparisons) or verifiable sources. Choose a plain LLM API when you have your own retrieval and do not want to pay for search grounding you will not use. If your app answers stable technical questions from your own docs, grounding is wasted money.
