Independent guide. perplexitiai.com is not affiliated with or endorsed by Perplexity AI, Inc. The official site is perplexity.ai.

Perplexity Search API Tutorial

The Search API gives your app fresh, ranked web results in one call: titles, URLs, snippets and dates, with filters for sites, dates, countries and languages. This tutorial takes you from your first request to a working retrieval (RAG) pipeline.

In one line

POST a query to /search, get ranked web results back

Endpoint https://api.perplexity.ai/search · up to 20 results per query and 5 queries per request · $5 per 1,000 requests, or $1 per 1,000 in fast mode · same API key as Sonar.

Choose

Search API vs Sonar API: which do you need?

Search API

Returns the raw results. You decide what to do with them.

  • Show results in your own UI
  • Feed your own LLM (RAG)
  • Monitor news, brands or prices
  • Cheapest per call
results[] → title, url, snippet, date

Sonar API

Searches, reads and writes a cited answer for you.

  • Q&A features and chatbots
  • No model of your own needed
  • Citations included
  • Billed per token plus request fee
choices[0].message.content + citations[]

Tutorial

Perplexity Search API tutorial in 6 steps

1Get your API key

Create a key in the API console and save it as PERPLEXITY_API_KEY. Our API key guide covers storing it safely.

2Make your first search request

cURL
curl -X POST https://api.perplexity.ai/search \
  -H "Authorization: Bearer $PERPLEXITY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "latest renewable energy policy in Sri Lanka",
    "max_results": 5
  }'

3Read the results

Results arrive in results, ranked by relevance. Each has a title, url, snippet of extracted page text, a publish date and last_updated (either can be null).

Response (shortened example)
{
  "id": "…",
  "server_time": "…",
  "results": [
    {
      "title": "Page title",
      "url": "https://example.com/article",
      "snippet": "Extracted text from the page…",
      "date": "2026-09-30",
      "last_updated": "2026-10-02"
    }
  ]
}

4Filter by site, recency, country and language

Narrow results to trusted sources and fresh content. Use a minus sign to exclude a domain.

Python
search = client.search.create(
    query="electric vehicle battery recycling",
    max_results=10,
    search_recency_filter="month",              # hour, day, week, month, year
    country="US",                                # ISO 3166-1 alpha-2
    search_language_filter=["en"],               # ISO 639-1, max 10
    search_domain_filter=["nature.com", "-reddit.com"],  # allow, or "-" to exclude (max 20)
)

Need an exact window? Use publish-date filters:

Python
search = client.search.create(
    query="central bank interest rate decision",
    search_after_date_filter="01/01/2026",    # MM/DD/YYYY
    search_before_date_filter="06/30/2026",
)

5Run several queries at once

Send up to five related queries in a single request, which is useful for comparisons and broad research.

Python
search = client.search.create(
    query=[
        "Perplexity Sonar API pricing",
        "Perplexity Search API pricing",
        "Perplexity Agent API tools",
    ],                       # up to 5 queries in one request
    max_results=5,
)

6Go faster and cheaper

Set search_type to fast for lower latency at $1 per 1,000 requests, and cap snippet length with max_tokens_per_page.

Python
search = client.search.create(
    query="weather Colombo today",
    search_type="fast",         # lower latency, $1 per 1,000 requests
    max_results=3,
    max_tokens_per_page=300,    # keep snippets short
)

Search API request builder

Set your options and copy a ready-made request in cURL or Python.

cURL
Python

Estimated cost: $0.005 per request.

Reference

Search API parameter reference

Request body for POST https://api.perplexity.ai/search.

