HTTP 502 Bad Gateway — Upstream Outage & Failover Guide

Occurs when an origin AI vendor drops a connection or experiences a transient outage. API Store Hub automatically fails over lanes, and clients should pair a cross-family fallback model.

Need resilient routing with automatic multi-upstream failover and full request telemetry on API Store Hub?

HTTP 502 Bad Gateway — Upstream Outage & Failover Guide visual architecture diagram — API Store Hub
HTTP 502 Bad Gateway — Upstream Outage & Failover Guide · Base URL https://apistorehub.com · Key prefix sk-ash-

Error runbook

HTTP Status502
Error typebad_gateway
Retry policyRetryable

Occurs when an origin AI vendor drops a connection or experiences a transient outage. API Store Hub automatically fails over lanes, and clients should pair a cross-family fallback model.

Metadata & root causes

  • Origin model provider undergoing emergency maintenance or a regional incident.
  • Stale HTTP keep-alive socket reset mid-flight between gateway and upstream.
  • Application hard-codes a single model ID with zero retry or cross-provider fallback.

3 steps to resolve

  1. Immediate diagnosis: Check live lane health on /status to confirm whether the target model family is experiencing upstream issues.
  2. Apply standard fix: Wrap calls with 2–3 jittered retries, then fall back to a different model family (e.g. Claude ↔ GPT ↔ DeepSeek).
  3. Prevent recurrence in production: Use idempotency keys and a circuit breaker on background jobs so queues drain cleanly on recovery.

Production retry & recovery snippet

cURL

curl -i https://apistorehub.com/v1/chat/completions \
  -H "Authorization: Bearer sk-ash-your_key" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-6.2-sol","messages":[{"role":"user","content":"failover check"}]}'

TypeScript

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://apistorehub.com/v1", apiKey: process.env.API_KEY });
const CHAIN = ["claude-sonnet-5-5", "gpt-6.2-sol", "deepseek-v4-pro"];

export async function completeWithFailover(prompt: string): Promise<string> {
  let lastErr: unknown;
  for (const model of CHAIN) {
    try {
      const res = await client.chat.completions.create({
        model,
        messages: [{ role: "user", content: prompt }],
      });
      return res.choices[0]?.message?.content || "";
    } catch (err: any) {
      lastErr = err;
      if (![502, 503, 504, 529, 429].includes(err?.status)) throw err;
    }
  }
  throw lastErr;
}

Frequently asked questions

Am I billed on API Store Hub when an HTTP 502 (bad_gateway) error occurs?
No. Atomic pre-hold settlement on API Store Hub automatically releases any reserved amount for failed requests that return no valid completion.
How do I tell whether the error originated from my client or upstream?
4xx codes (except 429) usually point to auth headers, wallet quota, or request payload formatting; 429/502/504/529 indicate load or transient upstream conditions visible on /status.
Can I fall back to another model without changing SDKs?
Yes. Pass the fallback model ID (e.g. across Claude, GPT, DeepSeek, or Gemini) inside your retry catch block using your existing sk-ash- API key.