401 Authorization Required Response in API

My credits are burning but im getting 401s… why?

Here’s a fresh, first-hand capture of what happens when this backend calls Perplexity right now:

REQUEST:
{
"model": "sonar",
"messages": [
{
"role": "system",
"content": "You are a concise news analyst. Always reply with raw JSON."
},
{
"role": "user",
"content": "Return a minimal JSON object with a hello message."
}
],
"temperature": 0.2,
"max_tokens": 200
}

RESPONSE STATUS: 401
HEADERS:
date: Wed, 12 Nov 2025 16:14:25 GMT
content-type: text/html
transfer-encoding: chunked
connection: keep-alive
cf-ray: 99d7527ecdf5e677-DEN
cf-cache-status: DYNAMIC
strict-transport-security: max-age=15552000; includeSubDomains; preload
server: cloudflare

BODY (first 400 chars):
<html>
<head><title>401 Authorization Required</title></head>
<body>
<center><h1>401 Authorization Required</h1></center>
<hr><center>openresty/1.27.4</center>
<script>(function(){function c(){var b=a.contentDocument||a.contentWindow document ...

So every request—including this simple test payload—gets intercepted by Cloudflare (note the cf-ray header and the HTML body). Perplexity counts the call as soon as it hits their edge, which is why credits go down even though the actual API never returns JSON.

This confirms the issue isn’t in our prompt or payload; the token is being blocked before it reaches the service. You’ll need to work with Perplexity to allow this key/IP (or rotate to a key with server-side access). Until then, any automated refresh will yield the same 401 HTML page while still consuming credits.