Skip to main content
This guide shows how to use Perplexity’s Agent API as a unified gateway to models from OpenAI, Anthropic, Google, xAI, and Perplexity — all through a single API key with zero markup. You will learn how to route to specific providers, build fallback chains for high availability, compare responses across models, and dynamically discover available models via the /v1/models endpoint.
Perplexity passes through third-party model usage at cost with no markup. You pay only what the provider charges, consolidated on a single bill. See Agent API Models for the full list.

Prerequisites

Install the Perplexity SDK:
If you don’t have an API key yet:

Get your Perplexity API Key

Navigate to the API Keys tab in the API Portal and generate a new key.
Then export your API key as an environment variable:

Why Multi-Provider?

Available Models

Use the /v1/models endpoint to discover all available models dynamically.
Key models across providers:

Routing to a Specific Provider

Use the model parameter to target a specific provider’s model.

Model Fallback Chains

The models parameter accepts an array of up to 5 models. The API tries each in order and returns the first successful response. This is ideal for production systems where availability matters.
Order your fallback chain by preference: put your primary model first, then alternatives in decreasing order of preference. The API returns the response from the first model that succeeds.

Comparing Responses Across Providers

Send the same prompt to multiple models and compare quality, latency, and cost.

Task-Based Model Routing

Different tasks suit different models. Build a router that picks the best model for each task type.

Combining Multi-Provider with Tools

All models accessed through the Agent API support the same tool interface — web_search, fetch_url, and custom functions work identically regardless of provider.

Dynamic Model Discovery

Build applications that automatically adapt to newly available models by querying the /v1/models endpoint at startup.
The /v1/models endpoint returns the current list of supported models. Query it at application startup or cache it with a TTL to stay current as new models are added.

Next Steps

Agent API Models

Full list of available models, capabilities, and pricing.

Model Fallback

Deep dive into fallback chain configuration and behavior.

Model Comparison Example

CLI tool for benchmarking models side-by-side.

Presets

Use presets like low for optimized defaults.