---
title: "How to Get Your Perplexity API Key"
description: "This guide walks you through how to get your Perplexity API key and start building with it. From there, it explains the must-know compliance rules and best practices, like showing citations, respecting source policies, handling rate limits, and caching responses, so you can use the API securely and effectively."
author: "Kateryna Poryvay"
published: "2025-09-08T09:00+05:30"
updated: "2026-05-06T07:53:59.268Z"
url: "https://www.apideck.com/blog/how-to-get-your-perplexity-api-key"
tags: ["AI", "Guides & Tutorials"]
---

# How to Get Your Perplexity API Key

Perplexity has turned into more than just their own search-grounded models. The API platform now ships three distinct APIs: **Sonar** (Perplexity's own search-augmented LLMs), **Agent** (proxied access to third-party models from OpenAI, Anthropic, Google, and xAI with web search tools attached), and **Search** (raw ranked web results without LLM synthesis). This guide covers all three, with most of the focus on Sonar because that's where most developers spend.

The other thing worth flagging upfront: Perplexity Pro (the $20/month chat subscription at perplexity.ai) and the Perplexity API are billed separately. A Pro subscription does not give you API access. They share an account but they're independent products.

## Step 1: Create a Perplexity Account

![How to Get Your Perplexity API Key 1](//images.ctfassets.net/d6o5ai4eeewt/5TrVnB6mBEL1ICofM7CHv8/f6f52389ac26a52e9e29578ae63c38c9/Screenshot_2025-09-05_at_12.50.20_2x.png)

Navigate to [perplexity.ai](https://perplexity.ai/) and create an account. Sign-in options:
- Email and password
- Google account (OAuth)
- Apple ID
- Single Sign-On for enterprise accounts

Already a Perplexity Pro subscriber? You still use the same account. Pro and API are billed separately but share authentication.

## Step 2: Access the API Portal

![How to Get Your Perplexity API Key 2](//images.ctfassets.net/d6o5ai4eeewt/7G1E3k0PKijprwlVrRN87h/6232774adecf753f4f1367cafc942745/Screenshot_2025-09-05_at_12.50.49_2x.png)

Once logged in, navigate to the API Portal:

1. Go to [perplexity.ai/account/api/keys](https://perplexity.ai/account/api/keys)
2. Or click your profile icon and select "API"

If you don't see the API option:

![How to Get Your Perplexity API Key 3](//images.ctfassets.net/d6o5ai4eeewt/5ptUpYCnJ8xphz24N4lDiF/4d48334faf326f47ea2a2143911efaa0/Screenshot_2025-09-05_at_12.51.59_2x.png)

- Verify your email address
- Complete your account profile
- Try refreshing or logging out and back in

## Step 3: Add Credits (Required Before Key Generation)

![How to Get Your Perplexity API Key 4](//images.ctfassets.net/d6o5ai4eeewt/4RKgUx2LAi6wl6eCYzu4NK/2b2f1e2656238743421d100df31cf042/Screenshot_2025-09-05_at_12.53.13_2x.png)

Perplexity uses **prepaid credits**, not post-paid billing. You need to load credits before you can generate a key.

1. Click "Add Credits" or "Buy Credits" in the API Portal
2. Enter your credit card information
3. Pick a credit amount (no minimum, but $5 is enough for thousands of Sonar calls during testing)
4. Configure spend controls:
   - Monthly cap on auto-recharge
   - Email alerts at 50%, 75%, 90% of cap
   - Auto-recharge threshold (optional, dangerous for experimentation)

If you have a Perplexity Pro subscription, you get $5/month in API credits automatically. They don't roll over.

The prepaid model trips up developers used to OpenAI's "use now, pay later" approach. If your API calls return `402 Payment Required` errors later, your credit balance is the first thing to check.

## Step 4: Where to Find Your Perplexity API Key

![How to Get Your Perplexity API Key 5](//images.ctfassets.net/d6o5ai4eeewt/L3pXULGZgfwiYwAdYjQ3S/6e06d5bf25ea5b4bd72ece47cc15d97a/Screenshot_2025-09-05_at_12.54.19_2x.png)

In the API Portal, click the "API Keys" tab. You'll see:

- All existing keys with creation dates
- Last-used timestamps
- Usage statistics per key
- Buttons to create, regenerate, or revoke keys

## Step 5: Create a New Perplexity API Key

![How to Get Your Perplexity API Key 6](//images.ctfassets.net/d6o5ai4eeewt/3k5b8QVs5qtePYKJRGdCT5/7f32bafed55247d4b764e7aea3a73115/Screenshot_2025-09-05_at_12.54.33_2x.png)

Click "Generate" or "Create API Key". Configure:

- **Name:** descriptive, like "Production Search Backend", "Local Dev", or "Research Agent". Future you will be grateful.
- **Permissions:** scope the key to specific endpoints if your account supports it.

That's it. There's no model selection step at key creation time. Your key gets access to all Sonar, Agent, and Search API endpoints. Model choice happens per-request in your code.

## Step 6: Copy and Save Your Perplexity API Key

The key appears once. Copy it immediately. Perplexity does not display the secret again after the dialog closes.

Perplexity API keys start with `pplx-` followed by a long alphanumeric string. The fastest way to use it is to set it as an environment variable:

```
export PERPLEXITY_API_KEY="pplx-..."
```

The official Perplexity SDKs and the Vercel AI SDK both default to reading `PERPLEXITY_API_KEY`, so you don't need to pass the key in code once it's set.

Storage recommendations:
- Use `.env` files in development (and add `.env` to `.gitignore`)
- Use a secrets manager in production (AWS Secrets Manager, HashiCorp Vault, GCP Secret Manager)
- Never commit keys to Git, even private repos
- Never paste keys into Slack, email, or shared docs

## Step 7: Test Your Perplexity API Key

With your key set as an environment variable, run a single curl request:

```
curl https://api.perplexity.ai/chat/completions \
  -H "Authorization: Bearer $PERPLEXITY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "sonar",
    "messages": [
      {"role": "user", "content": "What happened in tech news today?"}
    ]
  }'
```

A successful response returns Perplexity's answer along with a `citations` array of source URLs.

A few things to know:

1. **Perplexity's API is OpenAI-compatible.** The endpoint, request shape, and `Authorization: Bearer` header all match OpenAI's. You can point the OpenAI Python SDK at `https://api.perplexity.ai` and it will work.
2. **Citations come back automatically.** You don't need a `return_citations: true` flag. Older guides claim you do. They're out of date.
3. **The base endpoint is `https://api.perplexity.ai`.** Don't confuse this with `perplexity.ai` (the consumer chatbot).

## Is the Perplexity API Free?

No. There is no permanent free tier.

- New accounts: no free credits
- Pro subscribers: $5/month in API credits, doesn't roll over
- Everyone else: pay-as-you-go via prepaid credit purchases

This is different from Google's Gemini API (genuine free tier) and OpenAI (one-time signup credits). If you're prototyping, $5 of Sonar API credits gets you thousands of calls.

## Which Perplexity API Should You Use?

Perplexity now offers three distinct APIs. Pick based on what you're building.

### Sonar API (most common)
Perplexity's own search-augmented LLMs. Each response is grounded in live web search and includes citations as metadata. This is the API the rest of this guide focuses on.

Use Sonar when you want a Perplexity-style answer (search + synthesis + citations) in one call.

### Agent API
Proxied access to third-party frontier models (GPT-5.4, Claude Opus 4.6, Gemini 3.1 Pro, Grok) with web search tools attached. You pay direct provider rates for tokens, plus tool invocation fees ($0.005 per web search, $0.0005 per URL fetch).

Use the Agent API when you want a specific frontier model but with Perplexity's web search and URL-fetching plumbing already wired up. Saves you from building your own search-and-fetch agent.

### Search API
Raw ranked web results without any LLM synthesis. Flat $5 per 1,000 requests, no token costs.

Use the Search API when you're building your own RAG pipeline and only need Perplexity's search infrastructure, not its LLM.

## Which Sonar Model Should You Use?

Within the Sonar API, the current production model lineup as of Q2 2026:

- **Sonar** ($1/$1 per million input/output tokens): the daily driver. Fast, cheap, search-grounded, citations included. Default for most workloads.
- **Sonar Pro** ($3/$15 per million input/output tokens): larger 200K context window, more citations per response, better at multi-source synthesis. Use when Sonar's quality isn't enough.
- **Sonar Reasoning** ($1/$5 per million tokens): chain-of-thought reasoning over web search results. Use for complex factual questions that need step-by-step logic.
- **Sonar Reasoning Pro** ($2/$8 per million tokens): the reasoning variant of Sonar Pro.
- **Sonar Deep Research** ($2/$8 per million tokens, plus per-search and per-reasoning-token fees): the most expensive option, runs multiple iterative searches autonomously, returns a long-form research report. Closest analog to a Deep Research workflow.

On top of the per-token cost, Sonar charges per-request fees that depend on `search_context_size` (low / medium / high). These range from $5 to $14 per 1,000 requests depending on the model. **Older guides that don't mention these request fees are out of date.** Model your traffic before flipping the switch in production.

Models you might see referenced in older tutorials are all retired:
- `pplx-7b-online`, `pplx-70b-online`, `pplx-7b-chat`, `pplx-70b-chat`: all gone
- `sonar-small-online`, `sonar-medium-online`: the original Sonar generation, replaced by the current `sonar` and `sonar-pro` lineup

If you have legacy code targeting any of these, migrate to `sonar` (cheapest current model) or `sonar-pro` (better quality).

## Perplexity API Key Format

Perplexity API keys all start with the prefix `pplx-` followed by a long alphanumeric string. If your key doesn't start with `pplx-`, it's not a Perplexity key.

## Security Best Practices

A leaked Perplexity API key on a public repo can drain your prepaid balance overnight. The basics:

- **Rotate keys quarterly**, not just when you suspect a leak
- **Use a different key per environment.** Dev, staging, and prod should never share a key
- **Monitor usage daily** in the API Portal
- **Set a hard auto-recharge cap.** Without one, a runaway loop can keep recharging your credit card
- **Never expose Perplexity API keys in frontend code.** A key in a React bundle is a key in the wild

## Migrating from OpenAI, Anthropic, Gemini, or Grok to Perplexity

The Perplexity API is OpenAI-compatible, so migrating from OpenAI is the smallest possible code change.

| | OpenAI | Anthropic | Gemini | Grok | Perplexity |
|---|---|---|---|---|---|
| Auth header | `Authorization: Bearer` | `x-api-key` | `x-goog-api-key` | `Authorization: Bearer` | `Authorization: Bearer` |
| Endpoint | `api.openai.com/v1/responses` | `api.anthropic.com/v1/messages` | `generativelanguage.googleapis.com/v1beta/...` | `api.x.ai/v1/chat/completions` | `api.perplexity.ai/chat/completions` |
| Request shape | `messages` array | `messages` + system | `contents` with `parts` | `messages` (OpenAI-compatible) | `messages` (OpenAI-compatible) |
| Env var | `OPENAI_API_KEY` | `ANTHROPIC_API_KEY` | `GEMINI_API_KEY` | `XAI_API_KEY` | `PERPLEXITY_API_KEY` |
| Key format | `sk-...` | `sk-ant-...` | `AIza...` | `xai-...` | `pplx-...` |
| Built-in web search? | no | no | no | optional via tools | yes (Sonar) |
| Citations included? | no | no | no | optional | yes (Sonar) |
| OpenAI SDK works? | ✓ | ✗ | ✗ | ✓ | ✓ |

To migrate from OpenAI, the actual code change is two lines:

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

Then call `client.chat.completions.create(model="sonar", ...)` and the rest of your OpenAI code works.

## Troubleshooting Common Errors

**`401 Unauthorized: invalid API key`** — The key is wrong, expired, or revoked. Check the header format (`Authorization: Bearer pplx-...`), check for trailing whitespace, and regenerate at the API Portal if needed.

**`402 Payment Required`** — Your prepaid credit balance is empty. Add credits in the API Portal. This is the most common Perplexity-specific error.

**`404 model not found`** — You're calling a deprecated model. Migrate from `pplx-7b-online`, `pplx-70b-online`, `sonar-small-online`, `sonar-medium-online` to `sonar` or `sonar-pro`.

**`429 rate_limit_exceeded`** — You're sending requests faster than your tier allows. Implement exponential backoff. Tier limits scale with usage history.

**Empty or missing citations** — Make sure you're using a Sonar model. Citations are automatic on Sonar but Agent API responses depend on which underlying model you proxy to.

## FAQ

**Where do I find my Perplexity API key?**
At [perplexity.ai/account/api/keys](https://perplexity.ai/account/api/keys). Existing keys are listed there, but the secret value is only shown at creation. If you've lost a key, revoke it and create a new one.

**How do I get a Perplexity API key for the first time?**
Sign up at perplexity.ai, navigate to the API Portal, add prepaid credits (no minimum), then click "Generate" to create a key. Copy the `pplx-...` string immediately. The flow takes about three minutes.

**Is the Perplexity API free?**
No. There's no permanent free tier. Pro subscribers get $5/month in API credits but they don't roll over. Everyone else loads prepaid credits.

**Does my Perplexity Pro subscription include API access?**
Sort of. Pro gets you $5/month in API credits, which is enough for testing but not for production. Pro and the API are billed separately and any meaningful API usage requires additional credit purchases on top of the Pro subscription.

**What's the difference between Sonar and Sonar Pro?**
Sonar Pro has a 200K context window, returns roughly twice as many citations per response, and handles multi-step queries better. It costs 3x to 15x more depending on input vs output tokens. Default to Sonar; upgrade to Sonar Pro when you need more context or richer citation metadata.

**What's the Agent API?**
A separate Perplexity API that proxies third-party frontier models (GPT-5.4, Claude Opus 4.6, Gemini 3.1 Pro, Grok) with web search and URL-fetch tools pre-wired. You pay the underlying provider's token rates plus $0.005 per search invocation and $0.0005 per URL fetch.

**What's the Search API?**
Raw ranked web search results, no LLM synthesis. Flat $5 per 1,000 requests, no token costs. For developers building their own RAG pipeline who only want Perplexity's search infrastructure.

**What does a Perplexity API key look like?**
A string starting with `pplx-` followed by alphanumeric characters. Don't share it.

**How do I use Perplexity with the OpenAI SDK?**
Perplexity's API is OpenAI-compatible. Point the OpenAI client at `https://api.perplexity.ai`, pass your `PERPLEXITY_API_KEY`, and call models with their Perplexity names (`sonar`, `sonar-pro`, etc.). Most OpenAI code works unchanged.

**How do I set the PERPLEXITY_API_KEY environment variable in Python?**

```
export PERPLEXITY_API_KEY="pplx-..."
```

Then in Python:

```
from openai import OpenAI
client = OpenAI(
    base_url="https://api.perplexity.ai",
)  # picks up PERPLEXITY_API_KEY from env via OPENAI_API_KEY conflict — set it explicitly:

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

response = client.chat.completions.create(
    model="sonar",
    messages=[{"role": "user", "content": "What's happening in AI today?"}]
)
print(response.choices[0].message.content)
print(response.citations)  # source URLs
```

## Next Steps

With your key working, the official docs are the source of truth:
- [Sonar API quickstart](https://docs.perplexity.ai/docs/sonar/quickstart)
- [Models and pricing](https://docs.perplexity.ai/docs/getting-started/pricing)
- [Agent API docs](https://docs.perplexity.ai/docs/agent)
- [Search API docs](https://docs.perplexity.ai/docs/search)

If you're integrating Perplexity across multiple SaaS tools (CRM, accounting, HRIS, file storage), look at how unified APIs reduce the per-vendor integration work.