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 route is independent of the Sonar model list and supports third-party models, presets, fallback chains, tools, and streaming.

Quick setup

1

Get a Respan API key

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

Send your first request

Pick the integration that matches your stack. The base URL is https://api.respan.ai/api and the only key needed is your RESPAN_API_KEY.

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

1from openai import OpenAI
2
3client = OpenAI(
4 api_key="YOUR_RESPAN_API_KEY",
5 base_url="https://api.respan.ai/api",
6)
7
8response = client.chat.completions.create(
9 model="perplexity/sonar-pro",
10 messages=[{"role": "user", "content": "Hello, Perplexity!"}],
11)
12print(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.

1import os
2import requests
3
4response = requests.post(
5 "https://api.respan.ai/api/responses",
6 headers={
7 "Authorization": f"Bearer {os.environ['RESPAN_API_KEY']}",
8 "Content-Type": "application/json",
9 "X-Respan-Route-Provider": "perplexity",
10 },
11 json={
12 "preset": "medium",
13 "input": "Research recent advances in retrieval-augmented generation.",
14 "max_steps": 1,
15 "respan_params": {
16 "credential_override": {
17 "": {
18 "api_key": os.environ["PERPLEXITY_API_KEY"],
19 }
20 }
21 },
22 },
23)
24response.raise_for_status()
25print(response.json()["output"])

This request uses RESPAN_API_KEY for Respan authentication and PERPLEXITY_API_KEY as a request-scoped provider credential. If Perplexity is already configured under Settings → Providers, omit respan_params.credential_override.

The response reports the actual model chosen by Perplexity and its authoritative USD cost. Set stream: true for Responses API server-sent events, or pass model/models instead of a preset.

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.

1client.chat.completions.create(model="perplexity/sonar", messages=messages)
2client.chat.completions.create(model="perplexity/sonar-pro", messages=messages)
3client.chat.completions.create(model="perplexity/sonar-reasoning-pro", messages=messages)
4client.chat.completions.create(model="openai/gpt-5.5", messages=messages)
5client.chat.completions.create(model="anthropic/claude-sonnet-4-5", messages=messages)

Use your own Perplexity key (BYOK)

Credits are the default path. If you’d rather bill Perplexity directly, attach your own provider key.

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.

1{
2 "customer_credentials": {
3 "perplexity": { "api_key": "YOUR_PERPLEXITY_API_KEY" }
4 },
5 "credential_override": {
6 "perplexity/sonar-pro": { "api_key": "ANOTHER_PERPLEXITY_API_KEY" }
7 }
8}

Log without proxying (Optional)

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

1import requests
2
3requests.post(
4 "https://api.respan.ai/api/request-logs/create/",
5 headers={
6 "Authorization": "Bearer YOUR_RESPAN_API_KEY",
7 "Content-Type": "application/json",
8 },
9 json={
10 "model": "perplexity/sonar-pro",
11 "prompt_messages": [{"role": "user", "content": "Hello, how are you?"}],
12 "completion_message": {"role": "assistant", "content": "Hello from Perplexity through Respan."},
13 "cost": 0.001,
14 "generation_time": 1.2,
15 "customer_params": {"customer_identifier": "user_123"},
16 },
17)

See the logging guide for the full setup.