Skip to main content

Generating an API Key

Get your Perplexity API Key

Navigate to the API Keys tab in the API Portal and generate a new key.
See the API Groups page to learn more about API groups.

Pricing

Pay-as-you-go pricing for all APIs. No subscription required.

Overview

The Perplexity API provides three core APIs for different use cases: Agent API for web-grounded AI responses with access to OpenAI, Anthropic, Google, and xAI models, unified search tools, and transparent pricing, Search for ranked web search results, and Embeddings for generating text embeddings. All APIs support both REST and SDK access with streaming, filtering, and advanced controls.

Available APIs

Agent API

Web-grounded answers with built-in citations, plus multi-provider models (OpenAI, Anthropic, Google, xAI), presets, and web search tools.

Search

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

Sonar

Web-grounded AI responses. In maintenance mode; new projects should prefer the Agent API.

Embeddings

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

Choosing the Right API

  • You want web-grounded answers with built-in citations - send a message and get a researched, cited response, with conversation context when you need it
  • You prefer simplicity: pick a preset and get a researched answer in one call, or take granular control over model, reasoning, token budgets, and tools
  • You need multi-provider access to OpenAI, Anthropic, Google, xAI, and Perplexity’s own Sonar model through one API
Best for: AI assistants, research and Q&A tools, agentic workflows, custom AI applications
  • You need raw search results without LLM processing
  • You want to build custom AI workflows with your own models
  • You need search data for indexing, analysis, or training
Best for: Custom AI pipelines, data collection, search integration
Sonar is in maintenance mode. New projects should prefer the Agent API, which also returns web-grounded answers with citations - see the migration guide.
  • You need semantic similarity between texts for search or recommendations
  • You’re building RAG pipelines that require vector representations of documents
  • You need to cluster, classify, or compare text without generating a response
Best for: Semantic search, RAG applications, text classification, recommendation systems

Installation

Install the SDK for your preferred language:

Authentication

Set your API key as an environment variable:
OpenAI SDK Compatible: Perplexity’s API supports the OpenAI Chat Completions format. You can use OpenAI client libraries by pointing to our endpoint. See the OpenAI Compatibility Guide for examples.

Making Your First API Call

Choose your API based on your use case:
Use for third-party models with web search tools and presets:
The response includes structured output with tool usage and citations:

Streaming Responses

Enable streaming for real-time output with either API:
For a full guide on streaming, including parsing, error handling, citation management, and best practices, see our streaming guide.

Next Steps

Now that you’ve made your first API call, explore each API in depth:

Agent API

Get started with third-party models and presets

Search API

Get started with web search results

Sonar API

Get started with web-grounded AI responses

Embeddings API

Get started with text embeddings

Additional Resources

Perplexity SDK

Learn about the official Perplexity SDK with type safety and async support

Models

Explore available models and their capabilities

API Reference

View complete API documentation with detailed endpoint specifications

Examples

Explore code examples, tutorials, and integration patterns
Need help? Check out our community for support and discussions with other developers.