Perplexity with LiteLLM
Overview
Section titled “Overview”LiteLLM is a Python SDK and proxy server that gives you a single OpenAI-compatible interface to 100+ LLM providers. Perplexity's Agent API — with third-party models like GPT-5, Claude, and Gemini routed through Perplexity — is a first-class provider in LiteLLM.
Installation
Section titled “Installation”pip install litellmAPI Key Setup
Section titled “API Key Setup”LiteLLM reads your Perplexity API key from the environment:
export PERPLEXITY_API_KEY="your_api_key_here"Get API Key
Generate your Perplexity API key from the API portal.
Agent API
Section titled “Agent API”Use litellm.responses to call the Agent API, which routes through Perplexity to third-party models with tool orchestration and presets.
Presets
Section titled “Presets”from litellm import responses
import os
os.environ["PERPLEXITY_API_KEY"] = "your_api_key_here"
response = responses(
model="perplexity/preset/low",
input="What are the latest developments in AI?",
custom_llm_provider="perplexity",
)
print(response.output)Available presets: fast, low, medium, high, xhigh.
Tool Use (web_search and fetch_url)
Section titled “Tool Use (web_search and fetch_url)”from litellm import responses
response = responses(
model="perplexity/openai/gpt-5.6-sol",
input="Research quantum computing breakthroughs and cite sources.",
custom_llm_provider="perplexity",
tools=[
{"type": "web_search"},
{"type": "fetch_url"},
],
instructions="Use web_search and fetch_url to gather citations.",
max_output_tokens=1000,
temperature=0.7,
)
print(response.output)Structured Outputs
Section titled “Structured Outputs”from litellm import responses
response = responses(
model="perplexity/preset/low",
input="Extract key facts about the Eiffel Tower.",
custom_llm_provider="perplexity",
text={
"format": {
"type": "json_schema",
"name": "facts",
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"height_meters": {"type": "number"},
"year_built": {"type": "integer"},
},
"required": ["name", "height_meters", "year_built"],
},
"strict": True,
}
},
)Supported Third-Party Models via Agent API
Section titled “Supported Third-Party Models via Agent API”Prefix any Agent API model ID with perplexity/ (for example, perplexity/openai/gpt-5.6-sol). See the Agent API model list for the canonical, up-to-date catalogue.
LiteLLM Proxy
Section titled “LiteLLM Proxy”Run LiteLLM as a self-hosted proxy that fronts Perplexity (and any other provider) behind a single OpenAI-compatible endpoint.
config.yaml
Section titled “config.yaml”model_list:
- model_name: perplexity-low
litellm_params:
model: perplexity/preset/low
api_key: os.environ/PERPLEXITY_API_KEYStart the Proxy
Section titled “Start the Proxy”litellm --config /path/to/config.yamlCall the Proxy
Section titled “Call the Proxy”curl http://0.0.0.0:4000/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer anything" \
-d '{
"model": "perplexity-low",
"input": "What are the latest developments in AI?",
"tools": [{"type": "web_search"}]
}'Links & Resources
Section titled “Links & Resources”LiteLLM Perplexity Docs
Official LiteLLM Perplexity provider docs.
LiteLLM Docs
Full LiteLLM documentation.
Perplexity Agent API
Agent API reference and presets.
Agent API Models
Available Agent API models.
Support
Section titled “Support”Need help with the integration?
- Browse the LiteLLM documentation
- Review our FAQ