sonar

circle-info

This documentation is valid for the following list of our models:

  • perplexity/sonar

Model Overview

A model built on top of Llama 3.3 70B and optimized for Perplexity search. Fast, cost-effective, everyday search and Q&A. Ideal for simple queries, topic summaries, and fact-checking.

chevron-rightHow to make the first API callhashtag

1️⃣ Required setup (don’t skip this)Create an account: Sign up on the AI/ML API website (if you don’t have one yet). ▪ Generate an API key: In your account dashboard, create an API key and make sure it’s enabled in the UI.

2️ Copy the code example At the bottom of this page, pick the snippet for your preferred programming language (Python / Node.js) and copy it into your project.

3️ Update the snippet for your use caseInsert your API key: replace <YOUR_AIMLAPI_KEY> with your real AI/ML API key. ▪ Select a model: set the model field to the model you want to call. ▪ Provide input: fill in the request input field(s) shown in the example (for example, messages for chat/LLM models, or other inputs for image/video/audio models).

4️ (Optional) Tune the request Depending on the model type, you can add optional parameters to control the output (e.g., generation settings, quality, length, etc.). See the API schema below for the full list.

5️ Run your code Run the updated code in your development environment. Response time depends on the model and request size, but simple requests typically return quickly.

circle-check

API Schema

post
Body
modelstring · enumRequiredPossible values:
max_tokensnumber · min: 1Optional

The maximum number of tokens that can be generated in the chat completion. This value can be used to control costs for text generated via API.

streambooleanOptional

If set to True, the model response data will be streamed to the client as it is generated using server-sent events.

Default: false
temperaturenumber · max: 2Optional

What sampling temperature to use. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p but not both.

top_pnumber · min: 0.01 · max: 1Optional

An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.

frequency_penaltynumber · min: -2 · max: 2 · nullableOptional

Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.

presence_penaltynumber · min: -2 · max: 2 · nullableOptional

Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.

seedinteger · min: 1Optional

This feature is in Beta. If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result.

response_formatone ofOptional

An object specifying the format that the model must output.

or
or
top_knumberOptional

Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. Recommended for advanced use cases only. You usually only need to use temperature.

search_modestring · enumOptional

Controls the search mode used for the request. When set to 'academic', results will prioritize scholarly sources like peer-reviewed papers and academic journals.

Default: academicPossible values:
search_domain_filterstring[]Optional

A list of domains to limit search results to. Currently limited to 10 domains for Allowlisting and Denylisting. For Denylisting, add a - at the beginning of the domain string.

return_imagesbooleanOptional

Determines whether search results should include images.

Default: false
return_related_questionsbooleanOptional

Determines whether related questions should be returned.

Default: false
search_recency_filterstring · enumOptional

Filters search results based on time (e.g., 'week', 'day').

Possible values:
search_after_date_filterstringOptional

Filters search results to only include content published after this date. Format should be %m/%d/%Y (e.g. 3/1/2025)

Pattern: ^(0?[1-9]|1[0-2])\/(0?[1-9]|[12]\d|3[01])\/\d{4}$
search_before_date_filterstringOptional

Filters search results to only include content published before this date. Format should be %m/%d/%Y (e.g. 3/1/2025)

Pattern: ^(0?[1-9]|1[0-2])\/(0?[1-9]|[12]\d|3[01])\/\d{4}$
last_updated_after_filterstringOptional

Filters search results to only include content last updated after this date. Format should be %m/%d/%Y (e.g. 3/1/2025)

Pattern: ^(0?[1-9]|1[0-2])\/(0?[1-9]|[12]\d|3[01])\/\d{4}$
last_updated_before_filterstringOptional

Filters search results to only include content last updated before this date. Format should be %m/%d/%Y (e.g. 3/1/2025)

Pattern: ^(0?[1-9]|1[0-2])\/(0?[1-9]|[12]\d|3[01])\/\d{4}$
Responses
chevron-right
200Success
idstringRequired

A unique identifier for the chat completion.

Example: chatcmpl-CQ9FPg3osank0dx0k46Z53LTqtXMl
objectstring · enumRequired

The object type.

Example: chat.completionPossible values:
creatednumberRequired

The Unix timestamp (in seconds) of when the chat completion was created.

Example: 1762343744
modelstringRequired

The model used for the chat completion.

Example: perplexity/sonar
post
/v1/chat/completions
200Success

Code Example

chevron-rightResponsehashtag

Last updated

Was this helpful?