DEV Community

Sangmin Lee
Sangmin Lee

Posted on • Originally published at claudeguide.io

Claude API 502 bad_gateway: 원인과 해결법 (2026)

Originally published at claudeguide.io/claude-api-error-502

Claude API 502 bad_gateway: 원인과 해결법 (2026)

Claude API 502 bad_gateway는 Anthropic의 upstream proxy가 백엔드와 통신 실패 시 (Bedrock에서 흔함)에 발생합니다. Upstream gateway 오류이며, exponential backoff 재시도가 효과적해야 합니다. 이 글은 5가지 흔한 원인과 Python/TypeScript 코드 예시를 다룹니다.

전반적인 Claude API 에러 처리 패턴은 Claude API Error Handling 가이드를 참고하세요.


무엇을 의미하는가?

502 HTTP 상태 코드는 Anthropic의 upstream proxy가 백엔드와 통신 실패 시 (Bedrock에서 흔함)을 의미합니다. Anthropic API의 에러 응답 본문에는 error.type"bad_gateway"로 명시되며, error.message에 구체적 사유가 옵니다.

응답 예시:

{
  "type": "error",
  "error": {
    "type": "bad_gateway",
    "message": "..."
  }
}
Enter fullscreen mode Exit fullscreen mode

흔한 원인 5가지

  1. Bedrock proxy → Anthropic upstream 연결 일시 끊김
  2. Vertex AI 사용 시 GCP backend 일시 장애
  3. 긴 streaming 세션 중 connection drop
  4. Cloudflare/CDN 레벨 일시 장애

해결 코드 (Python)

# Treat 502 same as 5xx — retry with backoff
import time, anthropic

def retry_502(fn, max_retries=5):
    for attempt in range(max_retries):
        try:
            return fn()
        except anthropic.APIError as e:
            if e.status_code != 502 or attempt == max_retries - 1:
                raise
            time.sleep([3, 10, 30, 60, 120][attempt])
Enter fullscreen mode Exit fullscreen mode

해결 코드 (TypeScript)


typescript
async function retry502<T
Enter fullscreen mode Exit fullscreen mode

Top comments (0)