POST
/
chat
/
completions
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": "Be precise and concise."
    },
    {
      "role": "user",
      "content": "How many stars are there in our galaxy?"
    }
  ],
  "max_tokens": 123,
  "temperature": 0.2,
  "top_p": 0.9,
  "search_domain_filter": [
    "<any>"
  ],
  "return_images": false,
  "return_related_questions": false,
  "search_recency_filter": "<string>",
  "top_k": 0,
  "stream": false,
  "presence_penalty": 0,
  "frequency_penalty": 1,
  "response_format": {},
  "web_search_options": {
    "search_context_size": "high"
  }
}'
"<any>"

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json
model
string
required

The name of the model that will complete your prompt. Refer to Supported Models to find all the models offered.

Example:

"sonar"

messages
object[]
required

A list of messages comprising the conversation so far.

Example:
[
  {
    "role": "system",
    "content": "Be precise and concise."
  },
  {
    "role": "user",
    "content": "How many stars are there in our galaxy?"
  }
]
max_tokens
integer

The maximum number of completion tokens returned by the API.

temperature
number
default:0.2

The amount of randomness in the response, valued between 0 and 2.

Required range: 0 <= x < 2
top_p
number
default:0.9

The nucleus sampling threshold, valued between 0 and 1.

search_domain_filter
any[]

A list of domains to limit search results to.

return_images
boolean
default:false

Determines whether search results should include images.

Determines whether related questions should be returned.

search_recency_filter
string

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

top_k
number
default:0

The number of tokens to keep for top-k filtering.

stream
boolean
default:false

Determines whether to stream the response incrementally.

presence_penalty
number
default:0

Positive values increase the likelihood of discussing new topics.

frequency_penalty
number
default:1

Decreases likelihood of repetition based on prior frequency.

response_format
object

Enables structured JSON output formatting.

web_search_options
object

Configuration for using web search in model responses.

Example:
{ "search_context_size": "high" }

Response

200
application/json
OK

The response is of type any.