diff --git a/litellm/llms/modelslab/videos/transformation.py b/litellm/llms/modelslab/videos/transformation.py index 0f6c10a4448..5418f534eac 100644 --- a/litellm/llms/modelslab/videos/transformation.py +++ b/litellm/llms/modelslab/videos/transformation.py @@ -131,9 +131,8 @@ class ModelsLabVideoConfig(BaseVideoConfig): ) -> str: if api_base: return api_base.rstrip("/") - # Use img2video if init_image is present in litellm_params - if litellm_params.get("init_image") or litellm_params.get("input_reference"): - return f"{MODELSLAB_VIDEO_BASE_URL}/img2video" + # Default to text2video; endpoint selection is handled in + # transform_video_create_request based on mapped params return f"{MODELSLAB_VIDEO_BASE_URL}/text2video" def transform_video_create_request( @@ -152,6 +151,10 @@ class ModelsLabVideoConfig(BaseVideoConfig): } request_data.update(video_create_optional_request_params) + # Route to img2video endpoint if init_image is present + if "init_image" in video_create_optional_request_params: + api_base = f"{MODELSLAB_VIDEO_BASE_URL}/img2video" + files_list: List[Tuple[str, Any]] = [] return request_data, files_list, api_base diff --git a/tests/test_litellm/llms/modelslab/videos/test_modelslab_video_transformation.py b/tests/test_litellm/llms/modelslab/videos/test_modelslab_video_transformation.py index 9932ea83298..2744f09c596 100644 --- a/tests/test_litellm/llms/modelslab/videos/test_modelslab_video_transformation.py +++ b/tests/test_litellm/llms/modelslab/videos/test_modelslab_video_transformation.py @@ -112,6 +112,43 @@ class TestModelsLabVideoTransformation: assert data["init_image"] == "https://example.com/frame.jpg" assert "img2video" in url + def test_transform_video_create_request_img2video_auto_route(self): + """When init_image is present, endpoint is auto-routed to img2video.""" + # Start with text2video base URL (what get_complete_url returns by default) + base_url = "https://modelslab.com/api/v6/video/text2video" + + data, files, url = self.config.transform_video_create_request( + model="stable-video-diffusion", + prompt="Camera panning right", + api_base=base_url, + video_create_optional_request_params={"init_image": "https://example.com/frame.jpg"}, + litellm_params=GenericLiteLLMParams(), + headers={}, + ) + + assert data["key"] == "test-api-key" + assert data["init_image"] == "https://example.com/frame.jpg" + # Should auto-route to img2video + assert "img2video" in url + assert "text2video" not in url + + def test_transform_video_create_request_text2video_no_routing(self): + """When no init_image, stays on text2video endpoint.""" + base_url = "https://modelslab.com/api/v6/video/text2video" + + data, files, url = self.config.transform_video_create_request( + model="i2vgen-xl", + prompt="A flowing river", + api_base=base_url, + video_create_optional_request_params={}, + litellm_params=GenericLiteLLMParams(), + headers={}, + ) + + assert data["key"] == "test-api-key" + # Should stay on text2video + assert "text2video" in url + # ------------------------------------------------------------------------- # transform_video_create_response # -------------------------------------------------------------------------