Skip to navigation

Provider: Perplexity

Call Perplexity models through Respan Gateway with unified logs, cost, and latency.
This page is for Respan LLM Gateway users.

Respan supports both Perplexity Sonar models and the Perplexity Agent API while keeping unified observability for logs, cost, latency, and reliability.

Perplexity APIRespan endpointHow to select it
Sonar Chat CompletionsPOST /api/chat/completionsUse a model such as perplexity/sonar-pro.
Agent APIPOST /api/responsesSet X-Respan-Route-Provider: perplexity.

The Agent API can call Perplexity’s own Sonar model or third-party models offered by Perplexity. Through Respan, use an explicit model or a nonempty fallback chain; preset-only requests do not pass the current model validation.

Perplexity Sonar models require bring your own key (BYOK). Sonar usage cannot be paid with Respan credits. The Agent API has separate credential handling.

Quick setup

1

Get a Respan API key

Sign up and create a key on the API keys page.

2

Add your Perplexity credentials

Configure your Perplexity credentials on the Providers page before using the Sonar examples below. See Use your own Perplexity key.

Send your first request

After configuring your Perplexity credentials in Respan, pick the integration that matches your stack. The base URL is https://api.respan.ai/api and your application authenticates with RESPAN_API_KEY.

Perplexity is OpenAI-compatible. Point the OpenAI SDK at the Respan gateway and call any Perplexity model.

from openai import OpenAI
client = OpenAI(
api_key="YOUR_RESPAN_API_KEY",
base_url="https://api.respan.ai/api",
)
response = client.chat.completions.create(
model="perplexity/sonar-pro",
messages=[{"role": "user", "content": "Hello, Perplexity!"}],
)
print(response.choices[0].message.content)

Use Perplexity Agent API

Perplexity’s Agent API uses the OpenAI Responses shape. The route is activated only by the X-Respan-Route-Provider: perplexity header. These examples call Perplexity’s own Sonar model, perplexity/sonar.

import os
import requests
response = requests.post(
"https://api.respan.ai/api/responses",
headers={
"Authorization": f"Bearer {os.environ['RESPAN_API_KEY']}",
"Content-Type": "application/json",
"X-Respan-Route-Provider": "perplexity",
},
json={
"model": "perplexity/sonar",
"input": "Research recent advances in retrieval-augmented generation.",
"max_steps": 1,
"respan_params": {
"credential_override": {
"": {
"api_key": os.environ["PERPLEXITY_API_KEY"],
}
}
},
},
)
response.raise_for_status()
print(response.json()["output"])

This request uses RESPAN_API_KEY for Respan authentication and PERPLEXITY_API_KEY as a request-scoped provider credential. You can omit respan_params.credential_override if Perplexity is already configured under Gateway → API keys → Bring your own key, or when managed Perplexity credentials are available through Respan credits for the Agent API route.

The response reports the model returned by Perplexity and its authoritative USD cost. Set stream: true for Responses API server-sent events, or use models for an ordered fallback chain. Respan requires an explicit model or a nonempty fallback chain; preset-only requests do not pass its model validation.

For third-party model choices, see Perplexity’s Agent API model list. Requests to those models still use the Perplexity route header and Perplexity credentials.

See the Responses API guide for all request shapes, Agent API parameters, header rules, logging, and billing behavior.

More integrations

Perplexity models work with every Respan gateway integration:

Switch models

Change the model parameter to call any supported model through the same client. Use the perplexity/ prefix to disambiguate when routing across providers. Browse the full list on the Models page.

client.chat.completions.create(model="perplexity/sonar", messages=messages)
client.chat.completions.create(model="perplexity/sonar-pro", messages=messages)
client.chat.completions.create(model="perplexity/sonar-reasoning-pro", messages=messages)
client.chat.completions.create(model="openai/gpt-6-sol", messages=messages)
client.chat.completions.create(model="anthropic/claude-opus-5-5", messages=messages)

Use your own Perplexity key (BYOK)

Perplexity Sonar models require your own Perplexity credentials. Configure them in Respan or pass them with each request using one of the options below.

Agent API credentials are provider-scoped. Legacy Sonar values in available_models do not restrict Agent API model, preset, or fallback requests.

1

Open Providers

Go to the Providers page.

2

Add Perplexity

Select Perplexity and paste your perplexity.api_key. Grab one from the Perplexity API settings page.

3

Load balancing (Optional)

Add multiple credential sets and use Load balancing weight to distribute traffic across them.

Override credentials per model (Optional)

Use credential_override when one model on a request should use a different Perplexity key than the default.

{
"customer_credentials": {
"perplexity": { "api_key": "YOUR_PERPLEXITY_API_KEY" }
},
"credential_override": {
"perplexity/sonar-pro": { "api_key": "ANOTHER_PERPLEXITY_API_KEY" }
}
}

Log without proxying (Optional)

Already calling Perplexity directly? Send logs to Respan asynchronously to track cost, latency, and performance for those external calls.

import requests
requests.post(
"https://api.respan.ai/api/request-logs/create/",
headers={
"Authorization": "Bearer YOUR_RESPAN_API_KEY",
"Content-Type": "application/json",
},
json={
"model": "perplexity/sonar-pro",
"prompt_messages": [{"role": "user", "content": "Hello, how are you?"}],
"completion_message": {"role": "assistant", "content": "Hello from Perplexity through Respan."},
"cost": 0.001,
"generation_time": 1.2,
"customer_params": {"customer_identifier": "user_123"},
},
)

See the logging guide for the full setup.