Skip to main content

Overview

LiteLLM is a Python SDK and proxy server that gives you a single OpenAI-compatible interface to 100+ LLM providers. Both Perplexity’s Sonar models and the Agent API (with third-party models like GPT-5, Claude, and Gemini routed through Perplexity) are first-class providers in LiteLLM.
LiteLLM lets you swap providers without rewriting code, run a self-hosted proxy that fronts every model behind one API key, and track spend, latency, and errors per provider. Learn more at litellm.ai.

Installation

API Key Setup

LiteLLM uses two environment variables depending on which Perplexity endpoint you’re calling:
In practice, set both to the same key.

Get API Key

Generate your Perplexity API key from the API portal.

Sonar Chat Completions

Call Perplexity’s Sonar models through litellm.completion with the perplexity/ model prefix:

Streaming

Reasoning Effort

For reasoning-capable Sonar models, pass reasoning_effort to control depth:

Supported Sonar Models

Agent API

Use litellm.responses to call the Agent API, which routes through Perplexity to third-party models with tool orchestration and presets.

Presets

Available presets: fast, low, medium, high, xhigh.

Tool Use (web_search and fetch_url)

Structured Outputs

Supported Third-Party Models via Agent API

See the Agent API model list for the canonical, up-to-date catalogue.

LiteLLM Proxy

Run LiteLLM as a self-hosted proxy that fronts Perplexity (and any other provider) behind a single OpenAI-compatible endpoint.

config.yaml

Start the Proxy

Call the Proxy

LiteLLM Perplexity Docs

Official LiteLLM Perplexity provider docs.

LiteLLM Docs

Full LiteLLM documentation.

Perplexity Agent API

Agent API reference and presets.

Perplexity Models

Available Sonar and Agent API models.

Support

Need help with the integration?