Skip to main content

Overview

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.

Quick Start

Use the OpenAI SDK with Perplexity’s Agent API:

Configuration

Setting Up the OpenAI SDK

Configure OpenAI SDKs to work with Perplexity by setting the base_url to https://api.perplexity.ai/v1:
Important: Use base_url="https://api.perplexity.ai/v1" (with /v1) for the Agent API.

Agent API

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.

Basic Usage

Using Presets

Presets are pre-configured setups optimized for specific use cases. Use extra_body to pass presets via the OpenAI SDK:
See Agent API Presets for available presets and their configurations.

Using Third-Party Models

You can also specify third-party models directly instead of using presets:

Streaming Responses

Streaming works with the Agent API:

Using Tools

The Agent API supports built-in tools, including web search. With the OpenAI SDK, pass tools via extra_body in Python; in TypeScript/JS, pass tools as a top-level parameter and cast the call to bypass the SDK’s type checking:

API Compatibility

Standard OpenAI Parameters

These parameters work exactly the same as OpenAI’s API: Agent API:
  • model - Model name (use 3rd party models like openai/gpt-5.6-sol)
  • input - Input text or message array
  • instructions - System instructions
  • max_output_tokens - Maximum tokens in response
  • stream - Enable streaming responses
  • tools - Array of tools including web_search
  • store - Whether the response is visible through retrieval; see Conversation state
  • previous_response_id - Continue from a completed prior response; see Conversation state

Perplexity-Specific Parameters

Agent API:
  • preset - Preset name (use Perplexity presets like low)
  • tools[].filters - Search filters within web_search tool
  • tools[].user_location - User location for localized results
See Agent API Reference for complete parameter details.

Endpoint Mapping

MethodPerplexity EndpointOpenAI EquivalentNotes
client.responses.create()POST /v1/agentPOST /v1/responsesBoth paths accepted by Perplexity for compatibility
client.responses.retrieve()GET /v1/agent/{id}GET /v1/responses/{id}Both paths accepted by Perplexity for compatibility
client.models.list()GET /v1/modelsGET /v1/modelsLists 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.

Model Discovery

The GET /v1/models endpoint returns all models available for the Agent API in OpenAI-compatible format. No authentication is required.
This endpoint is compatible with tools like Open WebUI, Cherry Studio, and LiteLLM that auto-discover available models via the OpenAI /v1/models endpoint.

Response Structure

Agent API

Perplexity’s Agent API matches OpenAI’s Responses API response format:
  • output - Structured output array containing messages with content[].text
  • model - The model name used
  • usage - Token consumption details
  • id, created_at, status - Response metadata

Best Practices

1

Use the correct base URL

Always use https://api.perplexity.ai/v1 (with /v1) for the Agent API.
2

Handle errors gracefully

Use the OpenAI SDK’s error handling:
3

Use streaming for better UX

Stream responses for real-time user experience:
We recommend using Perplexity’s native SDKs for the best developer experience:
  • Cleaner preset syntax - Use preset="low" directly instead of extra_body={"preset": "low"}
  • Type safety - Full Typescript/Python type definitions for all parameters
  • Enhanced features - Direct access to all Perplexity-specific features
  • Better error messages - Perplexity-specific error handling
  • Simpler setup - No need to configure base URLs
See the Perplexity SDK Guide for details.

Migrating to the Perplexity SDK

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

2

Update the import and client

No base URL needed - The Perplexity SDK automatically uses the correct endpoint.
3

Update the API calls

The API calls are very similar:
4

Use presets with cleaner syntax

The Perplexity SDK supports presets with cleaner syntax compared to OpenAI SDK:

Next Steps

Agent API Quickstart

Get started with Agent API using OpenAI SDKs.

Agent API Models

Explore direct model selection and third-party models.

Conversation State

Continue a conversation with previous_response_id or replay turns yourself.

API Reference

View complete endpoint documentation.

Output Control

Configure streaming responses and structured outputs with JSON schema.

Model Fallback

Specify multiple models for automatic failover and higher availability.

Filters

Apply filters to web search results.