Skip to main content

Get your Perplexity API Key

Navigate to the API Keys tab in the API Portal and generate a new key.

Why Use the Agent API?

Multi-Provider Access

Access OpenAI, Anthropic, Google, xAI, and more through one unified API, no need to manage multiple API keys.

Transparent Pricing

See exact token counts and costs per request, no markup, just direct provider pricing.

Granular Control

Change models, reasoning, tokens, and tools with consistent syntax.
We recommend using our official SDKs for a more convenient and type-safe way to interact with the Agent API.

Installation

Install the SDK for your preferred language:

Authentication

Set your API key as an environment variable. The SDK will automatically read it:
All SDK examples below automatically use the PERPLEXITY_API_KEY environment variable. You can also pass the key explicitly if needed.

Basic Usage

Convenience Property: Both Python and Typescript SDKs provide an output_text property that aggregates all text content from response outputs. Instead of iterating through response.output, simply use response.output_text for cleaner code.

Using a Third-Party Model

Use third-party models from OpenAI, Anthropic, Google, xAI, and other providers for specific capabilities:

Using a Preset

Presets provide optimized defaults for specific use cases. Start with a preset for quick setup:
Learn more about presets to explore pre-configured setups optimized for different use cases with specific models, token limits, and tool access.
The Agent API provides access to a number of tools that can be used to extend the capabilities of the model. Enable web search capabilities using the web_search tool:

Next Steps

Tools

Use web search, URL fetching, and function calling to extend model capabilities.

Models

Browse available models and pricing across all supported providers.

Presets

Explore pre-configured setups for common use cases like pro-search and deep-research.

Output Control

Configure streaming responses and structured outputs with JSON schema.

Model Fallback

Specify multiple models for automatic failover and higher availability.

Prompt Guide

Best practices for effective prompting with web search models.

Search Filters

Control search results with domain, date, and location filters.

API Reference

View complete endpoint documentation and parameters.
Need help? Check out our community for support and discussions with other developers.