Perplexity AI Python SDK

0.30.1 · active · verified Sat Feb 28

Official Python SDK for the Perplexity API — web-grounded chat completions with real-time search, citations, and reasoning.

Warnings

Install

Imports

Quickstart

Web-grounded chat completion with citations

from perplexity import Perplexity

client = Perplexity()  # reads PERPLEXITY_API_KEY automatically

response = client.chat.completions.create(
    model='sonar',
    messages=[{'role': 'user', 'content': 'What happened in AI this week?'}]
)
print(response.choices[0].message.content)

view raw JSON →