Agent API Third-Party Models, Routing, Fallback and OpenAI Compatibility
How Perplexity’s Agent API routes frontier models through one key, OpenAI Responses compatibility, fallback chains, and tools.
This page summarizes Perplexity documentation for the Agent API: one API key and one billing surface to call models from OpenAI, Anthropic, Google, xAI, and Perplexity itself, using an OpenAI Responses-style interface (client.responses.create()). If you already use the OpenAI SDK or frameworks that speak /v1/responses, you mostly change the base URL and model IDs; the official Perplexity SDK is recommended when you want full typing and Perplexity-only fields such as effort.
Agent API: what it is and when to use it
Section titled “Agent API: what it is and when to use it”The Agent API is aimed at agent loops: pick a model (or a fallback list), pass input, optionally enable built-in tools such as web_search, and read structured output plus token-level usage (including cost). Perplexity positions it as a unified gateway with transparent token pricing and consolidated billing—you do not need separate API keys for each upstream provider.
Perplexity’s Agent API provides access to models from multiple providers through a single API key. You do not need separate API keys for OpenAI, Anthropic, Google, or xAI.
— Perplexity, Multi-Provider Model Comparison
Use the Agent API when you want multi-provider routing, Perplexity tool orchestration, or research-oriented behavior (for example perplexity/sonar with web_search). Use the legacy Sonar Chat Completions API (POST /v1/sonar, base URL https://api.perplexity.ai without /v1 on the Responses path) only when your stack is built around chat.completions—see Sonar OpenAI compatibility. The separate Orchestrator API (https://api.perplexity.ai/orchestrator/v1) exposes other open-weight models via Responses or Anthropic Messages formats (Orchestrator quickstart).
Endpoints and authentication: how to call POST /v1/agent
Section titled “Endpoints and authentication: how to call POST /v1/agent”Authentication uses Authorization: Bearer with PERPLEXITY_API_KEY. The canonical HTTP endpoint is POST https://api.perplexity.ai/v1/agent; for OpenAI SDK compatibility, POST /v1/responses is an alias.
Endpoint: The Agent API is available at POST https://api.perplexity.ai/v1/agent. For OpenAI SDK compatibility, POST /v1/responses is also accepted as an alias.
— Perplexity, Agent API quickstart
Set the key once; SDKs read it automatically:
export PERPLEXITY_API_KEY="your_api_key_here"| Method (OpenAI SDK) | Perplexity path | Notes |
|---|---|---|
client.responses.create() |
POST /v1/agent |
Alias: POST /v1/responses |
client.responses.retrieve() |
GET /v1/agent/{id} |
Alias: GET /v1/responses/{id} |
client.models.list() |
GET /v1/models |
No auth required per OpenAI compatibility |
Responses follow the Responses object shape: output (messages and optional search_results), model, usage, id, status. Text for the assistant reply is typically accessed as output_text in the Perplexity SDK or by parsing output in raw JSON.
Third-party models: provider/model IDs and one bill
Section titled “Third-party models: provider/model IDs and one bill”Model IDs use a provider/model prefix (for example openai/gpt-5.6-sol, anthropic/claude-sonnet-5-5, google/gemini-3.8-flash). You pass a single model string; Perplexity routes to that upstream capability.
Use third-party models from OpenAI, Anthropic, Google, xAI, and other providers for specific capabilities
— Perplexity, Agent API quickstart
List IDs and pricing on Agent API models. In proxies such as LiteLLM, prefix with perplexity/ (for example perplexity/openai/gpt-5.6-sol) per LiteLLM integration.
Common request parameters
Section titled “Common request parameters”These align with OpenAI Responses parameters documented for the Agent API (OpenAI compatibility):
model— third-party or Perplexity model IDinput— user text or message arrayinstructions— system instructionsmax_output_tokens— cap on generated tokensstream— stream deltas (response.output_text.delta)tools— e.g.[{"type": "web_search"}]store,previous_response_id— conversation / retrieval behavior
Every completed response can include usage with token counts and, on many calls, a cost breakdown—useful for budgeting (Agent API models).
Model routing: picking the right model per task
Section titled “Model routing: picking the right model per task”Routing means choosing different model values for different workloads. Perplexity’s multi-provider orchestration cookbook illustrates task-based maps—for example code → Anthropic, fast chat → xAI, research → perplexity/sonar with web_search, multimodal → Google.
Route between OpenAI, Anthropic, Google, and xAI models through Perplexity’s Agent API with transparent pricing, build fallback chains, and compare providers side-by-side
— Perplexity, Multi-Provider Orchestration
Use the model parameter to target one provider; use your own router logic in application code when the task type changes. For research tasks, the cookbook adds tools=[{"type": "web_search"}] when no tools are otherwise set.
Model fallback: models array for reliability
Section titled “Model fallback: models array for reliability”For higher availability, send an ordered models array instead of a single model. Perplexity tries providers in order (for example OpenAI, then Anthropic, then Google).
For maximum reliability, use models from different providers
— Perplexity, Model fallback
The response’s model field reflects which entry succeeded. Fallback pairs well with diverse providers so an outage or rate limit on one vendor does not block the request.
OpenAI SDK compatibility: base URL, aliases, and gaps
Section titled “OpenAI SDK compatibility: base URL, aliases, and gaps”Point the OpenAI client at https://api.perplexity.ai/v1 (the /v1 suffix is required for Agent API).
Important: Use base_url=“https://api.perplexity.ai/v1” (with /v1) for the Agent API.
— Perplexity, OpenAI compatibility
Perplexity’s Agent API supports the OpenAI Responses API interface, so you can use existing OpenAI client libraries by changing the base URL and providing your Perplexity API key. The APIs are not identical, and some defaults and Perplexity extensions differ.
— Perplexity, OpenAI compatibility
Brave Search Answers also documents OpenAI-style clients for its Answers product (Answers):
Use the familiar OpenAI SDK for seamless integration
— Brave, Answers
That is a different service and endpoint from Perplexity’s Agent API; the common pattern is “retarget base_url / baseURL and swap API keys,” not identical request paths.
MCP approval default
Section titled “MCP approval default”One documented behavioral difference: omitted or null require_approval for MCP is treated as "never" on Perplexity’s Agent API, while OpenAI defaults MCP calls toward approval (OpenAI compatibility).
Tools with the OpenAI SDK
Section titled “Tools with the OpenAI SDK”Built-in web_search is supported. In TypeScript with strict OpenAI types you may need to pass tools via a cast; the Perplexity SDK accepts tools and effort without casts (OpenAI compatibility, Claude Code integration).
Wrong base URLs (agent clients)
Section titled “Wrong base URLs (agent clients)”Clients that append /responses themselves must not use https://api.perplexity.ai/v1/agent or https://api.perplexity.ai/v1/responses as the base—those produce invalid paths. Use https://api.perplexity.ai/v1 so the client hits /v1/responses (OpenClaw integration).
Framework integrations: one Responses endpoint pattern
Section titled “Framework integrations: one Responses endpoint pattern”Many guides share the same wiring:
- LangChain: native
ChatPerplexitywithuse_responses_api=True, orChatOpenAIpointed at Perplexity (LangChain). - Vercel AI SDK / Mastra / OpenCode:
@ai-sdk/open-responseswithurl: "https://api.perplexity.ai/v1/responses"(Vercel AI SDK, Mastra, OpenCode). - LiveKit Agents:
openai.responses.LLMwithbase_url="https://api.perplexity.ai/v1"(LiveKit). - Haystack:
PerplexityChatGenerator(model="…")(Haystack).
Do not point Agent API integrations at Chat Completions-only adapters (/v1/chat/completions); OpenCode explicitly warns that route returns 404 on the Agent API (OpenCode).
Common mistakes
Section titled “Common mistakes”- Using
https://api.perplexity.ai(Sonar) asbase_urlforresponses.create()instead ofhttps://api.perplexity.ai/v1. - Omitting
/v1or setting the base to/v1/responses//v1/agentwhen the SDK already appends/responses. - Configuring
openai-completionswhere the product expects OpenAI Responses (openai-responses) (OpenClaw). - Expecting identical defaults to OpenAI (MCP approval, Perplexity-only
effort). - Forgetting
web_searchon research workloads when you need grounded results (Multi-Provider Orchestration).
How to check this on your site
Section titled “How to check this on your site”-
Create a Perplexity API key and export
PERPLEXITY_API_KEYas in the quickstart. -
List models with
GET https://api.perplexity.ai/v1/models(orclient.models.list()from the OpenAI compatibility guide) and confirm your targetprovider/modelIDs appear. -
Send a minimal
POSTtohttps://api.perplexity.ai/v1/agent(or useclient.responses.create()withbase_url/baseURLset tohttps://api.perplexity.ai/v1) and verifystatus: "completed"andoutput_textor message content inoutput. -
Inspect
usage(andusage.costwhen present) on the response against the Agent API models pricing table. -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about, and we will fix or clarify it.