Perplexity’s Agent API is fully compatible with OpenAI’s Responses API interface. You can use your existing OpenAI client libraries by simply changing the base URL and providing your Perplexity API key.
Endpoint Note: Perplexity’s canonical Agent API endpoint is POST /v1/agent. For OpenAI SDK compatibility, POST /v1/responses is also accepted as an alias — the OpenAI SDK automatically routes client.responses.create() to /v1/responses, which Perplexity handles seamlessly. No SDK changes are needed beyond setting the base URL.
We recommend using the Perplexity SDK for the best experience with full type safety, enhanced features, and preset support. Use OpenAI SDKs if you’re already integrated and need drop-in compatibility.
Perplexity’s Agent API follows OpenAI’s Responses API request/response format. The OpenAI SDK’s client.responses.create() method works out of the box — the SDK sends requests to /v1/responses, which Perplexity accepts alongside the canonical /v1/agent endpoint.
Presets are pre-configured setups optimized for specific use cases. Use extra_body to pass presets via the OpenAI SDK:
Python
Typescript
import osfrom openai import OpenAIclient = OpenAI( api_key=os.environ.get("PERPLEXITY_API_KEY"), base_url="https://api.perplexity.ai/v1")# Pass preset via extra_bodyresponse = client.responses.create( input="What are the key differences between the latest iPhone and Samsung Galaxy flagship phones?", extra_body={ "preset": "pro-search" })print(response.output_text)
import OpenAI from 'openai';const client = new OpenAI({ apiKey: process.env.PERPLEXITY_API_KEY, baseURL: "https://api.perplexity.ai/v1"});// Use type casting (as any) to pass preset directlyconst response = await (client.responses.create as any)({ input: "What are the key differences between the latest iPhone and Samsung Galaxy flagship phones?", preset: "pro-search"});console.log(response.output_text);
See Agent API Presets for available presets and their configurations.
import osfrom openai import OpenAIclient = OpenAI( api_key=os.environ.get("PERPLEXITY_API_KEY"), base_url="https://api.perplexity.ai/v1")response = client.responses.create( model="openai/gpt-5.4", input="Write a bedtime story about a unicorn.", stream=True)for event in response: if event.type == "response.output_text.delta": print(event.delta, end="", flush=True)
import OpenAI from 'openai';const client = new OpenAI({ apiKey: process.env.PERPLEXITY_API_KEY, baseURL: "https://api.perplexity.ai/v1"});const response = await client.responses.create({ model: "openai/gpt-5-mini", input: "Write a bedtime story about a unicorn.", stream: true});for await (const event of response) { if (event.type === "response.output_text.delta") { process.stdout.write(event.delta); }}
The Agent API supports built-in tools, including web search. Use extra_body to pass tools via the OpenAI SDK:
Python
Typescript
import osfrom openai import OpenAIclient = OpenAI( api_key=os.environ.get("PERPLEXITY_API_KEY"), base_url="https://api.perplexity.ai/v1")# Pass tools via extra_bodyresponse = client.responses.create( model="openai/gpt-5.4", input="Which companies announced the largest AI acquisitions this quarter?", extra_body={ "tools": [ { "type": "web_search", "filters": { "search_domain_filter": ["techcrunch.com", "crunchbase.com"] } } ] })print(response.output_text)
import OpenAI from 'openai';const client = new OpenAI({ apiKey: process.env.PERPLEXITY_API_KEY, baseURL: "https://api.perplexity.ai/v1"});// Use type casting (as any) to pass tools via extra_bodyconst response = await (client.responses.create as any)({ model: "openai/gpt-5-mini", input: "Which companies announced the largest AI acquisitions this quarter?", extra_body: { "tools": [ { "type": "web_search", "filters": { "search_domain_filter": ["techcrunch.com", "crunchbase.com"] } } ] }});console.log(response.output_text);
Both paths accepted by Perplexity for compatibility
client.models.list()
GET /v1/models
GET /v1/models
Lists available Agent API models. No authentication required.
When using the OpenAI SDK, client.responses.create() sends requests to /v1/responses. Perplexity accepts this path as an alias for /v1/agent, so no SDK configuration changes are needed beyond base_url.
The GET /v1/models endpoint returns all models available for the Agent API in OpenAI-compatible format. No authentication is required.
Python
Typescript
cURL
import osfrom openai import OpenAIclient = OpenAI( api_key=os.environ.get("PERPLEXITY_API_KEY"), base_url="https://api.perplexity.ai/v1")models = client.models.list()for model in models.data: print(f"{model.id} (owned by {model.owned_by})")
import OpenAI from 'openai';const client = new OpenAI({ apiKey: process.env.PERPLEXITY_API_KEY, baseURL: "https://api.perplexity.ai/v1"});const models = await client.models.list();for (const model of models.data) { console.log(`${model.id} (owned by ${model.owned_by})`);}
curl https://api.perplexity.ai/v1/models
This endpoint is compatible with tools like Open WebUI, Cherry Studio, and LiteLLM that auto-discover available models via the OpenAI /v1/models endpoint.
Switch to the Perplexity SDK for enhanced features and cleaner syntax. With the Perplexity SDK, you can use presets directly without extra_body and get full type safety:
1
Install the Perplexity SDK
Python
Typescript
pip install perplexityai
npm install @perplexity-ai/perplexity_ai
2
Update the import and client
Python
Typescript
# Before (OpenAI SDK)import osfrom openai import OpenAIclient = OpenAI( api_key=os.environ.get("PERPLEXITY_API_KEY"), base_url="https://api.perplexity.ai/v1")# After (Perplexity SDK)from perplexity import Perplexityclient = Perplexity() # reads PERPLEXITY_API_KEY env var automatically
// Before (OpenAI SDK)import OpenAI from 'openai';const openaiClient = new OpenAI({ apiKey: process.env.PERPLEXITY_API_KEY, baseURL: "https://api.perplexity.ai/v1"});// After (Perplexity SDK)import Perplexity from '@perplexity-ai/perplexity_ai';const perplexityClient = new Perplexity(); // reads PERPLEXITY_API_KEY env var automatically
No base URL needed - The Perplexity SDK automatically uses the correct endpoint.
3
Update the API calls
The API calls are very similar:
Python
Typescript
# Agent API - same interfaceresponse = client.responses.create( model="openai/gpt-5.4", input="Hello!")
// Agent API - same interfaceconst response = await client.responses.create({ model: "openai/gpt-5-mini", input: "Hello!"});
4
Use presets with cleaner syntax
The Perplexity SDK supports presets with cleaner syntax compared to OpenAI SDK:
Python
Typescript
# Before (OpenAI SDK) - extra_body requiredresponse = client.responses.create( input="What were the biggest tech IPOs this year and how did they perform on day one?", extra_body={"preset": "pro-search"})# After (Perplexity SDK) - direct parameterresponse = client.responses.create( preset="pro-search", input="What were the biggest tech IPOs this year and how did they perform on day one?")
// Before (OpenAI SDK) - type casting requiredconst response = await client.responses.create({ input: "What were the biggest tech IPOs this year and how did they perform on day one?", preset: "pro-search"} as any);// After (Perplexity SDK) - fully typedconst response = await client.responses.create({ preset: "pro-search", input: "What were the biggest tech IPOs this year and how did they perform on day one?"});