Perplexity API: Agent API, Search API, pricing and live Twitter (X) data

By TwitterAPI.io Team•12 min read
Diagram: a question goes to the Perplexity Search API and to TwitterAPI.io advanced_search, and both feed a Perplexity Agent API answer
One research agent, two sources: Perplexity for the web, TwitterAPI.io for live X posts. Prices from each vendor's docs.

This page is the developer guide to the Perplexity API itself: what each endpoint does, what it costs, how the rate limits work and how to get a key, as written in docs.perplexity.ai this year. If you are comparing model gateways instead, our OpenRouter API guide covers routing many models through one key; if you want the X-native assistant, the Grok API key guide covers xAI. Here the focus is Perplexity, plus the one thing its docs do not cover: live posts from X.

A lot of the material that ranks for this keyword still describes the old Sonar Chat Completions endpoint, sonar-pro examples and per-request search context fees. Perplexity's own docs now point every new project at the Agent API and the Search API, and say Sonar Chat Completions support ended on September 27, 2026. We read the current pricing, rate-limit, Search, Agent and migration pages for this guide and saved their text. We did not call the Perplexity API (we hold no Perplexity key), so every Perplexity number below is the documented price, not a measured bill.

The X side is measured. In 2026 we pulled 498 recent X posts about the Perplexity API and Sonar, plus the last 200 posts from @perplexity_ai and from CEO @AravSrinivas, through TwitterAPI.io. The result shows why a research agent that wants to know what developers are saying right now needs a second source next to the web index.

01 — Section

What the Perplexity API includes today

Perplexity's docs describe five APIs on one key. The two most developers need are the Agent API and the Search API.

APIEndpointWhat you getBilling
Agent APIPOST https://api.perplexity.ai/v1/agent (alias https://api.perplexity.ai/v1/responses)A cited answer from a chosen model or effort level, with toolsPer token + tool fees
Search APIPOST /searchRanked results: title, url, snippet, datePer successful request
EmbeddingsEmbeddings endpointVectors (pplx-embed-v1-*)Per token
Decisionshttps://api.perplexity.ai/v1/decisionsCalibrated probabilitiesPer input token
OrchestratorOrchestrator endpointsOpenAI / Anthropic format routing (private preview)Per token

Agent API. It follows the OpenAI Responses format, so the docs say you can point the OpenAI SDK at https://api.perplexity.ai/v1 and call client.responses.create(). You either name a model (OpenAI, Anthropic, Google, xAI, NVIDIA and Perplexity families are listed) or an effort level (fast, low, medium, high, xhigh, ultra-preview) that bundles a model, search configuration, step limit and tools. The fast effort level currently runs openai/gpt-6-luna with openai/gpt-5.6-luna as fallback, one step and the web_search tool in Fast Search mode, according to the effort page.

Search API. The docs call it one endpoint, POST https://api.perplexity.ai/search, that returns ranked web results as JSON with no generated answer and no token billing. A request can carry up to five queries, max_results from 1 to 20, search_domain_filter with up to 20 domains, a search_recency_filter of hour, day, week, month or year, and date windows. This is the piece to use when your own model writes the answer.

Official SDKs. Python pip install perplexityai (imported as perplexity) and TypeScript npm install @perplexity-ai/perplexity_ai. Both read PERPLEXITY_API_KEY from the environment.

02 — Section

What happened to Sonar (the sonar api)

If you searched for "sonar api", this is the part that changed. Perplexity's migration page says: "Sonar Chat Completions support ended on September 27, 2026. Synchronous and streaming requests keep working: they are being reformulated as Agent API requests, rolling out gradually by model. Asynchronous Sonar requests are not reformulated and are no longer supported." It recommends moving existing Sonar usage to the Agent API and using the Agent API for all new projects.

The Sonar model still exists as an Agent API model: perplexity/sonar, listed at $0.25 per million input tokens, $2.50 per million output tokens and $0.0625 per million cached input tokens. The migration page maps the old Sonar tiers to effort levels:

Old Sonar Chat CompletionsAgent API effort level
Sonarfast
Sonar Profast
Sonar Reasoning Prolow
Sonar Deep Researchhigh

Request shape. Sonar took a messages array and returned choices. The Agent API takes input and returns a typed output array, with a search_results item for sources and a message item for the answer text. Async jobs move to background mode.

What developers on X were saying. In our 2026 search sample for Sonar terms, 47.0% of 200 posts named Sonar explicitly and 57.0% were replies, which reads like support threads rather than announcements. The "sonar api" phrase also catches unrelated SonarQube posts, so treat that sample as noisy.

03 — Section

Perplexity API pricing, per the docs

All figures below are from Perplexity's pricing, Agent API models and Fast Search pages as read for this guide. They change, so check the pricing page before you budget.

ItemPriceUnit
Search API (standard)$5.00per 1,000 successful requests
Search API, Fast Search$1.00per 1,000 successful requests
Agent API web_search tool$0.0025 ($0.001 Fast Search)per call
Agent API fetch_url tool$0.0005per call
perplexity/sonar model$0.25 in / $2.50 outper million tokens
openai/gpt-6-luna model$0.10 in / $0.50 out (up to 272k context)per million tokens

Search billing details. The docs say billing is per successful POST /search request, not per query, so a request with five queries counts as one billable unit. Invalid, rate-limited and failed requests are not billed, and extracted text limits do not change the price.

Agent billing details. Tokens at each model's rate plus tool fees. A flex service tier runs at 0.5x the listed token prices and priority at 2x, only for models that list those tiers. The fast effort level is configured with the priority tier, so its token cost is double the listed model rate.

Other tools. people_search and finance_search are $0.005 per call; a sandbox session is $0.03 per 20-minute window plus $0.0025 per search query made inside it. Embeddings run from $0.004 to $0.05 per million tokens depending on the model.

04 — Section

Rate limits and usage tiers

Perplexity sets your tier from cumulative credit purchases over the life of the account, not from your current balance.

TierCredits purchasedAgent API QPSAgent TPM
Tier 0$015,000,000
Tier 1$50+36,000,000
Tier 2$250+88,000,000
Tier 3$500+1710,000,000
Tier 4 / 5$1,000+ / $5,000+3313,000,000 / 16,000,000

Two limits at once. An Agent API request must pass a request limit (QPS per organization, shared across models and keys) and a token limit (TPM and TPH per organization and model). The 429 body tells you which: request_rate_limit_exceeded, token_rate_limit_exceeded or overloaded (upstream capacity, not a rate limit). A 429 carries Retry-After and no x-ratelimit-* headers; successful responses carry x-ratelimit-limit, x-ratelimit-remaining, x-ratelimit-used and x-ratelimit-reset.

Search API. 50 query units per second with a burst of 50, the same for every tier. A five-query request is billed once but uses five units.

For comparison on the X side. TwitterAPI.io allows 0.2 requests per second before your first payment, 20 once paid, 50 on Scale and 500 on Business, and up to 1,000 on request.

05 — Section

How to get a Perplexity API key

Create a project first. The API key management page says you must create a project in the console (console.perplexity.ai/project/settings) before you can generate keys.

Generate the key. Open the API Keys page of that project and create a key. The docs warn that the full token is shown only once and cannot be retrieved later, so store it immediately in a secret manager or an environment variable named PERPLEXITY_API_KEY.

Manage keys in code. After the first key exists you can create and revoke more with the /generate_auth_token and /revoke_auth_token endpoints. A revoked key cannot be recovered, so roll new keys into your apps before revoking old ones.

Never ship the key to a browser. The docs say to keep keys out of client-side code and public repositories. The same rule applies to your TwitterAPI.io key: call both from your server.

06 — Section

The X gap: what a web index sees vs what is posted on X

We searched Perplexity's full documentation text for X or Twitter data sources and found none: the built-in tools are web search, image search, URL fetch, people search, finance search, sandbox and MCP. You can add x.com to search_domain_filter, but that only narrows results to pages from that domain that are already in the index; it is not a feed of new posts. We did not call the Search API, so we cannot tell you how many fresh posts that filter returns.

Our X sample shows what you would be trying to catch. Searching X for the exact phrase "perplexity api" (newest first) returned 298 posts covering 574 days, with only 9 in the last 30 days and a median gap of 23.1 hours between posts. That is a thin, bursty stream: a page or two of results covers more than a year, and the newest few posts are the signal that matters.

Metric ("perplexity api" X posts)Value
Posts collected298 over 574 days
Posts in the last 30 days9
Replies34.9%
Posts from accounts under 1,000 followers33.2%
Median / 90th percentile views476 / 15,207

What people talk about. 22.5% of the posts mention pricing, cost or credits and 9.7% mention errors, limits or outages. Those are exactly the questions ("is it down?", "did the price change?") where a live X search adds something the web index does not have yet. Only 1.3% mention the Agent API by name, which suggests the developer conversation has not caught up with the docs.

The official accounts. @perplexity_ai posted 0.42 times a day over the sample window and @AravSrinivas 3.27 times a day. Posts that mention the API, Sonar, docs or developers were 7.6% and 8.8% of their original posts. Median views for those API posts were 148,403 on @perplexity_ai, close to the 150,346 of their other posts.

