Perplexity API: Agent, Search & Sonar Developer Guide

Developer platform guide

Perplexity API: Agent, Search, Router, Sonar and Embeddings Explained

The Perplexity API is now a broader developer platform rather than a single Sonar endpoint. Learn which API to choose, how to make a first request, where costs arise and how to build dependable, source-grounded research applications for SEO, content and outreach work.

Real-time web grounding REST and official SDKs Pay-as-you-go billing

Fact checked against Perplexity’s official developer documentation in August 2026. Endpoints, models, prices and limits can change, so confirm the live documentation before deployment.

perplexity-api.py LIVE WEB
from perplexity import Perplexity client = Perplexity() response = client.responses.create(   preset="fast",   input="Latest search changes?" ) # web-grounded output + sources
200 completedcited
output_text: “The current changes include…”
search_results: [source_1, source_2]
ROUTERAGENTSEARCHEMBED
The platform in plain English

What is the Perplexity API?

The Perplexity API lets developers add models, live web search, cited answers, agent tools and embeddings to their own software. It is separate from the consumer Perplexity AI website and apps: your code sends authenticated requests to an endpoint, receives structured responses and is billed for API usage.

The current platform has four core product families: Router, Agent, Search and Embeddings. Sonar Chat Completions is still supported, but Perplexity now lists Sonar under its legacy API documentation and recommends Agent API for new projects. That distinction matters because many older tutorials use Sonar as a synonym for the entire Perplexity API.

Current product map

The Perplexity API types and what each one does

Choose the interface from the output you need. A generated answer, raw results, direct model access and vector embeddings solve different problems.

SEARCHRaw web results

Search API

Returns real-time ranked results as structured data, with controls for domains, language, region and extracted content. It can accept up to five related queries in one request.

Best for your own search interface, retrieval pipeline, monitoring tool or model-independent workflow.

POST /search
ROUTEModel access

Router API

Provides one endpoint and key for open-weight models hosted by Perplexity, with OpenAI- and Anthropic-compatible routes. Perplexity positions it for model-agnostic workloads and managed routing or failover.

Best when your application needs direct model output without the full agent tool loop.

OpenAI / Anthropic compatible
VECTORRetrieval

Embeddings API

Turns text into vectors for semantic search, clustering and retrieval-augmented generation. Standard embeddings suit independent text; contextualised embeddings preserve relationships between chunks from the same document.

Best for knowledge bases, recommendations and document retrieval rather than answer generation.

Standard + contextualised
Where does Sonar fit? Sonar remains an OpenAI-compatible, web-grounded Chat Completions API using a messages array and returning choices. It is useful for existing integrations and simpler migrations, but Agent API adds broader models, tools, model fallback, MCP, typed outputs, streaming and asynchronous work. A dedicated Sonar guide can cover its individual models and parameters without turning this platform overview into a model catalogue.
Decision guide

Which Perplexity API should you use?

Start from the data your application needs to receive, then add only the model and tools required to produce it.

Your requirement
Best starting point
What it returns
Typical build
A current answer with citations
Agent API
Generated response plus typed tool and source output
Research assistant or Q&A feature
Ranked web results for your own processing
Search API
Titles, URLs, snippets, dates and extracted content
Monitoring, retrieval or custom search
Direct access to hosted open-weight models
Router API
Model completion through compatible formats
Multi-model application or provider consolidation
Vector search over your documents
Embeddings API
Standard or document-aware vectors
RAG, similarity and recommendation engine
Maintain an older chat-completions integration
Sonar, then assess migration
OpenAI-compatible choices and cited answer data
Existing Sonar-backed product
First integration

How to use the Perplexity API

This Agent API example uses a dynamic preset rather than hard-coding a model that may be retired. Keep authentication on the server and never expose the key in browser-side JavaScript.

01

Create or join an API group

Sign in to the API Console and create an API group. Groups organise keys, billing and access across projects or environments.

02

Add billing and generate a key

Create a dedicated key for development. Perplexity displays the full key once, so copy it into a secure secret manager and never commit it to a repository.

03

Install the official SDK

Use pip install perplexityai for Python or npm install @perplexity-ai/perplexity_ai for TypeScript and JavaScript.

04

Set the environment variable

Store the secret as PERPLEXITY_API_KEY. The official SDK reads it automatically, keeping the credential out of the request code.

