# Perplexity API keys: find, store, rotate, and use them safely with AI agents

Source: https://botpassword.com/keys/perplexity
Last checked: 2026-11-08

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.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| API key | `pplx-` | Yes | The project it was generated in; the project holds billing, usage and members | — |

## How to create a Perplexity key

1. Sign in to the Perplexity API console at `console.perplexity.ai`.
2. Create a project first if you have none, on the project [settings](https://console.perplexity.ai/project/settings) page.
3. Open **API keys** in the sidebar and click **+ Generate API Key**.
4. Copy the key immediately. Perplexity displays the full key value only once.
5. Export it as `PERPLEXITY_API_KEY`, or store it in a secrets manager.

## 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

1. Generate a new key while the current key is still active, in the console or with `POST https://api.perplexity.ai/generate_auth_token` and a descriptive `token_name`.
2. Update every application with the new key and verify it with a test request.
3. Monitor until all services use the new key.
4. Revoke the old key with `POST https://api.perplexity.ai/revoke_auth_token`.

## How to revoke a Perplexity key

1. Revoke the key from the **API keys** page of the project in the API console.
2. Or call `POST https://api.perplexity.ai/revoke_auth_token` with a valid key in the `Authorization` header and the key to revoke as `auth_token`; success returns `200 OK`.
3. A revoked Perplexity API key cannot be recovered, so update applications before revoking.

## If the key leaked

1. Revoke the exposed Perplexity API key on the API keys page or with `/revoke_auth_token`.
2. Generate a replacement key and deploy it to every service that used the old one.
3. Ask a project Admin to check usage and the Billing page for spend you do not recognise, since only Admins can see them.
4. On Enterprise plans, review the Audit Log API for key and member changes.
5. Turn on GitHub push protection; GitHub secret scanning detects Perplexity API keys before they are pushed.

## Environment variables

- `PERPLEXITY_API_KEY`

## Gotchas

- 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.

## Using this key with AI agents (BotPassword)

- `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.

## FAQ

### 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.

## Sources

- https://docs.perplexity.ai/docs/getting-started/quickstart
- https://docs.perplexity.ai/docs/admin/api-key-management
- https://docs.perplexity.ai/guides/api-organization
- https://docs.perplexity.ai/docs/resources/faq
- https://docs.perplexity.ai/docs/sdk/error-handling
- https://docs.perplexity.ai/api-reference/decisions-post
- https://docs.perplexity.ai/docs/admin/audit-api
- https://docs.perplexity.ai/docs/getting-started/integrations/stripe-projects
- https://docs.perplexity.ai/docs/getting-started/integrations/mcp-server
- https://github.com/perplexityai/modelcontextprotocol
- https://docs.github.com/en/code-security/secret-scanning/introduction/supported-secret-scanning-patterns
