Perplexity API 502 Bad Gateway

Every Perplexity call is two systems in a trench coat: live retrieval and then generation. A 502 usually means the front door gave up waiting on the retrieval half.

11 min read
Staff Pick

📡 Monitor your APIs — know when they go down before your users do

Better Stack checks uptime every 30 seconds with instant Slack, email & SMS alerts. Free tier available.

Start Free →

Affiliate link — we may earn a commission at no extra cost to you

Live Perplexity status right now

Establish this first. If Perplexity is genuinely degraded, the attribution work below is unnecessary and you should be failing over instead of reading response headers.

A 502 is the only 5xx that is definitionally written by someone other than the component that failed. A gateway asked an upstream for a response, got something it could not use — an empty body, a reset connection, a malformed reply — and substituted an error of its own. Everything useful about a 502 follows from that one fact: your request was fine, the model may never have seen it, and the error you are reading was authored by a middleman.

Which middleman is the entire question. It might be Perplexity's own edge. It might equally be your ingress controller, a service-mesh sidecar, a corporate egress proxy, a CDN, or a routing library sitting between your code and the provider. These produce an identical status code and wildly different remediation, and teams routinely spend an incident refreshing a status page for a failure their own infrastructure emitted.

30-second triage: look at the response Content-Type. JSON with a structured error envelope means Perplexity answered. HTML with a <title>502 Bad Gateway</title> and a server banner means an intermediary answered and the model tier never saw your call. If it is JSON and sustained, check live Perplexity status and fail over. If it is HTML, read your own gateway logs.

502 against the rest of the 5xx family

These five get filed together as “the API is broken” and then handed one retry policy, which guarantees that the policy is wrong for at least three of them. The column that matters is the last one, because it is the only one that changes what you do next.

CodeWho authored itCorrect response
429Perplexity, deliberately, about your allowanceSlow down. Never fail over — you export your own pacing bug
500The service, about an unhandled faultRetry once or twice; a persistent 500 is a bug report
502An intermediary — possibly yoursIdentify the hop first, then one jittered retry
503The service, about having no capacityRetry with a budget, then fail over or degrade
504An intermediary, about a deadline it setRetry only if idempotent; consider raising the timeout

502 and 504 are siblings and both are written by gateways — the difference is that a 504 means the intermediary waited and gave up, while a 502 means it got an answer it could not use. Neither tells you the upstream failed. The capacity case is covered separately in the Perplexity 503 guide, and the throttling case in the Perplexity 429 guide.

📡
Recommended

Know Which Side Wrote the 502

External checks run from outside your own network, so a gateway failure inside your infrastructure looks different from a provider edge failure — instead of identical, which is what your application logs show you.

Try Better Stack Free →

Why Perplexity returns 502 specifically

A Perplexity request does something no other provider on this list does: before a single token is generated, it goes and reads the live web. That retrieval fan-out has a long and fat latency tail, because it depends on third-party sites that Perplexity does not operate and cannot make faster. When a hard query pushes the retrieval leg past whatever read timeout the edge in front of the model holds, the edge does what edges do — it writes a 502 and closes the connection.

This gives Perplexity 502s a distinct signature: they correlate with query difficulty rather than with traffic volume. A broad research-style prompt that fans out across many sources will 502 at a rate a short factual prompt never does, at the same time of day, from the same key. If your 502 rate tracks prompt complexity instead of request rate, you are looking at retrieval, not capacity.

Sample rather than probe once. One request cannot distinguish a total failure from the far more common partial one, and the two call for different responses:

for i in $(seq 1 10); do
  curl -s -o /tmp/body -w "%{http_code} %{time_total}s %{content_type}\n" \
    https://api.perplexity.ai/chat/completions \
    -H "Authorization: Bearer $PPLX_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"model":"sonar-pro","messages":[{"role":"user","content":"ping"}],"max_tokens":1}'
done

Three columns, three answers. The status code tells you whether it failed, the elapsed time tells you whether something waited before failing, and the content type tells you who wrote the error. Ten out of ten failing with a JSON body is an incident. Two out of ten failing with an HTML body is your own infrastructure having a moment, and no amount of provider failover will fix it.

The Perplexity trap: a 502 is a retrieval symptom, and thin citations are the early warning

