From 9f53bfe9b7fbcabfac3bf97d84c63f26852bcee3 Mon Sep 17 00:00:00 2001 From: Sameer Kankute Date: Thu, 9 Jul 2026 14:28:48 +0530 Subject: [PATCH] fix(videos): return 404 when video content is not ready OpenAI returns 404 for GET /v1/videos/{id}/content while processing; video_content_handler was ignoring non-2xx responses and the proxy returned 200 with the error JSON as video/mp4. Co-authored-by: Cursor --- litellm/llms/custom_httpx/llm_http_handler.py | 4 ++ tests/test_litellm/test_video_generation.py | 50 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.py index c426714a1bd..2af9d368ecd 100644 --- a/litellm/llms/custom_httpx/llm_http_handler.py +++ b/litellm/llms/custom_httpx/llm_http_handler.py @@ -6879,6 +6879,8 @@ class BaseLLMHTTPHandler: params=data, ) + response.raise_for_status() + # Transform the response using the provider config return video_content_provider_config.transform_video_content_response( raw_response=response, @@ -6957,6 +6959,8 @@ class BaseLLMHTTPHandler: params=data, ) + response.raise_for_status() + # Transform the response using the provider config return await video_content_provider_config.async_transform_video_content_response( raw_response=response, diff --git a/tests/test_litellm/test_video_generation.py b/tests/test_litellm/test_video_generation.py index 3d0472ef96e..f97a65d1fb8 100644 --- a/tests/test_litellm/test_video_generation.py +++ b/tests/test_litellm/test_video_generation.py @@ -1134,6 +1134,56 @@ def test_video_content_handler_uses_get_for_openai(): assert called_url == "https://api.openai.com/v1/videos/video_abc/content" +def test_video_content_handler_raises_on_not_ready_response(): + """OpenAI returns 404 while video is processing; proxy must not return 200.""" + import httpx + from litellm.llms.custom_httpx.http_handler import HTTPHandler + from litellm.llms.base_llm.chat.transformation import BaseLLMException + from litellm.types.router import GenericLiteLLMParams + + if hasattr(litellm, "in_memory_llm_clients_cache"): + litellm.in_memory_llm_clients_cache.flush_cache() + + handler = BaseLLMHTTPHandler() + config = OpenAIVideoConfig() + error_body = ( + '{"error":{"message":"Video is not ready yet, use GET /v1/videos/{video_id} to check status",' + '"type":"invalid_request_error","param":null,"code":null}}' + ) + mock_response = httpx.Response( + status_code=404, + content=error_body.encode(), + request=httpx.Request( + "GET", "https://api.openai.com/v1/videos/video_abc/content" + ), + ) + + mock_client = MagicMock(spec=HTTPHandler) + mock_client.get.return_value = mock_response + + with patch( + "litellm.llms.custom_httpx.llm_http_handler._get_httpx_client", + return_value=mock_client, + ): + with pytest.raises(BaseLLMException) as exc_info: + handler.video_content_handler( + video_id="video_abc", + video_content_provider_config=config, + custom_llm_provider="openai", + litellm_params=GenericLiteLLMParams( + api_base="https://api.openai.com/v1" + ), + logging_obj=MagicMock(), + timeout=5.0, + api_key="sk-test", + client=mock_client, + _is_async=False, + ) + + assert exc_info.value.status_code == 404 + assert "Video is not ready yet" in exc_info.value.message + + def test_video_content_respects_api_base_and_api_key_from_kwargs(): """Test that video_content respects api_base and api_key from kwargs (simulating database entry).""" from litellm.videos.main import video_content