Perplexity
Perplexity models combine language generation with live web search. Use them when you need sourced answers, current information, citation metadata, or research-style synthesis through AvalAI's OpenAI-compatible API.
AvalAI currently exposes the supported Perplexity LLMs through /v1/chat/completions and exposes direct search through v1/search. Responses examples are included as migration patterns for routes/models that explicitly support /v1/responses; keep native Sonar calls on Chat Completions when you need Perplexity-specific fields such as citations, search_results, or search_context_size.
Available Models
- sonar - fast answers with reliable search results
- sonar-pro - advanced search with richer results
- sonar-reasoning - quick chain-of-thought-style reasoning with live search
- sonar-reasoning-pro - deeper reasoning with broader search
- sonar-deep-research - comprehensive research across many sources
- perplexity-search - direct search results without an LLM response
API Endpoint Support
| Capability | Recommended endpoint | Notes |
|---|---|---|
| Native Perplexity LLM answers | /v1/chat/completions | Best for Sonar models, citations, search metadata, and Perplexity-specific response fields. |
| Responses-style text workflows | /v1/responses | Use only with a model/route that supports Responses; map messages to input and read output_text. |
| Direct search only | /v1/search | Use perplexity-search when you need search results without generated prose. |
sonar
Fast answers with reliable search results. Use sonar for quick grounded answers, news checks, definitions, and lightweight browsing tasks.
Features
- Non-reasoning model optimized for speed and cost
- 128K context window
- Live web search with citations and search-result metadata
- Good default for short factual questions and summaries
Pricing
| Type | Cost |
|---|---|
| Input tokens | $1.00 / 1M tokens |
| Cached input tokens | $0.50 / 1M tokens |
| Output tokens | $1.00 / 1M tokens |
| Search context: low | $5 / 1K requests |
| Search context: medium | $8 / 1K requests |
| Search context: high | $12 / 1K requests |
Example
curl https://api.avalai.ir/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AVALAI_API_KEY" \
-d '{
"model": "sonar",
"messages": [
{
"role": "user",
"content": "What is the latest news in AI research?"
}
]
}'import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["AVALAI_API_KEY"],
base_url="https://api.avalai.ir/v1",
)
response = client.chat.completions.create(
model="sonar",
messages=[{"role": "user", "content": "What is the latest news in AI research?"}],
)
print(response.choices[0].message.content)
print(getattr(response, "citations", []))import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.AVALAI_API_KEY,
baseURL: "https://api.avalai.ir/v1",
});
const response = await client.chat.completions.create({
model: "sonar",
messages: [{ role: "user", content: "What is the latest news in AI research?" }],
});
console.log(response.choices[0].message.content);
console.log(response.citations ?? []);Responses API migration pattern
Use this shape only when the selected AvalAI model supports /v1/responses. It does not expose Perplexity-specific citation metadata; keep the Sonar Chat Completions request when you need native search fields.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["AVALAI_API_KEY"],
base_url="https://api.avalai.ir/v1",
)
response = client.responses.create(
model=os.getenv("AVALAI_RESPONSES_MODEL", "gpt-5.5"),
instructions="Answer with concise citations when available.",
input="What is the latest news in AI research?",
)
print(response.output_text)import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.AVALAI_API_KEY,
baseURL: "https://api.avalai.ir/v1",
});
const response = await client.responses.create({
model: process.env.AVALAI_RESPONSES_MODEL ?? "gpt-5.5",
instructions: "Answer with concise citations when available.",
input: "What is the latest news in AI research?",
});
console.log(response.output_text);curl https://api.avalai.ir/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AVALAI_API_KEY" \
-d '{
"model": "gpt-5.5",
"instructions": "Answer with concise citations when available.",
"input": "What is the latest news in AI research?"
}'messages→input- system or policy prompt →
instructions choices[0].message.content→response.output_text- Perplexity
citations/search_results→ keep Chat Completions or call/v1/search
sonar-pro
Advanced search with enhanced result quality. Use sonar-pro for research questions that need broader retrieval, comparison across sources, or longer synthesis.
Features
- 200K input context
- More search results than standard Sonar
- Better fit for market analysis, research summaries, and multi-source synthesis
- Includes live search metadata and citations
Pricing
| Type | Cost |
|---|---|
| Input tokens | $3.00 / 1M tokens |
| Cached input tokens | $1.50 / 1M tokens |
| Output tokens | $15.00 / 1M tokens |
| Search context: low | $6 / 1K requests |
| Search context: medium | $10 / 1K requests |
| Search context: high | $14 / 1K requests |
Example
curl https://api.avalai.ir/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AVALAI_API_KEY" \
-d '{
"model": "sonar-pro",
"messages": [
{
"role": "user",
"content": "Analyze the competitive landscape for AI search engines in 2026."
}
]
}'import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["AVALAI_API_KEY"],
base_url="https://api.avalai.ir/v1",
)
response = client.chat.completions.create(
model="sonar-pro",
messages=[
{
"role": "user",
"content": "Analyze the competitive landscape for AI search engines in 2026.",
}
],
)
print(response.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.AVALAI_API_KEY,
baseURL: "https://api.avalai.ir/v1",
});
const response = await client.chat.completions.create({
model: "sonar-pro",
messages: [
{ role: "user", content: "Analyze the competitive landscape for AI search engines in 2026." },
],
});
console.log(response.choices[0].message.content);Responses API migration pattern
response = client.responses.create(
model=os.getenv("AVALAI_RESPONSES_MODEL", "gpt-5.5"),
instructions="Create a sourced competitive analysis.",
input="Analyze the competitive landscape for AI search engines in 2026.",
)
print(response.output_text)const response = await client.responses.create({
model: process.env.AVALAI_RESPONSES_MODEL ?? "gpt-5.5",
instructions: "Create a sourced competitive analysis.",
input: "Analyze the competitive landscape for AI search engines in 2026.",
});
console.log(response.output_text);curl https://api.avalai.ir/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AVALAI_API_KEY" \
-d '{
"model": "gpt-5.5",
"instructions": "Create a sourced competitive analysis.",
"input": "Analyze the competitive landscape for AI search engines in 2026."
}'Use Chat Completions with sonar-pro when you need native Perplexity citations and search-result fields.
sonar-reasoning
Fast reasoning with real-time search. Use sonar-reasoning when the answer benefits from visible stepwise synthesis but still needs low-latency search.
Features
- Live web search with reasoning-oriented answer synthesis
- 128K context window
- Good for quick fact-checking, current-event explanations, and multi-step Q&A
- Lower output cost than the Pro reasoning model
Pricing
| Type | Cost |
|---|---|
| Input tokens | $1.00 / 1M tokens |
| Cached input tokens | $0.50 / 1M tokens |
| Output tokens | $5.00 / 1M tokens |
| Search context: low | $5 / 1K requests |
| Search context: medium | $8 / 1K requests |
| Search context: high | $14 / 1K requests |
Example
curl https://api.avalai.ir/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AVALAI_API_KEY" \
-d '{
"model": "sonar-reasoning",
"messages": [
{
"role": "user",
"content": "Explain the main tradeoffs of open-weight AI models for startups."
}
]
}'response = client.chat.completions.create(
model="sonar-reasoning",
messages=[
{
"role": "user",
"content": "Explain the main tradeoffs of open-weight AI models for startups.",
}
],
)
print(response.choices[0].message.content)const response = await client.chat.completions.create({
model: "sonar-reasoning",
messages: [
{ role: "user", content: "Explain the main tradeoffs of open-weight AI models for startups." },
],
});
console.log(response.choices[0].message.content);Responses API migration pattern
response = client.responses.create(
model=os.getenv("AVALAI_RESPONSES_MODEL", "gpt-5.5"),
reasoning={"effort": "medium"},
input="Explain the main tradeoffs of open-weight AI models for startups.",
)
print(response.output_text)const response = await client.responses.create({
model: process.env.AVALAI_RESPONSES_MODEL ?? "gpt-5.5",
reasoning: { effort: "medium" },
input: "Explain the main tradeoffs of open-weight AI models for startups.",
});
console.log(response.output_text);curl https://api.avalai.ir/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AVALAI_API_KEY" \
-d '{
"model": "gpt-5.5",
"reasoning": {"effort": "medium"},
"input": "Explain the main tradeoffs of open-weight AI models for startups."
}'Map Chat reasoning examples to the Responses reasoning.effort object when the selected model supports it.
sonar-reasoning-pro
Advanced reasoning with comprehensive search. Use sonar-reasoning-pro for research briefs, high-stakes comparisons, and multi-source answers where depth matters more than latency.
Features
- Reasoning-oriented synthesis with live search
- 128K context window
- Better fit for complex research and strategy questions
- Higher search-context pricing for richer retrieval
Pricing
| Type | Cost |
|---|---|
| Input tokens | $2.00 / 1M tokens |
| Cached input tokens | $1.00 / 1M tokens |
| Output tokens | $8.00 / 1M tokens |
| Search context: low | $6 / 1K requests |
| Search context: medium | $10 / 1K requests |
| Search context: high | $14 / 1K requests |
Example
curl https://api.avalai.ir/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AVALAI_API_KEY" \
-d '{
"model": "sonar-reasoning-pro",
"messages": [
{
"role": "user",
"content": "Compare regulatory approaches to AI safety in the US, EU, and UK."
}
]
}'response = client.chat.completions.create(
model="sonar-reasoning-pro",
messages=[
{
"role": "user",
"content": "Compare regulatory approaches to AI safety in the US, EU, and UK.",
}
],
)
print(response.choices[0].message.content)const response = await client.chat.completions.create({
model: "sonar-reasoning-pro",
messages: [
{ role: "user", content: "Compare regulatory approaches to AI safety in the US, EU, and UK." },
],
});
console.log(response.choices[0].message.content);Responses API migration pattern
response = client.responses.create(
model=os.getenv("AVALAI_RESPONSES_MODEL", "gpt-5.5"),
reasoning={"effort": "high"},
input="Compare regulatory approaches to AI safety in the US, EU, and UK.",
)
print(response.output_text)const response = await client.responses.create({
model: process.env.AVALAI_RESPONSES_MODEL ?? "gpt-5.5",
reasoning: { effort: "high" },
input: "Compare regulatory approaches to AI safety in the US, EU, and UK.",
});
console.log(response.output_text);curl https://api.avalai.ir/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AVALAI_API_KEY" \
-d '{
"model": "gpt-5.5",
"reasoning": {"effort": "high"},
"input": "Compare regulatory approaches to AI safety in the US, EU, and UK."
}'Use reasoning.effort to tune quality, latency, and cost on supported Responses models.
sonar-deep-research
Comprehensive research across many sources. Use sonar-deep-research for long-form reports, source gathering, and questions where citation breadth is the product value.
Features
- Deep research workflow over live web sources
- 128K context window
- Citation-aware output with additional pricing dimensions for reasoning and citations
- Best for reports, market research, policy reviews, and due-diligence drafts
Pricing
| Type | Cost |
|---|---|
| Input tokens | $2.00 / 1M tokens |
| Cached input tokens | $1.00 / 1M tokens |
| Output tokens | $8.00 / 1M tokens |
| Reasoning output | $3.00 / 1M tokens |
| Citations | $2.00 / 1M citations |
| Search context | $5 / 1K requests |
Example
curl https://api.avalai.ir/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AVALAI_API_KEY" \
-d '{
"model": "sonar-deep-research",
"messages": [
{
"role": "user",
"content": "Create a sourced brief on AI adoption in healthcare systems."
}
]
}'response = client.chat.completions.create(
model="sonar-deep-research",
messages=[
{
"role": "user",
"content": "Create a sourced brief on AI adoption in healthcare systems.",
}
],
)
print(response.choices[0].message.content)
print(getattr(response, "citations", []))const response = await client.chat.completions.create({
model: "sonar-deep-research",
messages: [
{ role: "user", content: "Create a sourced brief on AI adoption in healthcare systems." },
],
});
console.log(response.choices[0].message.content);
console.log(response.citations ?? []);Responses API migration pattern
response = client.responses.create(
model=os.getenv("AVALAI_RESPONSES_MODEL", "gpt-5.5"),
reasoning={"effort": "high"},
instructions="Write a concise, source-aware research brief.",
input="Create a sourced brief on AI adoption in healthcare systems.",
store=False,
)
print(response.output_text)const response = await client.responses.create({
model: process.env.AVALAI_RESPONSES_MODEL ?? "gpt-5.5",
reasoning: { effort: "high" },
instructions: "Write a concise, source-aware research brief.",
input: "Create a sourced brief on AI adoption in healthcare systems.",
store: false,
});
console.log(response.output_text);curl https://api.avalai.ir/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AVALAI_API_KEY" \
-d '{
"model": "gpt-5.5",
"reasoning": {"effort": "high"},
"instructions": "Write a concise, source-aware research brief.",
"input": "Create a sourced brief on AI adoption in healthcare systems.",
"store": false
}'For true Perplexity deep-research citations, keep the native Chat Completions request. Use Responses when your workflow needs Responses state, tools, or output_text handling on a supported model.
Direct Search API Without LLM
Use perplexity-search with v1/search when you want search results and snippets without model-generated prose.
Request Option 1: Tool In URL
curl "https://api.avalai.ir/v1/search/perplexity-search?q=latest%20AI%20research" \
-H "Authorization: Bearer $AVALAI_API_KEY"Request Option 2: Tool In Body
curl https://api.avalai.ir/v1/search \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $AVALAI_API_KEY" \
-d '{
"tool": "perplexity-search",
"query": "latest AI research"
}'Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
tool | string | Yes | Use perplexity-search when calling /v1/search with a JSON body. |
query or q | string | Yes | Search query text. |
search_context_size | string | No | Optional search depth such as low, medium, or high when supported. |
Implementation Notes
- Log
citations,search_results,usage, andx-request-idfor debugging and cost review. - Treat live-search answers as time-sensitive; re-run important queries before showing stale information.
- For strict privacy workflows, review the data sent to search providers and avoid including secrets, credentials, or unrelated PII.
- For Responses migrations, confirm the selected model supports
/v1/responses; not every provider/model exposes the same feature set.