Merge pull request #17771 from BerriAI/litellm_db_videos_issue

fix: respect videos content db creds
This commit is contained in:
Sameer Kankute 2025-12-11 08:27:43 +05:30 • committed by GitHub
commit ad5d94a82f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 42 additions and 15 deletions

View file

@ -1,18 +1,21 @@
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union
from io import BufferedReader
from typing import cast
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union, cast
import httpx
from httpx._types import RequestFiles
import litellm
from litellm.llms.base_llm.videos.transformation import BaseVideoConfig
from litellm.types.videos.main import VideoCreateOptionalRequestParams
from litellm.llms.openai.image_edit.transformation import ImageEditRequestUtils
from litellm.secret_managers.main import get_secret_str
from litellm.types.llms.openai import CreateVideoRequest
from litellm.types.router import GenericLiteLLMParams
from litellm.secret_managers.main import get_secret_str
from litellm.types.videos.main import VideoObject
from litellm.types.videos.utils import encode_video_id_with_provider, extract_original_video_id
import litellm
from litellm.llms.openai.image_edit.transformation import ImageEditRequestUtils
from litellm.types.videos.main import VideoCreateOptionalRequestParams, VideoObject
from litellm.types.videos.utils import (
encode_video_id_with_provider,
extract_original_video_id,
)
if TYPE_CHECKING:
from litellm.litellm_core_utils.litellm_logging import Logging as _LiteLLMLoggingObj

View file

@ -271,7 +271,6 @@ def video_generation( # noqa: PLR0915
@client
def video_content(
video_id: str,
api_base: Optional[str] = None,
timeout: Optional[float] = None,
custom_llm_provider: Optional[str] = None,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@ -384,8 +383,6 @@ def video_content(
@client
async def avideo_content(
video_id: str,
api_key: Optional[str] = None,
api_base: Optional[str] = None,
timeout: Optional[float] = None,
custom_llm_provider: Optional[str] = None,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
@ -400,8 +397,6 @@ async def avideo_content(
Parameters:
- `video_id` (str): The identifier of the video whose content to download
- `api_key` (Optional[str]): The API key to use for authentication
- `api_base` (Optional[str]): The base URL for the API
- `timeout` (Optional[float]): The timeout for the request in seconds
- `custom_llm_provider` (Optional[str]): The LLM provider to use
- `extra_headers` (Optional[Dict[str, Any]]): Additional headers
@ -425,8 +420,6 @@ async def avideo_content(
func = partial(
video_content,
video_id=video_id,
api_key=api_key,
api_base=api_base,
timeout=timeout,
custom_llm_provider=custom_llm_provider,
extra_headers=extra_headers,

View file

@ -832,6 +832,37 @@ 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_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
# Mock the handler to capture litellm_params
captured_litellm_params = None
def capture_litellm_params(*args, **kwargs):
nonlocal captured_litellm_params
captured_litellm_params = kwargs.get("litellm_params")
return b"mp4-bytes"
with patch('litellm.videos.main.base_llm_http_handler') as mock_handler:
mock_handler.video_content_handler = capture_litellm_params
# Call video_content with api_base and api_key in kwargs (simulating database entry)
# This simulates how the router passes model config from database via **kwargs
result = video_content(
video_id="video_test_123",
custom_llm_provider="azure",
api_base="https://test-resource.openai.azure.com/", # Passed via kwargs by router
api_key="test-api-key-from-db", # Passed via kwargs by router
)
# Verify that api_base and api_key from kwargs were included in litellm_params
assert captured_litellm_params is not None
assert captured_litellm_params.get("api_base") == "https://test-resource.openai.azure.com/"
assert captured_litellm_params.get("api_key") == "test-api-key-from-db"
assert result == b"mp4-bytes"
def test_openai_video_config_has_async_transform():
"""Ensure OpenAIVideoConfig exposes async_transform_video_content_response at runtime."""
cfg = OpenAIVideoConfig()