Step-by-Step Fix
Step 1. Confirm You Are Seeing a 401 Error
A Perplexity 401 error may appear as:
- The exact text "401 Unauthorized"
- "You are not authorized to access this resource"
- "Authentication required"
- A redirect back to the Perplexity login page mid-session
If you are an API user, the JSON response body will typically contain "status": 401 and a message like "detail": "Invalid authentication credentials".
Do not confuse 401 with 403 — 401 means you are not authenticated at all, while 403 means you are authenticated but not permitted. The fixes are different.
Step 2. Fix for Web Users — Log Out and Log Back In
The fastest fix for web users is to fully log out and create a fresh session.
- Go to perplexity.ai/settings/account
- Scroll to the bottom and click Log Out
- Close the tab and open a completely new tab
- Clear your cookies for perplexity.ai:
- Chrome/Edge: Ctrl+Shift+Delete → Cookies → Clear
- Firefox: Ctrl+Shift+Delete → Cookies → Clear Now
- Safari: Settings → Privacy → Manage Website Data → remove perplexity.ai
- Navigate to perplexity.ai and log in again with your credentials
- Test a search query to confirm the 401 error is resolved
This process regenerates a fresh authentication token and eliminates any corrupted session state.
Step 3. Fix for API Users — Verify and Reformat Your API Key
If you are using the Perplexity API and receiving 401 errors, follow these checks in order:
Check 1: Verify your API key is active
- Go to perplexity.ai/settings/api
- Confirm the key you are using appears in the list and is not revoked
- If the key is missing or revoked, generate a new one
Check 2: Verify Bearer token format
Your Authorization header must be exactly:
Authorization: Bearer pplx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Common mistakes that cause 401:
Authorization: pplx-xxxx(missing "Bearer")Authorization: bearer pplx-xxxx(lowercase b — must be capital B)Authorization: Bearer "pplx-xxxx"(quotes around the key — do not include quotes)X-API-Key: pplx-xxxx(wrong header name — Perplexity uses Authorization, not X-API-Key)
Check 3: Send a minimal test request
Test with curl to isolate whether the issue is your key or your code:
curl -X POST https://api.perplexity.ai/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY_HERE" \
-H "Content-Type: application/json" \
-d '{"model":"llama-3.1-sonar-small-128k-online","messages":[{"role":"user","content":"Hello"}]}'
If this returns a 200 response, your key is valid and the problem is in your application code. If it returns 401, the key itself is invalid — generate a new one.
Step 4. Regenerate Your API Key
If your API key is confirmed invalid or you cannot locate it:
- Go to perplexity.ai/settings/api
- Click Generate New Key
- Copy the key immediately — it will only be shown once in full
- Update the key in your application, environment variables, or
.envfile - Do not hardcode the key in source code; store it in an environment variable like
PPLX_API_KEY
Step 5. Check for Browser Extension or Cookie Interference (Web Users)
If logging out and back in does not resolve the 401 error:
- Open Perplexity in an incognito/private window with extensions disabled
- Try to log in and use Perplexity normally
- If it works in incognito: a browser extension is modifying your cookies or request headers
- Disable extensions one at a time in your normal browser to identify the culprit
- Common offenders: Cookie AutoDelete, Privacy Cleaner, VPN browser extensions, header modifier extensions
Why This Happens
A 401 Unauthorized error occurs because Perplexity's server cannot confirm who you are. Every request to Perplexity — whether a web search or an API call — must include a valid credential: either a session cookie (web) or an API key (API). When that credential is missing, expired, or malformed, the server returns 401 and refuses the request.
Session cookies expire naturally after inactivity periods. API keys can be revoked manually, expire if the associated account has payment issues, or become invalid if copied incorrectly. The 401 error means no part of Perplexity's infrastructure is broken — the fix is always to provide a valid credential.
Common Mistakes to Avoid
- Assuming 401 means Perplexity is down — a 401 error is never a server outage. It is always an authentication issue. Checking the status page will show everything operational.
- Forgetting to include "Bearer" in the API Authorization header — the word Bearer is required. Omitting it is the single most common API integration mistake and produces an immediate 401.
- Copying an API key with extra spaces or line breaks — when copying from a browser, it is easy to accidentally include a trailing space. Always trim whitespace from your API key before use.
- Storing API keys in source code — hardcoding API keys means they can be accidentally committed to version control. If a key is exposed this way, revoke it immediately and generate a new one.
- Trying to refresh the page instead of logging out — a refresh does not clear an expired session token. You must fully log out and log back in to get a fresh authentication cookie.
- Generating a new API key without updating it in your application — a fresh key does nothing if your application is still using the old revoked key. After generating a new key, update every location where the key is stored: environment variables, config files, CI/CD secrets, and any deployed instances.
- Using an API key from a different Perplexity account — if you have multiple Perplexity accounts, make sure the API key you are using belongs to the account with an active paid subscription. API access on Perplexity requires a Pro or API subscription.
Perplexity 401 vs 403: What Is the Difference?
It is easy to confuse these two errors. Here is the key distinction:
- 401 Unauthorized: Perplexity cannot verify who you are. You have not provided credentials, or the credentials you provided are invalid or expired. Fix: authenticate (log in or provide a valid API key).
- 403 Forbidden: Perplexity knows who you are, but you are not permitted to access the requested resource. Fix: check your subscription level, account status, or region.
If your error alternates between 401 and 403, start with the 401 fix (log in / refresh credentials) — a 403 after a successful login points to a permission issue, not an authentication issue.
When to Contact Perplexity Support
Contact support@perplexity.ai if:
- You have completed all steps above and still receive 401 errors while logged in
- Your API key shows as active in the dashboard but returns 401 in API calls
- Your account was recently migrated, merged, or changed (for example, switching from Google login to email/password)
- You suspect your account has been locked or flagged
Include your account email, the exact error response, and the steps you have already tried.