ParameterTypeDefaultWhat it does
querystring or string[]requiredYour search. Pass a list for up to 5 queries at once.
max_resultsinteger10Results per query: 1–20.
search_typestringwebweb, fast (lower latency, cheaper) or people.
search_recency_filterstring—hour, day, week, month or year.
search_after_date_filterstring—Only results published after a date (MM/DD/YYYY).
search_before_date_filterstring—Only results published before a date (MM/DD/YYYY).
last_updated_after_filterstring—Only pages updated after a date (MM/DD/YYYY).
last_updated_before_filterstring—Only pages updated before a date (MM/DD/YYYY).
search_domain_filterstring[]—Up to 20 domains. Prefix with - to exclude.
countrystring—ISO 3166-1 alpha-2 code, e.g. US, GB, LK.
search_language_filterstring[]—Up to 10 ISO 639-1 codes, e.g. en, fr.
search_context_sizestringhighlow, medium or high.
max_tokensinteger—Total content budget across results (1–1,000,000).
max_tokens_per_pageinteger—Content limit per result (1–1,000,000).

From the official API reference, October 2026.

Recipes

Practical recipes

Build a RAG pipeline with fresh web data

Fetch results, format them as numbered sources, and ask your own language model to answer with citations.

Python
from perplexity import Perplexity

client = Perplexity()

def web_context(question: str, k: int = 5) -> str:
    """Fetch fresh web results and format them as numbered context for any LLM."""
    search = client.search.create(query=question, max_results=k, max_tokens_per_page=500)
    blocks = []
    for i, r in enumerate(search.results, start=1):
        blocks.append(f"[{i}] {r.title}\nURL: {r.url}\nDate: {r.date}\n{r.snippet}")
    return "\n\n".join(blocks)

question = "What changed in the EU AI Act this year?"
context = web_context(question)

prompt = f"""Answer using only the sources below. Cite them like [1], [2].

{context}

Question: {question}"""
# Send `prompt` to the language model of your choice.

Brand and news monitoring

Run on a schedule with a one-day recency filter to catch new mentions.

Python
search = client.search.create(
    query=["your-company-name", "your-product-name review"],
    search_recency_filter="day",
    max_results=10,
)

Search only your documentation

Restrict results to your own docs site for a help-centre search box.

Python
search = client.search.create(
    query="how to configure rate limits",
    search_domain_filter=["docs.yourproduct.com"],
    max_results=8,
)

Production

Best practices

Call from your server

Keep the API key on the backend and expose your own endpoint.

Use fast mode by default

Switch to web search only where quality matters more than speed.

Filter to trusted domains

Allowlists improve quality and reduce noise for focused apps.

Cache and deduplicate

Cache popular queries briefly and remove duplicate URLs across multi-query results.

Handle null dates

date and last_updated can be null; don’t sort or filter on them without a fallback.

Respect source sites

Link back to the original pages and follow each site’s terms when displaying content.

Common errors

CodeLikely causeFix
400Invalid parameterCheck max_results is 1–20, dates use MM/DD/YYYY, and no more than 20 domains or 5 queries.
401Missing or wrong keySend Authorization: Bearer YOUR_KEY and check the environment variable loads.
429Too many requestsRetry with exponential backoff and cache repeated queries.
Empty resultsFilters too strictLoosen recency, domains or language, or rephrase the query.

FAQ

Search API questions

What is the Perplexity Search API?

An API that returns ranked web search results (title, URL, snippet, publish date and last-updated date) for a query, without writing an answer. It’s built for apps and AI pipelines that need fresh web data.

How much does the Search API cost?

$5 per 1,000 requests for standard web search and $1 per 1,000 requests with search_type set to fast. There are no token charges for the results. See our API pricing guide for more.

What’s the difference between the Search API and the Sonar API?

Sonar searches the web and writes a cited answer. The Search API only returns the results, so you decide what to do with them: show them, filter them or feed them to your own model.

How many results can I get per request?

Up to 20 per query with web or fast search. You can send up to 5 queries in one request.

Can I limit results to specific websites?

Yes. Use search_domain_filter with up to 20 domains. Add a minus sign before a domain to exclude it instead.

How do I get only recent results?

Use search_recency_filter (hour, day, week, month or year), or the date filters with MM/DD/YYYY dates.

Do I need a separate key for the Search API?

No. The same Perplexity API key works for Search, Sonar, Agent and the other APIs.

More API guides

Build

Run your first search in under a minute

Grab a key from the official console, paste the cURL example, and see live results.