{"record":{"id":"5c47a6f2b997b019","repo":"BerriAI/litellm","slug":"anthropicexception-badgatewayerror-error-str","errorCode":null,"errorMessage":"AnthropicException BadGatewayError - {error_str}","messagePattern":"AnthropicException BadGatewayError - (.+?)","errorType":"exception","errorClass":"BadGatewayError","httpStatus":502,"severity":"error","filePath":"litellm/litellm_core_utils/exception_mapping_utils.py","lineNumber":585,"sourceCode":"                message=f\"AnthropicException - {error_str}\",\n                model=model,\n                llm_provider=\"anthropic\",\n            )\n        elif original_exception.status_code == 429:\n            raise RateLimitError(\n                message=f\"AnthropicException - {error_str}\",\n                llm_provider=\"anthropic\",\n                model=model,\n            )\n        elif original_exception.status_code == 500 or original_exception.status_code == 529:\n            raise litellm.InternalServerError(\n                message=f\"AnthropicException - {error_str}. Handle with `litellm.InternalServerError`.\",\n                llm_provider=\"anthropic\",\n                model=model,\n                response=getattr(original_exception, \"response\", None),\n            )\n        elif original_exception.status_code == 502:\n            raise BadGatewayError(\n                message=f\"AnthropicException BadGatewayError - {error_str}\",\n                llm_provider=\"anthropic\",\n                model=model,\n                response=getattr(original_exception, \"response\", None),\n            )\n        elif original_exception.status_code == 503:\n            raise litellm.ServiceUnavailableError(\n                message=f\"AnthropicException - {error_str}. Handle with `litellm.ServiceUnavailableError`.\",\n                llm_provider=\"anthropic\",\n                model=model,\n                response=getattr(original_exception, \"response\", None),\n            )\n        elif original_exception.status_code == 504:  # gateway timeout error\n            raise Timeout(\n                message=f\"AnthropicException Timeout - {error_str}\",\n                model=model,\n                llm_provider=\"anthropic\",\n                exception_status_code=original_exception.status_code,","sourceCodeStart":567,"sourceCodeEnd":603,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/exception_mapping_utils.py#L567-L603","documentation":"Anthropic-specific status mapping: an upstream Anthropic error with HTTP 502 is re-raised as BadGatewayError with the 'AnthropicException' prefix, signaling a gateway-level failure between LiteLLM and Anthropic.","triggerScenarios":"Thrown at litellm/litellm_core_utils/exception_mapping_utils.py:585 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Anthropic's gateway returned an error; retry with backoff.","Check https://status.anthropic.com for incidents."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}