Bar chart: share of X posts containing perplexity api by topic, pricing 22.5 percent, errors 9.7 percent, MCP 5.4, Search API 5.0, Sonar 4.7, Agent API 1.3
X posts containing "perplexity api" by topic (n=298, collected in 2026). Source: TwitterAPI.io advanced_search, Latest.
07 — Section

Pair Perplexity with live X posts: architecture and cost

The pattern is simple: run the web search and the X search side by side, merge both into one context block, and let a model answer with citations. You can wire the X call in two ways.

Option 1, call both yourself (shown in the code below). Your server calls Perplexity POST /search for web pages and TwitterAPI.io /twitter/tweet/advanced_search for posts, then sends both as context to the Agent API. Predictable cost: one billed request on each side.

Option 2, a custom function in the Agent API. The Agent API's custom functions let the model request a tool you define (for example search_x_posts(query)); the docs say the API never executes it for you, so your code runs the TwitterAPI.io call and returns a function_call_output. The model decides when it needs X data.

Per research queryPerplexity sideX side (TwitterAPI.io)Total
Standard Search + 1 X page$0.005$0.003 (20 tweets)$0.80 per 100 queries
Fast Search + 1 X page$0.001$0.003 (20 tweets)$0.40 per 100 queries
Same X page on the official X APIn/a$0.10 (20 posts at $0.005)$10.00 per 100 queries for the X side

The X price, in context. TwitterAPI.io bills $0.15 per 1,000 tweets returned (15 credits per tweet, minimum 15 credits per request, so an empty search costs $0.00015). The official X API pay-per-usage rate card on docs.x.com/x-api/getting-started/pricing lists $0.005 per post read, which is $5 per 1,000 posts, about 33x more. Our search pages averaged 19.9 tweets each.

Speed. In six single-page searches timed end to end through our shared, rate-limited study client (Python start-up and queue waits included), the median was 3.01 seconds and the slowest 3.93 seconds for 20 tweets. Raw API latency is lower; this is the honest upper figure we measured.

Agent API tokens come on top. The table excludes the answer step. Budget it from the model table: a few thousand tokens of context into perplexity/sonar is a fraction of a cent per answer at $0.25 per million input tokens.

08 — Section

How we collected this

Question. How much developer conversation about the Perplexity API happens on X, how fresh it is, what it is about, and what the X side of a paired research agent costs.

Accounts and queries. Timelines of @perplexity_ai (organization) and @AravSrinivas (CEO, public figure), 200 posts each, via /twitter/user/last_tweets. Searches via /twitter/tweet/advanced_search with queryType=Latest: the exact phrase "perplexity api" (298 posts) and Sonar terms (200 posts), retweets excluded. Plus six single-page searches timed end to end.

Window and size. The most recent posts at collection time, collected in 2026: 898 posts from 57 requests, about $0.15 of credits.

What the sample cannot show. Topic shares come from keyword matching on post text, not manual coding. The Sonar query also catches unrelated SonarQube posts. We did not call the Perplexity API, so we cannot say which of these posts its index would return.

Privacy. Aggregates only. Search results come mostly from private individuals: raw pages were kept off the repository, and the published sample holds de-identified rows with no IDs, URLs, text or handles.

09 — Section

Getting started with the X side

Writing to X is a separate product. If your agent should also post the summary, TwitterAPI.io's write endpoints run through an authenticated session: one /twitter/user_login_v2 login ($0.10, with a proxy you supply) returns login_cookies, then each post such as /twitter/create_tweet_v2 is 60 credits ($0.0006). The call acts as that account, so X can rate-limit, lock or suspend it; keep a human pace, expect occasional re-login, and note that billing is per HTTP 200 call. Reads need no X account.

Free start. New TwitterAPI.io accounts that pass the automatic bot check get up to $1 of free credits (at most 100,000 credits, no card, one per person or network, expiring after 31 days). Purchased credits never expire. Plans run from Starter at $29 a month to Business at $1,499; see /pricing for details.

Next step. Create a key in the TwitterAPI.io dashboard, copy the script below, set PERPLEXITY_API_KEY and TWITTERAPI_IO_KEY, and run it against a question your users actually ask. The full parameter list for advanced_search is in the docs at docs.twitterapi.io.

python
import os, json, requests

BASE = "https://api.twitterapi.io"
PPLX_H = {"Authorization": f"Bearer {os.environ['PERPLEXITY_API_KEY']}", "Content-Type": "application/json"}
X_H = {"X-API-Key": os.environ["TWITTERAPI_IO_KEY"]}

