Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion litellm/litellm_core_utils/exception_mapping_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,7 @@ def exception_type( # type: ignore
litellm_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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading