diff --git a/litellm/completion_extras/litellm_responses_transformation/transformation.py b/litellm/completion_extras/litellm_responses_transformation/transformation.py index 85fb0bc8dc6..99a600ce78a 100644 --- a/litellm/completion_extras/litellm_responses_transformation/transformation.py +++ b/litellm/completion_extras/litellm_responses_transformation/transformation.py @@ -1546,6 +1546,18 @@ class OpenAiResponsesToChatCompletionStreamIterator(BaseModelResponseIterator): ], usage=usage, ) + elif event_type in ("response.failed", "error"): + failure_response_data = parsed_chunk.get("response") or {} + if not isinstance(failure_response_data, dict): + failure_response_data = {} + error_data = failure_response_data.get("error") or parsed_chunk.get("error") or parsed_chunk + error_message = error_data.get("message") if isinstance(error_data, dict) else None + raise litellm.APIError( + status_code=500, + message=error_message or "Responses API stream failed", + llm_provider="", + model=failure_response_data.get("model", ""), + ) else: pass # For any unhandled event types, create a minimal valid chunk or skip diff --git a/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py b/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py index 21b60d7a216..b03ba421269 100644 --- a/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py +++ b/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py @@ -21,6 +21,37 @@ if TYPE_CHECKING: from litellm.types.utils import ModelResponse +@pytest.mark.parametrize( + ("chunk", "message"), + [ + ( + { + "type": "response.failed", + "response": { + "model": "gpt-5.6-luna", + "error": {"code": "server_error", "message": "upstream failed"}, + }, + }, + "upstream failed", + ), + ({"type": "error", "code": "server_error", "message": "stream failed"}, "stream failed"), + ( + {"type": "response.failed", "response": "invalid", "error": {"message": "malformed failure"}}, + "malformed failure", + ), + ], +) +def test_response_stream_failure_raises_api_error(chunk, message): + from litellm.completion_extras.litellm_responses_transformation.transformation import ( + OpenAiResponsesToChatCompletionStreamIterator, + ) + + with pytest.raises(litellm.APIError, match=message) as exc_info: + OpenAiResponsesToChatCompletionStreamIterator.translate_responses_chunk_to_openai_stream(chunk) + + assert exc_info.value.status_code == 500 + + def test_convert_chat_completion_messages_to_responses_api_image_input(): from litellm.completion_extras.litellm_responses_transformation.transformation import ( LiteLLMResponsesTransformationHandler,