Skip to main content
Perplexity

Search documentation

Type to search this documentation.

On this pageOverview

Quickstart

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.

Access three APIs: Agent API for third-party models with web search tools and presets, Search for ranked web search results, and Embeddings for generating text embeddings.

Install the SDK for your preferred language:

Python
pip install perplexityai
TypeScript
npm install @perplexity-ai/perplexity_ai

Get your Perplexity API Key

Generate a new key on the API Keys page in the API Console.

Click here

After generating the key, set it as an environment variable in your terminal:

Bash
setx PERPLEXITY_API_KEY "your_api_key_here"
Bash
export PERPLEXITY_API_KEY="your_api_key_here"

You can use the environment variable directly:

Python
import os
from perplexity import Perplexity

client = Perplexity() # Automatically uses PERPLEXITY_API_KEY
TypeScript
import Perplexity from '@perplexity-ai/perplexity_ai';

const client = new Perplexity({
  apiKey: process.env['PERPLEXITY_API_KEY'], // This is the default and can be omitted
});

Or use python-dotenv (Python) or dotenv (Node.js) to load the environment variable from a .env file:

Python
import os
from dotenv import load_dotenv
from perplexity import Perplexity

load_dotenv()

client = Perplexity() # Uses PERPLEXITY_API_KEY from .env file
TypeScript
import Perplexity from '@perplexity-ai/perplexity_ai';
import dotenv from 'dotenv';

dotenv.config();

const client = new Perplexity(); // Uses PERPLEXITY_API_KEY from .env file
Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu