Pricing+7% bonus
Tiffany Layne2026-03-02

Perplexity AI API Guide: Pricing, API Keys, Costs, and Code Examples

Compare Perplexity Agent, Search, Router, and Embeddings APIs. See 2026 pricing, get an API key, calculate costs, and run Python examples.

Perplexity AI API Guide: Pricing, API Keys, Costs, and Code Examples

The Perplexity AI API is no longer one product with one obvious endpoint. It now covers four distinct jobs: generating web-grounded answers, returning raw search results, routing requests to open-weight models, and creating embeddings.

That distinction matters. If you choose the wrong API, you may pay for tools you do not need—or build around an older Sonar endpoint that is already on a retirement clock.

Here is the short version:

Perplexity API Best use How it is billed Main trade-off
Agent API Generate answers using web search and citations Model tokens plus tool calls The bill has multiple components
Search API Retrieve ranked, structured web results Successful requests It does not write the final answer
Router API Call hosted open-weight models Model tokens Search is not included automatically
Embeddings API Build semantic search or RAG Input tokens You still own the retrieval pipeline

One more detail before we start: Perplexity says Sonar Chat Completions is now part of the Agent API, and the legacy Sonar API will remain supported only until September 27, 2026. New integrations should not start with an old /chat/completions tutorial.

Table of contents

What Is the Perplexity AI API?

“Perplexity AI API” is an umbrella term for a set of developer services built around search, generation, model access, and retrieval.

It is separate from the consumer Perplexity application. You do not need a Perplexity Pro subscription to use the APIs. Instead, you create an API account, add billing, buy credits, and pay for usage.

The four services solve different problems:

  • Agent API combines language models with tools such as web search and URL fetching. Use it when the output should be a written answer rather than a result list.

  • Search API returns ranked web results as structured data. Use it when your application—not Perplexity—will decide how to process and display those results.

  • Router API exposes open-weight models hosted by Perplexity through compatible endpoints. It is model infrastructure, not a search-answer engine.

  • Embeddings API converts text into vectors for semantic retrieval and RAG systems.

In plain English: “I need an answer” usually points to Agent; “I need search results” points to Search.

The Four Perplexity APIs, Ranked by Use Case

This ranking reflects how closely each product matches the usual reason developers search for “Perplexity AI API”: adding current web information to an application. It is not a claim that one API is technically better than another.

1. Agent API: Best for Web-Grounded Answers

The Agent API is the closest match to the familiar Perplexity experience. It can use a selected model or a preset, call web tools, and return a generated answer with supporting sources.

Its canonical endpoint is POST /v1/agent. Perplexity also accepts POST /v1/responses as an alias so existing OpenAI Responses API integrations can use the service with limited changes. The base URL for that compatibility layer is:

https://api.perplexity.ai/v1

Agent API costs are additive. You pay the selected model's token rate, then pay separately for any tools invoked. A web_search call currently costs $0.0025; fetch_url costs $0.0005.

That makes Agent the easiest option for producing cited answers, but not the easiest bill to forecast. One user request can trigger model tokens and several tool calls.

Verdict: Start here if the search step and written answer belong in the same request.

2. Search API: Best for Raw Search Results

The Search API returns ranked results with titles, URLs, snippets, and extracted content. It also supports domain, language, country, and date controls.

It costs $5 per 1,000 successful requests, or $0.005 per request, with no additional token charge for the Search API response. One request may contain up to five queries and still count as one billing unit, although each query consumes a rate-limit unit.

There is a less obvious boundary: a successful request is billable even when it returns no results. Invalid, rate-limited, and upstream-failed requests are not billed.

Search gives you more control than Agent, but also more work. Your application must decide how to rank, summarize, cite, cache, or display the results.

Verdict: Choose Search when the result set is the product—or when you already have your own generation layer.

3. Router API: Best for Hosted Open-Weight Models

The Router API provides a common endpoint for open-weight models hosted by Perplexity. It supports OpenAI- and Anthropic-compatible interfaces, which can reduce the amount of provider-specific integration code.

Router requests are billed at the requested model's published token rates. There is no separate per-request fee. Cache reads, cache writes, long context, and reasoning tokens may have model-specific rates.

The important distinction: Router is not automatically a web-search API. Calling a model through Router does not recreate the cited Perplexity answer experience.

Verdict: Use Router for model access. Do not select it merely because your application needs current web information.

4. Embeddings API: Best for Custom RAG

Perplexity offers standard and contextualized embedding models. Current published rates are:

Model Dimensions Price per 1M tokens
pplx-embed-v1-0.6b 1,024 $0.004
pplx-embed-v1-4b 2,560 $0.03
pplx-embed-context-v1-0.6b 1,024 $0.008
pplx-embed-context-v1-4b 2,560 $0.05

Embeddings are inexpensive compared with generation. The trade-off is ownership: you must supply the documents, vector store, retrieval logic, and generation model.

Verdict: Pick Embeddings when control over the corpus and retrieval pipeline matters more than a ready-made web answer.

Perplexity AI API Pricing and Cost

The phrase “Perplexity API cost” does not have one number. Each API measures usage differently.

The following prices were checked against Perplexity's published pricing on August 20, 2026.

Current Sonar and Tool Pricing

Product Input Output Other charges
Sonar $1/1M tokens $1/1M tokens Request fee may apply by search context
Sonar Pro $3/1M tokens $15/1M tokens Request fee may apply by search context
Sonar Reasoning Pro $2/1M tokens $8/1M tokens Request fee may apply by search context
Sonar Deep Research $2/1M tokens $8/1M tokens $2/1M citation tokens; $3/1M reasoning tokens; $5/1K search queries
Search API — — $5/1K successful requests
Agent web_search — — $0.0025/invocation
Agent fetch_url — — $0.0005/invocation
Agent sandbox — — $0.03/session, covering up to 20 active minutes for billing

Do not copy these rates into a permanent budget spreadsheet without a date. API prices and available models change.

How to Calculate Perplexity API Cost

For Search API, the basic formula is simple:

Search API cost = successful requests × $0.005

For Agent API, add the selected model's token cost and the tools actually invoked:

Agent API cost = input tokens + output tokens + tool invocations

Legacy Sonar cost is more complicated because it can combine token rates with search-context or query charges:

Legacy Sonar cost = token cost + applicable request or search cost

Perplexity's own Agent API example uses 500 input tokens, 200 output tokens, and one web search. The published total is $0.006175. In that example, the web search alone costs $0.0025—large enough that estimating tokens but ignoring tools would materially understate the bill.

For production forecasting, log the returned usage data instead of estimating solely from prompt length. Perplexity notes that completed responses may expose the calculated total through usage.cost.total_cost.

How to Get a Perplexity AI API Key

Perplexity's current API key process is:

  1. Open the Perplexity API Console.

  2. Add a payment method under Billing.

  3. Select Buy more credits.

  4. Open the API Keys tab.

  5. Select Generate API Key.

  6. Copy the key and store it in a secret manager or environment variable.

On macOS or Linux, the official documentation uses:

export PERPLEXITY_API_KEY="your_api_key_here"

Do not place the key in browser-side JavaScript or commit it to a repository. Requests should originate from a trusted server environment.

Perplexity also notes that API credits are separate from its other product credits. A consumer subscription balance should not be treated as an API budget.

How to Use the Perplexity AI API

Install the official Python SDK:

pip install perplexityai

The SDK reads PERPLEXITY_API_KEY automatically.

Make an Agent API Request in Python

This example uses an Agent API preset. Presets package the model and tool configuration, so you do not have to specify a model for a basic request.

from perplexity import Perplexity

client = Perplexity()

response = client.responses.create(
    preset="low",
    input="What changed in the Python release notes this week? Cite the sources."
)

print(response.output_text)

Use the native SDK when starting a new integration. It exposes Perplexity-specific parameters directly and avoids manual base URL configuration.

Use Perplexity with the OpenAI Python SDK

If an application already uses the OpenAI Responses interface, change the key and base URL:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["PERPLEXITY_API_KEY"],
    base_url="https://api.perplexity.ai/v1",
)

response = client.responses.create(
    input="Explain the difference between keyword and vector search.",
    extra_body={"preset": "low"},
)

print(response.output_text)

The /v1 suffix matters. The OpenAI SDK sends client.responses.create() requests to /v1/responses, which Perplexity accepts as an alias for its canonical /v1/agent endpoint.

Call the Search API with cURL

Use Search API when you need structured results rather than a generated answer:

curl --request POST \
  --url https://api.perplexity.ai/search \
  --header "Authorization: Bearer $PERPLEXITY_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "query": "Python release notes",
    "max_results": 5,
    "search_context_size": "low"
  }'

max_results accepts values from 1 to 20. Use search_context_size: "low" when short snippets are sufficient; larger extracted passages increase the amount of content your downstream system must process, even though Search API itself has no token charge.

These examples follow the current documentation, but they have not been executed here with a live Perplexity key. Smoke-test them in the publishing environment before release.

Migrating from the Legacy Sonar API

Perplexity states that Sonar Chat Completions is now Agent API and that legacy Sonar support ends on September 27, 2026. This is why many older tutorials are misleading even when their code still works today.

For a new application, use the Agent API instead of building around the legacy Sonar Chat Completions interface.

For an existing integration, check five areas:

  1. Endpoint: move from the legacy Chat Completions endpoint to /v1/agent, or use /v1/responses through the OpenAI SDK.

  2. SDK method: replace chat.completions.create() with the Responses-style method where appropriate.

  3. Request fields: Agent API uses Responses parameters such as input, instructions, and max_output_tokens.

  4. Response parsing: read the Responses output structure rather than assuming choices[0].message.content.

  5. Cost tracking: include tool invocations, not just tokens.

Do not treat migration as a model-name substitution. The request format, response structure, and billing model can all change.

Common Perplexity API Problems

A request returns 401

Confirm that the server received PERPLEXITY_API_KEY and that the authorization header uses the Bearer scheme. Also check that the key belongs to the intended project and has not been revoked.

A request returns 429

Rate limits depend on the account's usage tier and the API being called. A multi-query Search request counts as one billing unit but consumes one rate-limit unit per query, so a five-query request consumes five rate-limit units.

Search succeeds but returns no results

A successful Search API response can be billable even when the result set is empty. Validate narrow domain, language, country, and date filters before sending them at scale.

The OpenAI SDK calls the wrong URL

For Agent API compatibility, set the base URL to exactly:

https://api.perplexity.ai/v1

Leaving off /v1 can send the SDK to an invalid path.

A model name stops working

Available models change. Perplexity exposes the current Agent API catalog at GET /v1/models, and its documentation says this listing does not require authentication. Discover models at runtime or validate configured model IDs during deployment.

Is the Perplexity API Worth Using?

Perplexity earns its place when search is part of the product.

The Agent API is a practical choice when your application needs current information and visible supporting sources without operating its own search pipeline. Search API makes sense when you want Perplexity's result retrieval but prefer to control ranking, summarization, and presentation yourself.

The trade-off is cost and dependency. Agent requests can accumulate model and tool charges. Search results depend on Perplexity's index. A custom retrieval stack requires more engineering, but it gives you control over the corpus, ranking, caching, and failure behavior.

If your workload is ordinary drafting, classification, coding, image generation, or video generation, web search may be incidental rather than essential. Paying for an additional search layer then solves the wrong problem.

Does GPT Proto Offer the Perplexity API?

No. GPT Proto does not currently offer Perplexity or Sonar models. It does not provide an indirect Perplexity endpoint, and you should use Perplexity's official API when you specifically need its web-grounded answers or Search API.

If your application instead needs other language, image, or video models through one account, browse GPT Proto's available model catalog. Check the catalog before designing an integration; model availability should never be inferred from an article about another provider.

Final Recommendation

Choose Agent API when you need a written, web-grounded answer. Choose Search API when you need the underlying results. Router is for open-weight model access, while Embeddings is for a retrieval system you control.

For new projects, the most important decision is simpler: do not start with a legacy Sonar Chat Completions tutorial. Select the API that matches the output your application actually needs, then budget for its real billing unit—tokens, tools, or successful requests.

Frequently Asked Questions

Is the Perplexity AI API free?

Perplexity describes its APIs as pay-as-you-go. A Pro subscription is not required, but the documented API key flow requires adding billing and buying API credits. The Search playground may allow testing without a key; that is not the same as a permanent free API tier.

Do I need Perplexity Pro to use the API?

No. Perplexity's current Quickstart states that no subscription is required for API access.

How do I get a Perplexity API key?

Open the API Console, add a payment method, purchase credits, then generate a key under the API Keys tab. Store it as `PERPLEXITY_API_KEY` rather than hard-coding it.

How much does the Perplexity API cost?

It depends on the product. Search API costs $5 per 1,000 successful requests. Agent API combines the selected model's token charges with fees for tools such as web search. Router and Embeddings are token-based.

What is the difference between Agent API and Search API?

Agent API produces a generated answer and can use search tools. Search API returns structured web results for your application to process.

Is the Perplexity API compatible with the OpenAI SDK?

