mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
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 <cursoragent@cursor.com>
This commit is contained in:
parent
60729f733e
commit
9f53bfe9b7
2 changed files with 54 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue