Files
litellm/docs/my-website/docs/providers/perplexity.md
T
Krish DholakiaandGitHub d15664c8e6 Litellm stable docs 06 14 2025 p2 (#11738)
* docs: track which items need docs

* docs(anthropic.md): add tool_choice="none" to docs

* docs: add docs for new anthropic + perplexity features

* docs: cleanup mistral reasoning docs

* docs: add links to docs

* docs(index.md): update docs

* docs: refactor to add a new 'integrations' tab to docs

* refactor(docs/): create separate tab for integrations

make it easier to highlight new integrations

* docs: sort sidebar

* docs: update
2025-06-14 19:38:46 -07:00

3.0 KiB

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

Perplexity AI (pplx-api)

https://www.perplexity.ai

API Key

# env variable
os.environ['PERPLEXITYAI_API_KEY']

Sample Usage

from litellm import completion
import os

os.environ['PERPLEXITYAI_API_KEY'] = ""
response = completion(
    model="perplexity/sonar-pro", 
    messages=messages
)
print(response)

Sample Usage - Streaming

from litellm import completion
import os

os.environ['PERPLEXITYAI_API_KEY'] = ""
response = completion(
    model="perplexity/sonar-pro", 
    messages=messages,
    stream=True
)

for chunk in response:
    print(chunk)

Reasoning Effort

Requires v1.72.6+

:::info

See full guide on Reasoning with LiteLLM here

:::

You can set the reasoning effort by setting the reasoning_effort parameter.

from litellm import completion
import os

os.environ['PERPLEXITYAI_API_KEY'] = ""
response = completion(
    model="perplexity/sonar-reasoning", 
    messages=messages,
    reasoning_effort="high"
)
print(response)
  1. Setup config.yaml
model_list:
  - model_name: perplexity-sonar-reasoning-model
    litellm_params:
        model: perplexity/sonar-reasoning
        api_key: os.environ/PERPLEXITYAI_API_KEY
  1. Start proxy
litellm --config /path/to/config.yaml
  1. Test it!

Replace anything with your LiteLLM Proxy Virtual Key, if setup.

curl http://0.0.0.0:4000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer anything" \
  -d '{
    "model": "perplexity-sonar-reasoning-model",
    "messages": [{"role": "user", "content": "Who won the World Cup in 2022?"}],
    "reasoning_effort": "high"
  }'

Supported Models

All models listed here https://docs.perplexity.ai/docs/model-cards are supported. Just do model=perplexity/<model-name>.

Model Name Function Call
sonar-deep-research completion(model="perplexity/sonar-deep-research", messages)
sonar-reasoning-pro completion(model="perplexity/sonar-reasoning-pro", messages)
sonar-reasoning completion(model="perplexity/sonar-reasoning", messages)
sonar-pro completion(model="perplexity/sonar-pro", messages)
sonar completion(model="perplexity/sonar", messages)
r1-1776 completion(model="perplexity/r1-1776", messages)

:::info

For more information about passing provider-specific parameters, go here :::