Overview

The official Perplexity SDKs provide convenient access to the Perplexity APIs from Python 3.8+ and Node.js applications. Both SDKs include type definitions for all request parameters and response fields, with both synchronous and asynchronous clients.

Available APIs

Installation

Install the SDK for your preferred language:
pip install perplexityai

Authentication

Get your Perplexity API Key

Navigate to the API Keys tab in the API Portal and generate a new key.
After generating the key, set it as an environment variable in your terminal:
setx PERPLEXITY_API_KEY "your_api_key_here"

Using Environment Variables

You can use the environment variable directly:
import os
from perplexity import Perplexity

client = Perplexity() # Automatically uses PERPLEXITY_API_KEY
Or use python-dotenv (Python) or dotenv (Node.js) to load the environment variable from a .env file:
import os
from dotenv import load_dotenv
from perplexity import Perplexity

load_dotenv()

client = Perplexity() # Uses PERPLEXITY_API_KEY from .env file
Now you’re ready to start using the Perplexity APIs! Choose your API below for step-by-step usage guides.

Resources