Perplexity AI's Sonar API: Real-Time Answers with Citations
Perplexity AI has unveiled its Sonar API, a powerful tool delivering real-time, accurate, and citation-backed answers for AI applications. Unlike traditional models limited to pre-trained data, Sonar directly accesses the internet, guaranteeing responses reflect the most current information. This article explores its key features, advantages, and enhanced capabilities for Pro subscribers.
Introducing Sonar: Perplexity's API.
Sonar is the most affordable search API product on the market. Use it to build generative search, powered by real-time information and citations, into your apps. We’re also offering a Pro version with deeper functionality. pic.twitter.com/CWpVUUKYtW
— Perplexity (@perplexity_ai) January 21, 2025
The Sonar API is a versatile solution handling diverse queries, from simple questions to intricate multi-step research. Its real-time web connectivity, citation provision, and customizable search filters make it ideal for applications prioritizing accuracy and factual integrity.
from openai import OpenAI client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.perplexity.ai") response = client.chat.completions.create( model="sonar", messages=[ {"role": "system", "content": "Be precise and concise."}, {"role": "user", "content": "How many stars are in the Milky Way?"} ] ) print(response)
Time needed: 1 minute
Getting started is straightforward:
Sign-up: Register and obtain an API key via the Perplexity API documentation.
Payment Information: Provide your payment details to activate API access.
API Key Generation: Generate your API key.
A curl
example:
from openai import OpenAI client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.perplexity.ai") response = client.chat.completions.create( model="sonar", messages=[ {"role": "system", "content": "Be precise and concise."}, {"role": "user", "content": "How many stars are in the Milky Way?"} ] ) print(response)
Further Python examples demonstrating both streaming and non-streaming responses are provided in the original article.
Sonar API finds applications in various fields:
Tips for optimal API usage include managing rate limits, strategically utilizing search_domain_filter
, debugging effectively, and optimizing performance through streaming and JSON mode.
Perplexity's Pro subscription unlocks advanced features:
Feature | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Handles longer, more detailed queries. | ||||||||||||
Double the Citations | Provides more citations per search. | ||||||||||||
Advanced Search Filters | More granular control over search parameters. | ||||||||||||
Higher Usage Limits | Increased query limits. | ||||||||||||
Priority Support | Faster customer support. |
The above is the detailed content of Perplexity Sonar API: Reliable, Scalable, and Developer-Friendly. For more information, please follow other related articles on the PHP Chinese website!