curl --request POST \
--url https://api.perplexity.ai/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "sonar",
"messages": [
{
"role": "system",
"content": "<string>"
}
]
}
'{
"id": "<string>",
"model": "<string>",
"created": 123,
"choices": [
{
"index": 123,
"message": {
"role": "system",
"content": "<string>"
},
"delta": {
"role": "system",
"content": "<string>"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"cost": {
"input_tokens_cost": 123,
"output_tokens_cost": 123,
"total_cost": 123,
"reasoning_tokens_cost": 123,
"request_cost": 123,
"citation_tokens_cost": 123,
"search_queries_cost": 123
},
"search_context_size": "<string>",
"citation_tokens": 123,
"num_search_queries": 123,
"reasoning_tokens": 123
},
"object": "chat.completion",
"citations": [
"<string>"
],
"search_results": [
{
"title": "<string>",
"url": "<string>",
"date": "<string>",
"last_updated": "<string>",
"snippet": "",
"source": "web"
}
],
"images": [
{
"image_url": "<string>",
"origin_url": "<string>",
"title": "<string>",
"width": 123,
"height": 123
}
],
"related_questions": [
"<string>"
]
}Generate a chat completion response for the given conversation.
curl --request POST \
--url https://api.perplexity.ai/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "sonar",
"messages": [
{
"role": "system",
"content": "<string>"
}
]
}
'{
"id": "<string>",
"model": "<string>",
"created": 123,
"choices": [
{
"index": 123,
"message": {
"role": "system",
"content": "<string>"
},
"delta": {
"role": "system",
"content": "<string>"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123,
"cost": {
"input_tokens_cost": 123,
"output_tokens_cost": 123,
"total_cost": 123,
"reasoning_tokens_cost": 123,
"request_cost": 123,
"citation_tokens_cost": 123,
"search_queries_cost": 123
},
"search_context_size": "<string>",
"citation_tokens": 123,
"num_search_queries": 123,
"reasoning_tokens": 123
},
"object": "chat.completion",
"citations": [
"<string>"
],
"search_results": [
{
"title": "<string>",
"url": "<string>",
"date": "<string>",
"last_updated": "<string>",
"snippet": "",
"source": "web"
}
],
"images": [
{
"image_url": "<string>",
"origin_url": "<string>",
"title": "<string>",
"width": 123,
"height": 123
}
],
"related_questions": [
"<string>"
]
}Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Model to use, for example, sonar-pro
sonar, sonar-pro, sonar-deep-research, sonar-reasoning-pro Array of messages forming the conversation history
Show child attributes
Maximum number of completion tokens to generate
0 < x <= 128000If true, returns streaming SSE response
Stop sequences. Generation stops when one of these strings is produced
Controls randomness in the response. Higher values make output more random. Range: 0-2
0 <= x <= 2Nucleus sampling parameter. Controls diversity via nucleus sampling
0 <= x <= 1Optional. Controls the output format. Omit for default text output. Set type to json_schema for structured output.
Show child attributes
Configuration options for web search behavior
Show child attributes
Source of search results (web, academic, or sec)
web, academic, sec When true, include image results in the response
When true, generates suggested follow-up queries based on the search results
When true, uses a classifier to determine if web search is needed for the query
When true, disables all web search capabilities. The model responds based solely on its training data
Limit search results to specific domains (e.g. github.com, wikipedia.org)
Filter results by language using ISO 639-1 codes (e.g. en, fr, de)
Filter by publication recency (hour, day, week, month, or year)
hour, day, week, month, year Return results published after this date (MM/DD/YYYY)
Return results published before this date (MM/DD/YYYY)
Return results last updated before this date (MM/DD/YYYY)
Return results last updated after this date (MM/DD/YYYY)
Filter image results by format (e.g. png, jpg)
Limit image results to specific domains
Controls the format of streaming events. 'full' suppresses reasoning events and includes metadata inline; 'concise' emits reasoning events separately
full, concise Controls how much effort the model spends on reasoning
minimal, low, medium, high ISO 639-1 language code for preferred response language
Successful Response
Unique identifier for the completion
Model used for generation
Unix timestamp when the completion was created
Array of completion choices
Show child attributes
Token usage and cost information for a request
Show child attributes
Object type identifier
URLs of sources used to generate the response
Search results used for context in the response
Show child attributes
Array of images returned when return_images is true
Show child attributes
Array of related questions returned when return_related_questions is true
Was this page helpful?
Suggestions