05

Send, inspect and log safely

Make a small test call, check status, output, sources, usage and cost. Log response IDs and operational metrics, but do not copy keys or sensitive prompts into logs.

Why Agent API is different

Agent API features for production applications

The Agent API can move beyond one prompt and one completion by combining reasoning, retrieval, tools and controlled outputs in a single run.

WEB

Web search and URL fetch

Let the model discover current pages with web_search or retrieve known pages with fetch_url. Domain, recency and location controls can narrow the evidence.

TOOLS

Hosted and custom tools

Add finance, people or sandbox tools; connect a remote MCP server; or declare your own function schema and return the result to the run.

JSON

Structured outputs

Use JSON Schema when downstream software needs predictable fields. Validate the response anyway, particularly where an output can trigger a database or publishing action.

ASYNC

Streaming and background work

Stream user-facing answers or run longer jobs in the background and retrieve them by response ID. Design timeout, reconnect and cancellation behaviour deliberately.

MODEL

Multi-provider models

Use models from several providers behind a consistent interface. Presets can select a tested configuration; explicit models provide more control when requirements are fixed.

SAFE

Fallback and budgets

Configure model fallback for reliability, set token and step limits, and restrict the tool set. These controls help contain latency, failure modes and unexpected spend.

Commercial overview

How Perplexity API pricing works

API access is pay as you go and does not require a consumer subscription. The bill can include model tokens, search request fees or tool invocations depending on the API.

Agent API

Model tokens are charged at the chosen provider’s published rate with no markup, while enabled tools are billed separately when invoked.

Token + tool Current example: web_search $0.0025 per invocation

Search API

A successful request is one billing unit, even if it contains up to five queries. Rate limiting still counts every query in that array.

$5 / 1K Successful POST /search requests

Router API

Billed per model token at the requested model’s published rate, including applicable cache and long-context pricing.

Per model No separate per-request fee

Sonar API

Sonar pricing combines input and output tokens with a request fee determined by model and search-context size.

Token + request Deep Research has additional billing dimensions
Budget for the whole workflow, not only the model. A multi-step Agent API run may call search, fetch pages and use a sandbox before generating the final answer. Inspect the response usage and cost data, set hard application budgets and follow the live Perplexity pricing page. The later dedicated pricing guide should handle model-by-model tables because those figures change too often for this overview.
Real-world applications

Perplexity API use cases for SEO and guest posting

Use the API to build repeatable research systems, not to manufacture evidence or send indiscriminate outreach at scale.

NEWS

Search-change monitor

Run scheduled Search API queries for official search-engine updates, filter by trusted domains and store titles, dates and URLs for editorial review.

Build with: Search API, multi-query search, domain and recency filters.
GUIDE

Publisher-guideline parser

Fetch known contributor pages and return a validated JSON record for topic fit, word count, link policy, contact route and evidence date.

Build with: Agent API, fetch_url and structured outputs.
GAP

Editorial gap research

Search a publication’s recent coverage, cluster topics and identify potentially useful angles. A human should confirm that the gap is real before pitching.

Build with: Search API plus your own model, or Agent API with web_search.
CITE

Claim-to-source checker

Compare draft claims with primary sources and flag missing, stale or contradictory evidence. Store the source URL and retrieval date beside each finding.

Build with: Agent API, domain allowlist, fetch_url and JSON Schema.
RAG

Internal knowledge search

Index approved service pages, editorial rules and campaign notes, then retrieve relevant passages before an answer or brief is generated.

Build with: Contextualised Embeddings and a vector database.
QA

Prospect-quality review

Collect public evidence about topical relevance, editorial activity and contributor information. Keep commercial notes separate from editorial-quality assessment.

Build with: Search API for discovery; Agent API for evidence-led classification.
Avoid automated spam and unsupported SEO metrics. The API cannot replace Search Console, backlink indexes or a real relationship with a publisher. Do not invent traffic, rankings, Domain Authority or acceptance status. Keep a human approval step before sending email, submitting a form, publishing content or making a commercial decision.
Reliability and quality

How to build a dependable Perplexity API integration

A good demo returns an answer. A good production system controls evidence, output shape, failure recovery, cost and downstream consequences.

Restrict the evidence

Use domain and recency filters for sensitive topics. Prefer primary sources and record the source list returned with the response.

