Skip to main content

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. 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.

Available APIs

Agent API

Third-party models from OpenAI, Anthropic, Google, and more with presets and web search tools.

Search

Ranked web search results with filtering, multi-query support, and domain controls.

Embeddings

Generate high-quality text embeddings for semantic search and RAG.

Installation

Install the SDK for your preferred language:

Authentication

Get your Perplexity API Key

Generate a new key on the API Keys page in the API Console.
After generating the key, set it as an environment variable in your terminal:

Using Environment Variables

You can use the environment variable directly:
Or use python-dotenv (Python) or dotenv (Node.js) to load the environment variable from a .env file:
Now you’re ready to start using the Perplexity APIs! Choose your API below for step-by-step usage guides.

Agent API

Get started with third-party models

Search

Get started with web search

Embeddings

Get started with text embeddings

Resources

Python Package

Install from PyPI with pip

Node.js and TypeScript Package

Install from npm registry