API for the model perplexity/sonar at OpenRouter, $1 / $1 per million tokens, context 127,072 tokens. curl, Python and JavaScript samples, live testing.
Sonar is lightweight, affordable, fast, and simple to use — now featuring citations and the ability to customize sources. It is designed for companies seeking to integrate lightweight question-and-answer features...
- Type
- Model
- Provider
- OpenRouter
- Model ID
perplexity/sonar- Pricing
- Paid
- Input / output price
- $1 / $1 per million tokens
- Keyless access
- No
- Key variable
OPENROUTER_API_KEY- Base URL (OpenAI-compatible)
https://openrouter.ai/api/v1- Context
- 127,072 tokens
- Inputs
- Text, Image
- Features
- Web search
- Developer rating
- Not rated yet
- Documentation
- https://openrouter.ai/perplexity/sonar
Code samples
cURL
curl https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d '{"model":"perplexity/sonar","messages":[{"role":"user","content":"Hello, introduce yourself in one sentence."}]}'Python
# pip install openai
import os
from openai import OpenAI
client = OpenAI(base_url="https://openrouter.ai/api/v1", api_key=os.environ["OPENROUTER_API_KEY"])
r = client.chat.completions.create(
model="perplexity/sonar",
messages=[{"role": "user", "content": "Hello, introduce yourself in one sentence."}],
)
print(r.choices[0].message.content)JavaScript
// npm install openai
import OpenAI from 'openai'
const client = new OpenAI({ baseURL: 'https://openrouter.ai/api/v1', apiKey: process.env.OPENROUTER_API_KEY })
const r = await client.chat.completions.create({
model: 'perplexity/sonar',
messages: [{ role: 'user', content: 'Hello, introduce yourself in one sentence.' }],
})
console.log(r.choices[0].message.content)
Generate the integration code →
Popular searches
Frequently asked questions
Is the Perplexity: Sonar API free?
No: Perplexity: Sonar is a paid API ($1 / $1 per million tokens).
How do I call Perplexity: Sonar from my code?
Perplexity: Sonar exposes an OpenAI-compatible API at https://openrouter.ai/api/v1: use any OpenAI SDK (Python, JavaScript…) with this base URL. Model identifier: perplexity/sonar. Ready-to-use code (streaming, JSON, retries) is available in the developer toolkit.
What is the context window of Perplexity: Sonar?
Perplexity: Sonar accepts up to 127,072 tokens of context (prompt and history).
What are the alternatives to Perplexity: Sonar?
Similar APIs listed in the catalog: Perplexity: Sonar Pro Search, Perplexity: Sonar Reasoning Pro, Perplexity: Sonar Pro, Perplexity: Sonar Deep Research, Perplexity · sonar.
Alternatives
- Perplexity: Sonar Pro Search — Paid
- Perplexity: Sonar Reasoning Pro — Paid
- Perplexity: Sonar Pro — Paid
- Perplexity: Sonar Deep Research — Paid
- Perplexity · sonar — Price not disclosed