curl --request POST \
--url https://api.perplexity.ai/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "sonar-deep-research",
"messages": [
{
"role": "system",
"content": "Be precise and concise."
},
{
"role": "user",
"content": "How many stars are there in our galaxy?"
}
],
"search_mode": "web",
"reasoning_effort": "low",
"max_tokens": 123,
"temperature": 0.2,
"top_p": 0.9,
"language_preference": "<string>",
"search_domain_filter": "<array>",
"return_images": false,
"return_related_questions": false,
"search_recency_filter": "<string>",
"search_after_date_filter": "<string>",
"search_before_date_filter": "<string>",
"last_updated_after_filter": "<string>",
"last_updated_before_filter": "<string>",
"top_k": 0,
"stream": false,
"presence_penalty": 0,
"frequency_penalty": 0,
"response_format": {},
"disable_search": false,
"enable_search_classifier": false,
"web_search_options": {
"search_context_size": "high"
},
"media_response": {
"overrides": {
"return_videos": true,
"return_images": true
}
}
}
'{
"id": "<string>",
"model": "<string>",
"created": 123,
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"search_context_size": "<string>",
"citation_tokens": 123,
"num_search_queries": 123,
"reasoning_tokens": 123
},
"object": "chat.completion",
"choices": [
{
"index": 123,
"message": {
"content": "<string>",
"role": "system"
},
"finish_reason": "stop"
}
],
"search_results": [
{
"title": "<string>",
"url": "<string>",
"date": "2023-12-25"
}
],
"videos": [
{
"url": "<string>",
"thumbnail_url": "<string>",
"thumbnail_width": 123,
"thumbnail_height": 123,
"duration": 123
}
]
}Generates a model’s response for the given chat conversation.
curl --request POST \
--url https://api.perplexity.ai/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "sonar-deep-research",
"messages": [
{
"role": "system",
"content": "Be precise and concise."
},
{
"role": "user",
"content": "How many stars are there in our galaxy?"
}
],
"search_mode": "web",
"reasoning_effort": "low",
"max_tokens": 123,
"temperature": 0.2,
"top_p": 0.9,
"language_preference": "<string>",
"search_domain_filter": "<array>",
"return_images": false,
"return_related_questions": false,
"search_recency_filter": "<string>",
"search_after_date_filter": "<string>",
"search_before_date_filter": "<string>",
"last_updated_after_filter": "<string>",
"last_updated_before_filter": "<string>",
"top_k": 0,
"stream": false,
"presence_penalty": 0,
"frequency_penalty": 0,
"response_format": {},
"disable_search": false,
"enable_search_classifier": false,
"web_search_options": {
"search_context_size": "high"
},
"media_response": {
"overrides": {
"return_videos": true,
"return_images": true
}
}
}
'{
"id": "<string>",
"model": "<string>",
"created": 123,
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"search_context_size": "<string>",
"citation_tokens": 123,
"num_search_queries": 123,
"reasoning_tokens": 123
},
"object": "chat.completion",
"choices": [
{
"index": 123,
"message": {
"content": "<string>",
"role": "system"
},
"finish_reason": "stop"
}
],
"search_results": [
{
"title": "<string>",
"url": "<string>",
"date": "2023-12-25"
}
],
"videos": [
{
"url": "<string>",
"thumbnail_url": "<string>",
"thumbnail_width": 123,
"thumbnail_height": 123,
"duration": 123
}
]
}Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
The name of the model that will complete your prompt. Choose from our available Sonar models: sonar (lightweight search), sonar-pro (advanced search), sonar-deep-research (exhaustive research), sonar-reasoning (fast reasoning), or sonar-reasoning-pro (premier reasoning).
sonar, sonar-pro, sonar-deep-research, sonar-reasoning, sonar-reasoning-pro "sonar-deep-research"
A list of messages comprising the conversation so far.
[
{
"role": "system",
"content": "Be precise and concise."
},
{
"role": "user",
"content": "How many stars are there in our galaxy?"
}
]Controls search mode: 'academic' prioritizes scholarly sources, 'sec' prioritizes SEC filings, 'web' uses general web search. See academic guide and SEC guide.
academic, sec, web Perplexity-Specific: Controls how much computational effort the AI dedicates to each query for deep research models. 'low' provides faster, simpler answers with reduced token usage, 'medium' offers a balanced approach, and 'high' delivers deeper, more thorough responses with increased token usage. This parameter directly impacts the amount of reasoning tokens consumed. WARNING: This parameter is ONLY applicable for sonar-deep-research. Defaults to 'medium' when used with sonar-deep-research.
low, medium, high OpenAI Compatible: The maximum number of completion tokens returned by the API. Controls the length of the model's response. If the response would exceed this limit, it will be truncated. Higher values allow for longer responses but may increase processing time and costs.
The amount of randomness in the response, valued between 0 and 2. Lower values (e.g., 0.1) make the output more focused, deterministic, and less creative. Higher values (e.g., 1.5) make the output more random and creative. Use lower values for factual/information retrieval tasks and higher values for creative applications.
0 <= x < 2OpenAI Compatible: The nucleus sampling threshold, valued between 0 and 1. Controls the diversity of generated text by considering only the tokens whose cumulative probability exceeds the top_p value. Lower values (e.g., 0.5) make the output more focused and deterministic, while higher values (e.g., 0.95) allow for more diverse outputs. Often used as an alternative to temperature.
Perplexity-Specific: Specifies the preferred language for the chat completion response (i.e., English, Korean, Spanish, etc.) of the response content. This parameter is supported only by the sonar and sonar-pro models. Using it with other models is on a best-effort basis and may not produce consistent results.
Perplexity-Specific: Determines whether search results should include images.
Perplexity-Specific: Determines whether related questions should be returned.
Perplexity-Specific: Filters search results based on time (e.g., 'week', 'day').
Perplexity-Specific: Filters search results to only include content published after this date. Format should be %m/%d/%Y (e.g. 3/1/2025)
Perplexity-Specific: Filters search results to only include content published before this date. Format should be %m/%d/%Y (e.g. 3/1/2025)
Perplexity-Specific: Filters search results to only include content last updated after this date. Format should be %m/%d/%Y (e.g. 3/1/2025)
Perplexity-Specific: Filters search results to only include content last updated before this date. Format should be %m/%d/%Y (e.g. 3/1/2025)
OpenAI Compatible: The number of tokens to keep for top-k filtering. Limits the model to consider only the k most likely next tokens at each step. Lower values (e.g., 20) make the output more focused and deterministic, while higher values allow for more diverse outputs. A value of 0 disables this filter. Often used in conjunction with top_p to control output randomness.
OpenAI Compatible: Determines whether to stream the response incrementally.
OpenAI Compatible: Positive values increase the likelihood of discussing new topics. Applies a penalty to tokens that have already appeared in the text, encouraging the model to talk about new concepts. Values typically range from 0 (no penalty) to 2.0 (strong penalty). Higher values reduce repetition but may lead to more off-topic text.
OpenAI Compatible: Decreases likelihood of repetition based on prior frequency. Applies a penalty to tokens based on how frequently they've appeared in the text so far. Values typically range from 0 (no penalty) to 2.0 (strong penalty). Higher values (e.g., 1.5) reduce repetition of the same words and phrases. Useful for preventing the model from getting stuck in loops.
Enables structured JSON output formatting.
Perplexity-Specific: Configuration for using web search in model responses.
Show child attributes
Determines how much search context is retrieved for the model. Options are: low (minimizes context for cost savings but less comprehensive answers), medium (balanced approach suitable for most queries), and high (maximizes context for comprehensive answers but at higher cost).
low, medium, high To refine search results based on geography, you can specify an approximate user location. For best accuracy, we recommend providing as many fields as possible including city and region.
Show child attributes
The latitude of the user's location.
The longitude of the user's location.
The two letter ISO country code of the user's location.
The region/state/province of the user's location (e.g., 'California', 'Ontario', 'Île-de-France').
The city name of the user's location (e.g., 'San Francisco', 'New York City', 'Paris').
When enabled, improves the relevance of image search results to the user query. Enhanced images will be streamed in later chunks of the response.
{ "search_context_size": "high" }Perplexity-Specific: Configuration for controlling media content in responses, such as videos and images. Use the overrides property to enable specific media types.
Show child attributes
Configuration overrides for controlling specific types of media content in API responses.
Show child attributes
When set to true, enables video content to be returned in the response. Videos will be included as part of the response structure with URL and metadata.
When set to true, enables image content to be returned in the response. This overrides the top-level return_images parameter when used within media_response.overrides.
{
"overrides": {
"return_videos": true,
"return_images": true
}
}OK
A unique identifier for the chat completion.
The model that generated the response.
The Unix timestamp (in seconds) of when the chat completion was created.
The type of object, which is always chat.completion.
A list of chat completion choices. Can be more than one if n is greater than 1.
Show child attributes
stop, length A list of video results when media_response.overrides.return_videos is enabled. Contains video URLs and metadata.
Show child attributes
The URL of the video.
The URL of the video thumbnail image.
The width of the thumbnail image in pixels.
The height of the thumbnail image in pixels.
The duration of the video in seconds.
Was this page helpful?