Cohere API 502 Bad Gateway

Cohere 502s cluster on the embed endpoint during bulk indexing, and the usual cause is a request body too large for something in the path — which is frequently your own proxy, not Cohere.

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 Cohere status right now

Establish this first. If Cohere 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 Cohere'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 Cohere 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 Cohere 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
429Cohere, 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 Cohere 503 guide, and the throttling case in the Cohere 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 Cohere returns 502 specifically

Cohere is three workloads behind one key — chat, embed and rerank — and they generate wildly different request shapes. Chat sends a small body and streams a small one back. Embed, during an indexing run, sends batches of documents that can be megabytes per call. Rerank sits in between. Any intermediary in the path with an opinion about request body size will express that opinion on the embed leg only, and 502 is one of the ways it does so.

That is why a Cohere 502 so often appears to be endpoint-specific in a way that makes no sense as a provider incident: chat is fine, rerank is fine, embed fails on the large batches and succeeds on the small ones. A provider outage does not care how big your body is. A reverse proxy does.

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.cohere.com/v2/chat \
    -H "Authorization: Bearer $CO_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"model":"command-r-plus","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 Cohere trap: the bad gateway is often yours, and it fails by batch size

Before you file anything with Cohere, test the same batch at a tenth of the size. If the small batch succeeds and the large one 502s, deterministically, the ceiling is a body-size or buffer limit somewhere in your egress path — an nginx client_max_body_size, an ingress controller default, a corporate proxy — and it will follow you to any provider you fail over to. This is the fastest and cheapest test in this entire guide and it resolves a large share of Cohere 502 reports on the spot.

The second-order damage is worse than the error. A bulk embed run that fails partway leaves the index inconsistent rather than merely incomplete, and a retrieval system querying a half-built index returns confident nonsense with no error anywhere. Checkpoint by document id and resume, never restart — restarting re-embeds under a possibly different model version and leaves you with vectors that are not comparable to the ones already stored.

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 Cohere 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 Cohere 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 Cohere 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 Cohere 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 Cohere 502 from a 502 emitted by my own proxy?

Read the content type and the body, not the status code. Cohere 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 Cohere 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 Cohere 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 Cohere 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 Cohere error rate throughout an incident your users are watching happen.

My Cohere embed calls 502 but chat works fine — is the embed endpoint down?

Usually not. The distinguishing feature of embed traffic is body size, and the fastest test is to resend the identical batch at a tenth of the size. If the small one succeeds while the large one fails every time, this is a body-size or buffer limit in the path rather than a Cohere fault, and it is almost always on your side — an nginx client_max_body_size, an ingress default, or a corporate proxy. That distinction is worth ninety seconds of your time because the two fixes have nothing in common: a real Cohere incident wants failover and patience, a proxy limit wants smaller batches now and a config change later. And whichever it turns out to be, checkpoint the indexing job by document id first, because a half-finished index is a worse problem than a failed one.

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 Cohere'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 Cohere Guides

Catch the 502 Before Your Users Report It

API Status Check watches Cohere 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 Cohere goes down, you'll know in under 60 seconds — not when your users start complaining.

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

🌐 Can't Access Cohere?

If Cohere 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 Cohere 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 Cohere 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