Degradation here is visible before it becomes an error, and almost nobody instruments for it. As the retrieval half struggles, successful 200 responses start coming back with fewer citations, weaker sources, or none at all — and your code happily renders them because a 200 is a 200. The 502s arrive later, once the edge timeouts start tripping. Counting citations per response gives you a leading indicator of an incident that your error rate will not show for another ten minutes.

The corollary is a product decision worth making in advance: an answer that arrives ungrounded is not the product your users think they bought. Grade it as a soft failure, label it in the interface, and consider whether a slower well-cited answer beats a fast unsourced one for your use case. That framing turns a fuzzy quality problem into something you can alert on.

The streaming case, where the 502 never reaches your status-code metrics

If you stream, a large share of your gateway failures will never be counted as 502s at all. The response headers arrived long ago with a 200; the failure happens partway through the token stream, and what your client receives is a truncated event or an HTML error fragment spliced into a channel that was expecting server-sent events. Most SDKs raise that as a decoding error, so it lands in your logs as a parse failure in the JSON layer and your Perplexity error-rate panel stays flat through the entire incident.

  • Assert on the terminal event. An iterator finishing is not the same as a stream completing. If the terminal marker never arrived, the response was truncated, whatever the status code said.
  • Count partial responses as their own class. Not a success, not a 5xx. They behave differently and they are the metric that moves first.
  • Record bytes and tokens received on failure. A stream that died at token three is a different problem from one that died at token three hundred, and only one of them is worth showing the user.
  • Decide the resume policy in advance. Re-issuing the whole prompt is the honest default and it bills twice; showing the partial output with a visible label is often the better product answer.

A retry policy that fits a 502 specifically

502s are the most retry-friendly 5xx there is — they are usually brief, usually one hop, and usually gone by the time you look. That makes blanket “never retry 5xx” advice actively wrong here. Four rules keep the retry from becoming its own incident:

  • One quick jittered retry first. Randomise across the full window rather than adding a small wobble, so a fleet of clients does not resynchronise and re-burst against the first recovered backend.
  • Assume the work may have happened. The gateway could not read the response; that does not mean the upstream never produced one. Send an idempotency key for anything with a side effect, and expect that a retried completion can bill twice.
  • Budget by ratio, not by count. Allow retries as a fraction of recent successes so the allowance collapses on its own when almost everything is failing — no deploy required. See the Perplexity retry budget guide.
  • Retry against a deadline. If the user-facing request gave up eight seconds ago, attempt three is load on behalf of nobody. Propagate the deadline and skip attempts that cannot finish inside it.

If 502s persist past a handful of retries, they have stopped being transient and the failover machinery should take over — which only works if it was kept warm. The Perplexity failover guide covers keeping a second path tested rather than merely configured, and the circuit breaker guide covers stopping the retries automatically.

Frequently Asked Questions

What does a 502 from the Perplexity API actually mean?

It means some intermediary between your process and the model received an invalid, empty or truncated response from whatever it forwarded your request to, and wrote its own error rather than passing anything through. The crucial word is intermediary: a 502 is never authored by the component that failed, which is what makes it the hardest 5xx to attribute. Your request was almost certainly fine — 502 says nothing about your payload, your key or your model choice — so editing the request is wasted effort. The productive question is not what is wrong with the call but which hop in the path wrote the error, and that is answerable in about thirty seconds from the response itself.

How do I tell a Perplexity 502 from a 502 emitted by my own proxy?

Read the content type and the body, not the status code. Perplexity returns structured JSON error envelopes with recognisable fields and its own identifying response headers. Load balancers, ingress controllers, CDNs and corporate proxies return an HTML page — a short document with a title like "502 Bad Gateway" and a server banner at the bottom. If the body is HTML, the model tier never saw your request and the Perplexity status page is not the document you need. That single check resolves the majority of misattributed incidents, and it costs nothing to log the first 200 bytes of every error body alongside the status code so the evidence is already captured next time.

Is a 502 the same as Perplexity being down?

Not usually, and the difference matters because it changes what you should do. A genuine outage is broad, sustained and consistent across endpoints and keys. A 502 is characteristically brief, patchy and self-clearing — one hop lost one upstream connection for a moment. The test takes seconds: sample the endpoint ten times in a loop rather than once. Ten out of ten failing over several minutes is an incident and warrants failover; three out of ten failing is transient turbulence that a correct retry policy absorbs without anyone noticing. Reacting to a single 502 as though it were an outage is how teams cut over to a fallback provider for an event that had already resolved before the deploy finished.