Yes. Agent API accepts the OpenAI Responses format at a compatible `/v1/responses` alias, and Router supports OpenAI-compatible model calls. Use the correct base URL for the API you selected.

Is the Sonar API being discontinued?

The legacy Sonar Chat Completions API is. Perplexity says it has become part of Agent API and will be supported until September 27, 2026. This does not mean the Sonar model family disappears on that date; the change concerns the legacy API integration.

Does GPTProto provide Perplexity models?

No. GPTProto does not currently list Perplexity or Sonar models. Its model catalog contains other text, image, and video options.

Related Articles

More Blogs
Why Small, Stable AI Models Still Power Everyday Production Workflows

Why Small, Stable AI Models Still Power Everyday Production Workflows

Data checked August 18, 2026. Hugging Face's Summer 2026 report found that the 25 most-downloaded models and the 25 most-liked models had only one entry in common. None of the download leaders had been released in 2026, while 13 came from 2022. One compact embedding model, sentence-transformers/all-MiniLM-L6-v2 , recorded 1.55 billion pulls in the first seven months of the year despite having only 5,156 likes. That does not prove which models generate the most revenue or serve the most production requests. Hugging Face downloads exclude private deployments, API traffic, and distribution outside the Hub. They also include automated pulls and repeated downloads. But the gap still reveals something important: production demand often favors models that are small, specialized, mature, and easy to operate. For teams choosing small models for production AI , the right question is rarely “Which model tops the newest benchmark?” It is “Which model can complete this repeated task at the required quality, latency, and total cost?”

Michael Johnson | 2026-08-19

7 Best Image Editing AI Models in 2026 for API, Batch Editing, and Product Photos

7 Best Image Editing AI Models in 2026 for API, Batch Editing, and Product Photos

The best image editing AI model is GPT Image 2 for difficult, instruction-heavy edits , but it is not the cheapest answer for every workload. Seedream 5.0 Pro is my first pick for ecommerce product imagery, Nano Banana Pro is strongest when text and layout matter, Nano Banana 2 is the practical batch option, and FLUX.2 [max] is the premium reference for consistency-heavy professional work. That distinction matters because an attractive output can still be a failed edit. A model may create beautiful studio lighting while quietly changing a logo, bottle shape, face, or product color. For an ecommerce catalog or a customer-facing editor, those errors cost more than a slightly less cinematic result. This is therefore an Image Edit AI model comparison , not another roundup of consumer photo-editing apps. I am comparing the underlying image-to-image models developers and product teams can put behind an API workflow. If you do not want to upload files, manage keys, or write code, use the browser-based GPTProto AI Image Editor . For new visuals rather than edits, open the AI image generation workspace .

Schuyler Stacy | 2026-08-13

Seedance 2.0 vs Seedance 2.5: Same Prompt, Storyboard, and Real Results

Seedance 2.0 vs Seedance 2.5: Same Prompt, Storyboard, and Real Results

Seedance 2.5 is the better model for cinematic storytelling in our same-prompt test. Its footage feels less like a collection of attractive AI shots and more like one human moment unfolding in front of a camera. The character interaction is more convincing, the transitions feel more purposeful, and the emotion survives from one shot to the next. Seedance 2.0 is not obsolete, though. It follows parts of the written storyboard more literally, costs less at the current GPTProto starting price, and remains a practical choice for repeated drafts or reference-driven jobs that already fit its 15-second limit. The short version: choose Seedance 2.5 for the final cinematic take. Choose Seedance 2.0 when iteration cost, literal shot planning, or an established image/reference-to-video workflow matters more.

Schuyler Stacy | 2026-08-12

7 Best Affordable LLMs for Coding in 2026: API Price vs Performance

7 Best Affordable LLMs for Coding in 2026: API Price vs Performance

The cheapest coding model is not always the cheapest model to use. A model priced at $0.14 per million input tokens looks inexpensive—until it misunderstands the repository, edits the wrong file, and needs three retries. Meanwhile, a model with a higher token price may finish the same patch in one run. That is why this is not another list of models sorted by input price. We first looked for models with enough coding ability to handle terminal work, debugging, and multi-step development tasks. We then compared their input, cached-input, and output prices using the same two simulated workloads. This ranking covers API-accessible LLMs , not coding IDE subscriptions. It also excludes self-hosted models because GPUs, inference infrastructure, maintenance, and engineering time are not free. Prices and benchmark results were checked on August 12, 2026 . Treat them as a snapshot rather than a permanent rate card.

Michael Johnson | 2026-08-12