How to Generate a Perplexity API Key
🔍 WiseChecker

How to Generate a Perplexity API Key

To use Perplexity programmatically in your own applications, scripts, or third-party tools, you need an API key. This key acts as a unique token that authenticates your requests to the Perplexity API. Without it, you cannot access the search, chat, or completion endpoints.

The process requires a paid Perplexity Pro subscription. Free accounts do not have API access. Once you subscribe, you can generate the key from your account settings page. This article walks you through the exact steps to create and copy your first Perplexity API key.

You will also learn how to set the key in common development environments and how to avoid security mistakes that could expose your key.

Key Takeaways: Generating Your First Perplexity API Key

  • Perplexity Pro subscription required: Only Pro subscribers can create and use API keys.
  • Settings > API > Generate Key: The exact menu path to create a new key.
  • Environment variable PERPLEXITY_API_KEY: Best practice for storing the key securely in development.

ADVERTISEMENT

What You Need Before Generating a Perplexity API Key

The Perplexity API is not available on the free tier. You must have an active Perplexity Pro subscription. As of 2025, Pro costs $20 per month and includes unlimited search queries, access to GPT-4, Claude, and other models, as well as API access.

You also need a Perplexity account. If you do not have one, sign up at perplexity.ai with an email address or Google account. Then subscribe to Pro from the Settings > Subscription page.

Once subscribed, the API section becomes visible in your account settings. No additional setup or developer tools are required on your local machine to generate the key itself.

Steps to Generate Your Perplexity API Key

  1. Log in to Perplexity
    Open your browser and go to perplexity.ai. Sign in with the account that has an active Pro subscription.
  2. Open Settings
    Click your profile picture or initials in the top-right corner. Select Settings from the dropdown menu.
  3. Navigate to the API section
    In the left sidebar, click API. This page shows your existing API keys and lets you create new ones.
  4. Generate a new key
    Click the Generate Key button. A dialog box appears asking you to name the key. Enter a descriptive name such as “Development” or “MyApp-v1”.
  5. Copy the key immediately
    After you click Generate, the new key appears as a long alphanumeric string. Click the copy icon next to it. Perplexity does not show the full key again after you leave this page. Store it in a secure password manager or environment variable file.

Using the Key in a Development Environment

The most secure way to use your API key is through an environment variable. On macOS or Linux, add this line to your shell profile file, for example .zshrc or .bashrc:

export PERPLEXITY_API_KEY="your-key-here"

On Windows, set it via System Properties > Environment Variables or run this command in Command Prompt:

setx PERPLEXITY_API_KEY "your-key-here"

In Python, you can access it with os.getenv('PERPLEXITY_API_KEY'). Never hard-code the key directly into your source code files.

ADVERTISEMENT

Common Mistakes and Security Warnings

I Lost My API Key After Closing the Browser Tab

Perplexity does not store the full key in plain text on the settings page after generation. If you did not copy it, you cannot retrieve it. You must generate a new key and immediately save it to a secure location like a password manager.

My API Key Was Exposed on GitHub

If you accidentally committed your key to a public repository, revoke it immediately. Go to Settings > API, find the key, and click Revoke or Delete. Generate a new key and add .env or .gitignore rules to prevent future leaks.

API Calls Return 401 Unauthorized

A 401 error means the API key is missing, expired, or invalid. Check that your environment variable is set correctly. If you regenerated the key, update your application with the new value. Also confirm your Pro subscription is still active.

Perplexity Free vs Pro: API Access Comparison

Item Free Plan Pro Plan
API key generation Not available Available from Settings > API
Monthly cost $0 $20
Rate limit None Higher tier, depends on usage
Model access Perplexity default model only GPT-4, Claude, Llama, and more

You now have a working Perplexity API key and know how to use it securely. Start by making a test request with curl or a Python script to verify the key works. For production applications, always rotate keys periodically and monitor usage from the API dashboard in Settings.

ADVERTISEMENT