Is it safe to retry a Perplexity 502?

Safer than most 5xx, with one real caveat. A 502 is typically transient and a single retry after a short jittered delay clears it, which is why blanket "never retry 5xx" advice is wrong here. The caveat is that a 502 tells you the intermediary did not get a usable response — it does not tell you the upstream never did the work. For a chat completion that is a billing question rather than a correctness one, and it is worth knowing that a retried request can be charged twice. For anything with a side effect, propagate an idempotency key so the retry is provably the same operation rather than a second one. Cap retries against a deadline rather than a fixed count, and use full jitter so a fleet of clients does not resynchronise on recovery.

Why does a 502 show up as a JSON parse error instead of a status code in my logs?

Because of streaming. On a streamed response your client has already received a 200 and started consuming server-sent events; if a hop fails mid-stream, what arrives is either a truncated event or an HTML error fragment spliced into a stream that was expecting JSON. Most SDKs surface that as a decoding exception, so the incident lands in your logs as a parse failure and never appears in the status-code panel at all. Handle stream termination explicitly — check for the terminal event rather than assuming the iterator ending means completion — and record partial-response events as their own failure class. Otherwise your dashboards will show a healthy Perplexity error rate throughout an incident your users are watching happen.

Why do my hard research prompts 502 while short questions always work?

Because the two prompts do fundamentally different amounts of work before any generation starts. A short factual question resolves against a small retrieval set; a broad research prompt fans out across many live sources, and its latency is bounded by the slowest third-party site in that set rather than by Perplexity’s own infrastructure. When the total crosses the read timeout of whatever sits in front of the model, you get a 502 that has nothing to do with capacity and everything to do with query shape. Practical response: raise your own client timeout to match the work you are asking for, narrow the prompt or constrain the domains where you can, and split your metrics by prompt class so a research-heavy workload does not average out with your quick lookups and hide the pattern.

Should I fail over to another provider on a 502?

Only after you know which hop wrote it, which is the whole point of the content-type check. If the 502 came from an intermediary you own — an egress proxy, a mesh sidecar, an ingress controller — failing over to a second provider routes the same traffic through the same broken hop and changes nothing except your bill and your confidence. If it genuinely came from Perplexity's edge and is sustained across a sampled loop, failover is the correct response and should be a config flip you have already tested rather than a change you write during the incident. The middle case — brief and patchy — wants neither: it wants one jittered retry and no human involvement at all.

Related Perplexity Guides

Catch the 502 Before Your Users Report It

API Status Check watches Perplexity and the rest of your stack from outside your own network, so you find out whether the gateway that failed was theirs or yours — in seconds, not after twenty minutes of reading a status page that was never going to mention it.

Start Your Free Trial →

Alert Pro

14-day free trial

Stop checking — get alerted instantly

Next time Perplexity goes down, you'll know in under 60 seconds — not when your users start complaining.

  • Email alerts for Perplexity + 9 more APIs
  • $0 charged today — card required to start
  • Cancel anytime — $9/mo after trial

🌐 Can't Access Perplexity?

If Perplexity is working for others but not for you, it might be an ISP or regional issue. A VPN can help bypass network-level blocks and routing problems.

🔒

Troubleshoot with a VPN

Connect from a different region to test if the issue is local to your network. Also protects your connection on public Wi-Fi.

Try NordVPN — 30-Day Money-Back Guarantee
🔑

Secure Your Perplexity Account

Service outages are a common time for phishing attacks. Use a password manager to keep unique, strong passwords for every account.

Try NordPass — Free Password Manager
Quick ISP test: Try accessing Perplexity on mobile data (Wi-Fi off). If it works, the issue is with your ISP or local network.

⏳ While You Wait — Try These Alternatives

🛠 Tools We Use & Recommend

Tested across our own infrastructure monitoring 200+ APIs daily

SEMrushBest for SEO

SEO & Site Performance Monitoring

Used by 10M+ marketers

Track your site health, uptime, search rankings, and competitor movements from one dashboard.

We use SEMrush to track how our API status pages rank and catch site health issues early.

From $129.95/moTry SEMrush Free
View full comparison & more tools →Affiliate links — we earn a commission at no extra cost to you