Perplexity API keys are generated on the API keys page of a project in the Perplexity API console (console.perplexity.ai/project/keys), and the full key is shown only once. Send the key as Authorization: Bearer $PERPLEXITY_API_KEY, the environment variable Perplexity's SDKs and quickstart use. Perplexity API keys can also be generated and revoked through the /generate_auth_token and /revoke_auth_token endpoints.
Perplexity key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| API key Perplexity's key-management examples show keys starting with pplx-; the docs do not state a fixed format. Audit Log API and Analytics API keys are separate Enterprise keys. | pplx- | Yes | The project it was generated in; the project holds billing, usage and members | — |
How to create a Perplexity key
- Sign in to the Perplexity API console at
console.perplexity.ai. - Create a project first if you have none, on the project settings page.
- Open API keys in the sidebar and click + Generate API Key.
- Copy the key immediately. Perplexity displays the full key value only once.
- Export it as
PERPLEXITY_API_KEY, or store it in a secrets manager.
Open Perplexity's key settings
Limiting what the key can do
Perplexity API keys are scoped to a project, so use separate projects for separate teams or environments. Project roles control the console: an Admin can invite or remove members, manage billing and view usage, while a Member cannot open the Billing page or see usage metrics.
How to rotate a Perplexity key
- Generate a new key while the current key is still active, in the console or with
POST https://api.perplexity.ai/generate_auth_tokenand a descriptivetoken_name. - Update every application with the new key and verify it with a test request.
- Monitor until all services use the new key.
- Revoke the old key with
POST https://api.perplexity.ai/revoke_auth_token.
Perplexity API keys have no automatic overlap window; the old key works until it is revoked. Perplexity's rotation scripts wait 30 seconds for propagation before revoking. Keys provisioned through Stripe Projects are the exception: a rotated-out key keeps working for 24 hours. Perplexity suggests rotating every 90 days.
How to revoke a Perplexity key
- Revoke the key from the API keys page of the project in the API console.
- Or call
POST https://api.perplexity.ai/revoke_auth_tokenwith a valid key in theAuthorizationheader and the key to revoke asauth_token; success returns200 OK. - A revoked Perplexity API key cannot be recovered, so update applications before revoking.
If your Perplexity key leaked
- Revoke the exposed Perplexity API key on the API keys page or with
/revoke_auth_token. - Generate a replacement key and deploy it to every service that used the old one.
- Ask a project Admin to check usage and the Billing page for spend you do not recognise, since only Admins can see them.
- On Enterprise plans, review the Audit Log API for key and member changes.
- Turn on GitHub push protection; GitHub secret scanning detects Perplexity API keys before they are pushed.
Environment variables and CLI
Perplexity's SDKs and docs read the key from PERPLEXITY_API_KEY.
Things that catch people out
- Perplexity API keys are blocked when the project runs out of prepaid credits, which looks like an authentication failure. Perplexity recommends auto reload.
- The full key is shown only once, at creation.
- Perplexity's docs say never to print the key or any part of it, including in tests.
- The Perplexity MCP server reads
PERPLEXITY_API_KEY; reference the variable in MCP config files instead of pasting the key.
Common Perplexity authentication errors
invalid_api_key
HTTP 401. Perplexity returns this when the API key is invalid or deleted, or the account has run out of credits. Sending the key in an x-api-key header also returns 401, because only the bearer header is read.
Recent incidents that put Perplexity keys at risk
If you were affected by one of these, rotate your Perplexity keys using the rotation steps above.
- VS Code and Open VSX extensions leaked 550+ secrets, including tokens that could publish updates 2025-10-15
Using your Perplexity key with AI agents
A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.
BotPassword works this way. For a Perplexity key, these intents fit:
| Intent | What BotPassword does |
|---|---|
run_with | Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output. |
http_request | Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused. |
store_secret | Saves a value the agent already holds as a new vault item. |
capture_secret | Planned, not built yet: will read a newly created key straight from the page or command output into the vault. |
Perplexity also publishes its own MCP server. Whatever server the agent uses, keep the credential it authenticates with out of the agent's context.
Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents
Frequently asked questions
Where do I get a Perplexity API key?
Generate one on the API keys page of your project in the Perplexity API console at console.perplexity.ai/project/keys, with + Generate API Key.
What environment variable does the Perplexity API use?
PERPLEXITY_API_KEY, which Perplexity's Python and TypeScript SDKs and its MCP server read.
How do I rotate a Perplexity API key?
Generate a new key, update and test your applications, then revoke the old key. Revoked Perplexity API keys cannot be recovered.
Why does my Perplexity API key return 401?
Perplexity returns 401 when the key is invalid or deleted, when the account is out of credits, or when the key is sent in x-api-key instead of the Authorization: Bearer header.
Does Perplexity have an MCP server?
Yes. Perplexity hosts a remote MCP server at https://api.perplexity.ai/mcp and publishes a local one as @perplexity-ai/mcp-server; both can use PERPLEXITY_API_KEY.
Can an AI agent use my Perplexity key without seeing it?
Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with run_with, http_request, store_secret, so the agent gets the result and never the value.