def web_sources(question):
    # Perplexity Search API: one billed request, up to 5 queries
    r = requests.post("https://api.perplexity.ai/search", headers=PPLX_H, timeout=60, json={
        "query": question, "max_results": 5, "max_tokens_per_page": 512,
        "search_type": "fast"})
    r.raise_for_status()
    return [x for x in r.json()["results"] if x.get("snippet")]

def x_posts(query, pages=1):
    # TwitterAPI.io advanced_search: newest posts, 20 per page
    out, cursor = [], ""
    for _ in range(pages):
        r = requests.get(f"{BASE}/twitter/tweet/advanced_search", headers=X_H, timeout=30,
                         params={"query": query, "queryType": "Latest", "cursor": cursor})
        r.raise_for_status()
        d = r.json()
        for t in d.get("tweets", []):
            out.append({"url": t["url"], "text": t["text"], "createdAt": t["createdAt"],
                        "likes": t["likeCount"], "author_followers": t["author"]["followers"]})
        if not d.get("has_next_page"):
            break
        cursor = d["next_cursor"]
    return out

def answer(question, x_query):
    web = web_sources(question)
    posts = x_posts(x_query)
    context = "WEB:\n" + "\n".join(f"- {w['title']} ({w['url']}): {w['snippet'][:400]}" for w in web)
    context += "\n\nX POSTS (newest first):\n" + "\n".join(
        f"- {p['createdAt']} | {p['likes']} likes | {p['url']}: {p['text'][:280]}" for p in posts)
    # Agent API: answer from the supplied context (no extra web_search tool calls)
    r = requests.post("https://api.perplexity.ai/v1/agent", headers=PPLX_H, timeout=120, json={
        "model": "perplexity/sonar",
        "instructions": "Answer from the supplied WEB and X POSTS only. Cite URLs. Say when X posts disagree with the web sources.",
        "input": f"{context}\n\nQUESTION: {question}"})
    r.raise_for_status()
    return r.json()

if __name__ == "__main__":
    res = answer("Is the Perplexity Search API down or slow right now?",
                 '"perplexity api" OR "perplexity search api" -filter:retweets')
    for item in res.get("output", []):
        if item.get("type") == "message":
            print(item["content"][0]["text"])
10 — Questions

Questions readers ask

Is the Perplexity API free?

No free tier is listed in Perplexity's pricing docs. The Search API is $5 per 1,000 successful requests ($1 with Fast Search) and the Agent API bills per token plus tool fees. New accounts start at usage Tier 0 with a 1 QPS Agent API limit.

Is the Sonar API deprecated?

Perplexity's docs say Sonar Chat Completions support ended on September 27, 2026. Synchronous and streaming Sonar requests keep working because they are reformulated as Agent API requests; async Sonar requests are no longer supported. The perplexity/sonar model remains available in the Agent API.

How much does the Perplexity Search API cost?

$5.00 per 1,000 successful requests, or $1.00 per 1,000 with search_type: "fast". A request can carry up to five queries and is billed once. Invalid, rate-limited and failed requests are not billed, per the docs.

How do I get a Perplexity API key?

Create a project in the Perplexity API console, then generate a key on that project's API Keys page. The full key is shown only once. After the first key you can manage more with the /generate_auth_token and /revoke_auth_token endpoints.

What are the Perplexity API rate limits?

Agent API requests are limited per organization from 1 QPS at Tier 0 to 33 QPS at Tiers 4 and 5, plus per-model token limits (TPM and TPH). The Search API allows 50 query units per second for every tier. Tiers rise with cumulative credit purchases ($50, $250, $500, $1,000, $5,000).

Can the Perplexity API search Twitter (X) in real time?

Perplexity's docs list no first-party X data source. You can restrict web search to x.com with search_domain_filter, but that only returns pages already in its index. For posts from the last minutes, call an X data API such as TwitterAPI.io's /twitter/tweet/advanced_search and pass the posts to the model, as in the code on this page.

Does the Perplexity API work with the OpenAI SDK?

Yes for the Agent API, which follows the OpenAI Responses format: point the OpenAI SDK at https://api.perplexity.ai/v1 and call client.responses.create(). For the Chat Completions format the docs point to the Orchestrator API, which is in private preview.

11 — Further reading

Continue

Sources & further reading
More from this series
Build it

Stop reading. Start building.

Starter credits cover real testing on real data. Google sign-in, no card, no application queue.

Get an API key

Already building with TwitterAPI.io? Publish an honest tutorial or build log about it and earn up to $200 a month in API credits.