Overview
The Perplexity API provides three core APIs for different use cases: Chat Completions for web-grounded AI responses with Sonar models, Agentic Research for accessing OpenAI, Anthropic, Google, and xAI models with unified search tools and transparent pricing, and Search for ranked web search results. All APIs support both REST and SDK access with streaming, filtering, and advanced controls.Available APIs
Chat Completions
Web-grounded AI responses with citations, conversation context, and streaming support.
Agentic Research
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.
Choosing the Right API
Use the Chat Completions API when...
Use the Chat Completions API when...
- You want Perplexity’s Sonar models optimized for research and Q&A
- You need built-in citations and conversation context
- You prefer simplicity—just send a message and get a researched answer
Use the Agentic Research API when...
Use the Agentic Research API when...
- You need multi-provider access to OpenAI, Anthropic, Google, and more models through one API
- You want granular control over model selection, reasoning, token budgets, and tools
- You want presets for common use configurations or full customization for advanced workflows
Use the Search API when...
Use the Search API when...
- 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
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 set up an API group.
Installation
Install the SDK for your preferred language:Authentication
Set your API key as an environment variable:- macOS/Linux
- Windows
.env file in your project:
.env
OpenAI SDK Compatible: Perplexity’s API supports the OpenAI Chat Completions format. You can use OpenAI client libraries by pointing to our endpoint. See our OpenAI Compatibility Guide for examples.
Making Your First API Call
Choose your API based on your use case:- Agentic Research API
- Chat Completions API
Use for third-party models with web search tools and presets:
Example Response
Example Response
The response includes structured output with tool usage and citations:
Streaming Responses
Enable streaming for real-time output with either API:- Agentic Research API
- Chat Completions 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:Chat Completions API
Get started with web-grounded AI responses
Agentic Research API
Get started with third-party models and presets
Search API
Get started with web search results
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.