Validate structured output

JSON Schema improves consistency but is not a substitute for server-side validation, type checks and safe defaults.

Handle 429 responses

Respect Retry-After where supplied, use exponential backoff with jitter and avoid retrying invalid requests.

Design for partial failure

Search can return no results, a page can block extraction and a model can time out. Show a useful state rather than a fabricated answer.

Measure answer quality

Create an evaluation set for citation correctness, factuality, freshness, latency and field-level extraction accuracy.

Control spend

Limit steps, output tokens, search depth and enabled tools. Cache safe results and deduplicate repeated background jobs.

Data and commercial access

Perplexity API privacy and subscription rules

API data handling and API billing are separate from the settings and subscription attached to the consumer Perplexity product.

Data privacy and retention

Perplexity documents zero-day retention of user prompt data for the API and says customer data is not used for model training. It retains essential billable metadata such as token counts, model, timestamp, duration and key identification.

That policy does not remove your own obligations. Minimise personal data, review any third-party model or tool implications and keep secrets out of prompts and logs. Read the current Privacy & Security documentation.

API access vs Pro or Enterprise

A Perplexity Pro or Max subscription pays for features inside the Perplexity product; it does not provide unlimited API usage. The API uses its own console, groups, keys, credits, usage tiers and pay-as-you-go billing.

Perplexity Enterprise may be relevant for organisation-wide search, collaboration and admin controls, while an API integration is for embedding capabilities into your own application or workflow. Some organisations may need both.

Common problems

Why a Perplexity API request fails

Check credentials, endpoint shape, model or preset availability, billing and rate limits before changing the prompt.

401

Missing or invalid key

Confirm the Authorization header, environment variable and API group. Rotate the key immediately if it appeared in public code, client-side JavaScript or a shared screenshot.

400

Request shape is invalid

Agent uses an input and typed output model, while Sonar uses messages and choices. Do not send one API’s payload to another endpoint.

429

Rate limit exceeded

Usage tiers affect several limits, while Search API has its own query-unit limit. Queue bursts and retry only after the documented interval.

$

Credit or billing issue

Check the API Console rather than the consumer subscription page. API groups require their own billing setup and available credit.

JSON

Structured output is incomplete

Allow enough output tokens, keep the schema focused and validate after receipt. Define a recovery path when required fields are missing.

WEB

Sources are weak or missing

Improve the query, adjust recency or domain filters and return an explicit insufficient-evidence state rather than filling gaps from assumption.

Questions answered

Perplexity API questions

Direct answers about access, Sonar, search results, keys, pricing and production use.

Is the Perplexity API free?

The platform is pay as you go. Perplexity says no subscription is required, but production requests are billed according to the API, model, tokens and tools used. The Search Playground may allow testing without a key, which is not the same as free production usage.

Do I need Perplexity Pro to use the API?

No. API access and billing are separate from consumer Pro, Max and Enterprise subscriptions. Set up an API group, billing and an API key in the API Console.

Is Sonar API deprecated?

Perplexity still supports Sonar Chat Completions, but documents it under Legacy API and recommends Agent API for new projects. Existing teams should evaluate migration based on required tools, response format, testing effort and risk.

What is the difference between Search API and Agent API?

Search API returns raw ranked web results for your software to process. Agent API uses models and optional tools to produce an answer or multi-step result, with source and tool output available in the response.

Does Perplexity train on API prompts?

Perplexity’s API documentation states that user prompt data has zero-day retention and is not used for AI training. It retains essential billing and service metadata. Always review the current policy and your own compliance obligations.

Which API is best for an SEO research tool?

Use Search API when you want raw results and will perform your own analysis. Use Agent API when you want a cited answer, structured extraction or a multi-step workflow. Use Embeddings for retrieval across your own approved document library.

Build the smallest reliable Perplexity API workflow first

Choose one endpoint, one clearly defined output and a small evaluation set. Prove citation quality, failure handling and cost before adding more models, tools or automation.

guestpost.uk new logo
💙 PayPal
💳 VISA
💳 Mastercard
🏦 Bank
🔒 SSL

© 2026. All rights reserved.

AI
GuestPost AI ConsultantSEO Consultant · Link Building · GEO · Tools
Ask about packages, pricing, SEO tools or a growth plan