Quickstart
Learn how to use the official Perplexity SDKs for Python and TypeScript to access the Perplexity APIs with type safety and async support.
Overview
Section titled “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
Section titled “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
Section titled “Installation”Install the SDK for your preferred language:
pip install perplexityainpm install @perplexity-ai/perplexity_aiAuthentication
Section titled “Authentication”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:
setx PERPLEXITY_API_KEY "your_api_key_here"export PERPLEXITY_API_KEY="your_api_key_here"Using Environment Variables
Section titled “Using Environment Variables”You can use the environment variable directly:
import os
from perplexity import Perplexity
client = Perplexity() # Automatically uses PERPLEXITY_API_KEYimport 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:
import os
from dotenv import load_dotenv
from perplexity import Perplexity
load_dotenv()
client = Perplexity() # Uses PERPLEXITY_API_KEY from .env fileimport Perplexity from '@perplexity-ai/perplexity_ai';
import dotenv from 'dotenv';
dotenv.config();
const client = new Perplexity(); // Uses PERPLEXITY_API_KEY from .env fileAgent API
Get started with third-party models
Search
Get started with web search
Embeddings
Get started with text embeddings