Skip to main content
POST
/
chat
/
completions
Create Chat Completion
curl --request POST \
  --url https://api.perplexity.ai/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "<string>",
  "messages": [
    {
      "role": "system",
      "content": "<string>"
    }
  ]
}
'
{
  "id": "<string>",
  "model": "<string>",
  "created": 123,
  "choices": [
    {
      "index": 123,
      "message": {
        "role": "system",
        "content": "<string>",
        "reasoning_steps": [
          {
            "thought": "<string>",
            "type": "<string>",
            "web_search": {
              "search_results": [
                {
                  "title": "<string>",
                  "url": "<string>",
                  "date": "<string>",
                  "last_updated": "<string>",
                  "snippet": "",
                  "source": "web"
                }
              ],
              "search_keywords": [
                "<string>"
              ]
            },
            "fetch_url_content": {
              "contents": [
                {
                  "title": "<string>",
                  "url": "<string>",
                  "date": "<string>",
                  "last_updated": "<string>",
                  "snippet": "",
                  "source": "web"
                }
              ]
            },
            "execute_python": {
              "code": "<string>",
              "result": "<string>"
            }
          }
        ],
        "tool_calls": [
          {
            "id": "<string>",
            "type": "<string>",
            "function": {
              "name": "<string>",
              "arguments": "<string>"
            }
          }
        ],
        "tool_call_id": "<string>"
      },
      "delta": {
        "role": "system",
        "content": "<string>",
        "reasoning_steps": [
          {
            "thought": "<string>",
            "type": "<string>",
            "web_search": {
              "search_results": [
                {
                  "title": "<string>",
                  "url": "<string>",
                  "date": "<string>",
                  "last_updated": "<string>",
                  "snippet": "",
                  "source": "web"
                }
              ],
              "search_keywords": [
                "<string>"
              ]
            },
            "fetch_url_content": {
              "contents": [
                {
                  "title": "<string>",
                  "url": "<string>",
                  "date": "<string>",
                  "last_updated": "<string>",
                  "snippet": "",
                  "source": "web"
                }
              ]
            },
            "execute_python": {
              "code": "<string>",
              "result": "<string>"
            }
          }
        ],
        "tool_calls": [
          {
            "id": "<string>",
            "type": "<string>",
            "function": {
              "name": "<string>",
              "arguments": "<string>"
            }
          }
        ],
        "tool_call_id": "<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"
    }
  ],
  "type": "message",
  "status": "PENDING"
}

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
messages
ChatMessage · object[]
required
max_tokens
integer | null
Required range: 0 < x <= 128000
stream
boolean | null
default:false
stop
response_format
ResponseFormatText · object

Optional. Controls the output format. Omit for default text output. Set type to json_schema for structured output.

web_search_options
WebSearchOptions · object
search_mode
enum<string> | null
Available options:
web,
academic,
sec
return_images
boolean | null
enable_search_classifier
boolean | null
disable_search
boolean | null
search_domain_filter
string[] | null
search_language_filter
string[] | null
search_recency_filter
enum<string> | null
Available options:
hour,
day,
week,
month,
year
search_after_date_filter
string | null
search_before_date_filter
string | null
last_updated_before_filter
string | null
last_updated_after_filter
string | null
image_format_filter
string[] | null
image_domain_filter
string[] | null
safe_search
boolean | null
default:true
stream_mode
enum<string>
default:full
Available options:
full,
concise
reasoning_effort
enum<string> | null
Available options:
minimal,
low,
medium,
high
language_preference
string | null

Response

Successful Response

id
string
required
model
string
required
created
integer
required
choices
Choice · object[]
required
usage
UsageInfo · object
object
string
default:chat.completion
citations
string[] | null
search_results
ApiPublicSearchResult · object[] | null
type
enum<string> | null
Available options:
message,
info,
end_of_stream
status
enum<string> | null
Available options:
PENDING,
COMPLETED