The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(responses): map upstream 4xx on cancel to client error instead of 500 (#32271)
Mateo Wangb4a10fb134ac
diff --git a/litellm/litellm_core_utils/exception_mapping_utils.py b/litellm/litellm_core_utils/exception_mapping_utils.pyindex 2441cbb3903..d908c5d6f20 100644--- a/litellm/litellm_core_utils/exception_mapping_utils.py+++ b/litellm/litellm_core_utils/exception_mapping_utils.py@@ -2173,7 +2173,7 @@ def exception_type( # type: ignorelitellm_response_headers = _get_response_headers(original_exception=original_exception)try:error_str = redact_string(str(original_exception)) if _ENABLE_SECRET_REDACTION else str(original_exception)- if model:+ if model or custom_llm_provider:if hasattr(original_exception, "message"):error_str = (redact_string(str(original_exception.message))diff --git a/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py b/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.pyindex 53960847fdc..234d04ec481 100644--- a/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py+++ b/tests/test_litellm/litellm_core_utils/test_exception_mapping_utils.py@@ -626,3 +626,26 @@ def test_replicate_422_maps_to_unprocessable_entity():)assert excinfo.value.llm_provider == "replicate"+++def test_upstream_4xx_without_model_maps_to_bad_request():+ """Responses API follow-ups (cancel/get/delete) call ``exception_type`` with+ ``model=None``; the provider mapping used to be gated on ``if model:``, so an+ upstream 400 like Azure's "Cannot cancel a synchronous response." fell through to+ the generic 500 APIConnectionError instead of surfacing as a 400."""+ from litellm.llms.base_llm.chat.transformation import BaseLLMException++ original_exception = BaseLLMException(+ status_code=400,+ message='{"error": {"message": "Cannot cancel a synchronous response.", "type": "invalid_request_error"}}',+ )++ with pytest.raises(litellm.BadRequestError) as excinfo:+ exception_type(+ model=None,+ original_exception=original_exception,+ custom_llm_provider="azure",+ )++ assert excinfo.value.status_code == 400+ assert "Cannot cancel a synchronous response." in excinfo.value.message