Perplexity Releases Sonar
AI is getting better every week with new information. But accuracy is getting more and more important. This is why Perplexity has released Sonar and Sonar Pro API where the user can build their own generative search capabilities. Its best for companies looking to integrate lightweight question and answer features that are optimized for speed.
How to use the Sonar API: Start by visiting the API registration page and adding credits.
Then you can go ahead and make your first API call using cURL.
curl --location 'https://api.perplexity.ai/chat/completions' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'Authorization: Bearer {API_KEY}' \
--data '{
"model": "sonar-pro ",
"messages": [
{
"role": "system",
"content": "Be precise and concise."
},
{
"role": "user",
"content": "How many stars are there in our galaxy?"
}
]
}'
or alternatively using Python.
from openai import OpenAI
YOUR_API_KEY = "INSERT API KEY HERE"
messages = [
{
"role": "system",
"content": (
"You are an artificial intelligence assistant and you need to "
"engage in a helpful, detailed, polite conversation with a user."
),
},
{
"role": "user",
"content": (
"How many stars are in the universe?"
),
},
]
client = OpenAI(api_key=YOUR_API_KEY, base_url="https://api.perplexity.ai")
# chat completion without streaming
response = client.chat.completions.create(
model="sonar-pro",
messages=messages,
)
print(response)
# chat completion with streaming
response_stream = client.chat.completions.create(
model="sonar-pro",
messages=messages,
stream=True,
)
for response in response_stream:
print(response)
Models Supported
Sonar provides four models: sonar-reasoning pro which has a context length of 127k tokens, sonar-reasoning also with 127k, sonar-pro with 200k, and sonar regular with 127k.
Pricing
Sonar’s pricing is comparable to open AI, albeit a small bit cheaper.
Sonar’s reasoning model is powered by DeepSeek, most likely due to its cost-effectiveness.
Businesses of all varieties do a ton of online research, Sonar will unlock the capability to automate much of this process, at more accurate levels than we have ever seen before.
As models perform more reasoning at the time the user prompts the LLM, the amount of tokens require increases quadratically, which is why it is so important to keep the cost of compute as low as possible.
“While most generative AI features today have answers informed only by training data, this limits their capabilities,” Perplexity wrote in a blog post. “To optimize for factuality and authority, APIs require a real-time connection to the Internet, with answers informed by trusted sources.”
The real differentiator of this model is its real-time internet searches. Sonar has even outperformed GPT 4o and Claude on some tasks.
How to leverage Sonar?
Sonar supports structured outputs using JSON Schema. You can specify the desired output format in the response_format
field of the API request. Using the Perplexity API, developers can seamlessly incorporate these capabilities, providing users with accurate and up-to-date information tailored to their needs.
Thank you for reading. I hope this article brought you value and inspiration for your next project. To connect with me, please visit me on LinkedIn, or subscribe to my website.