Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions litellm/llms/custom_httpx/llm_http_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5602,7 +5602,7 @@ def video_remix_handler(
sync_httpx_client = client

headers = video_remix_provider_config.validate_environment(
api_key=api_key,
api_key=api_key or litellm_params.get("api_key", None),
headers=extra_headers or {},
model="",
)
Expand Down Expand Up @@ -5684,7 +5684,7 @@ async def async_video_remix_handler(
async_httpx_client = client

headers = video_remix_provider_config.validate_environment(
api_key=api_key,
api_key=api_key or litellm_params.get("api_key", None),
headers=extra_headers or {},
model="",
)
Expand Down
113 changes: 113 additions & 0 deletions tests/test_litellm/test_video_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from litellm.cost_calculator import default_video_cost_calculator
from litellm.integrations.custom_logger import CustomLogger
from litellm.litellm_core_utils.litellm_logging import Logging as LitellmLogging
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler
from litellm.llms.custom_httpx.llm_http_handler import BaseLLMHTTPHandler
from litellm.llms.gemini.videos.transformation import GeminiVideoConfig
from litellm.llms.openai.videos.transformation import OpenAIVideoConfig
Expand Down Expand Up @@ -1437,5 +1438,117 @@ def create_mock_coroutine(*args, **kwargs):
)


def test_video_remix_handler_uses_api_key_from_litellm_params():
"""Sync remix handler should fall back to litellm_params api_key when api_key param is None."""
handler = BaseLLMHTTPHandler()
config = OpenAIVideoConfig()

with patch.object(config, "validate_environment") as mock_validate:
mock_validate.return_value = {"Authorization": "Bearer deployment-key"}

with patch.object(config, "transform_video_remix_request") as mock_transform:
mock_transform.return_value = ("https://api.openai.com/v1/videos/video_123/remix", {"prompt": "remix it"})

with patch.object(config, "transform_video_remix_response") as mock_resp:
mock_resp.return_value = MagicMock()

mock_client = MagicMock()
mock_client.post.return_value = MagicMock(status_code=200)

with patch(
"litellm.llms.custom_httpx.llm_http_handler._get_httpx_client",
return_value=mock_client,
):
handler.video_remix_handler(
video_id="video_123",
prompt="remix it",
video_remix_provider_config=config,
custom_llm_provider="openai",
litellm_params={"api_key": "deployment-key", "api_base": "https://api.openai.com/v1"},
logging_obj=MagicMock(),
timeout=5.0,
api_key=None,
_is_async=False,
)

mock_validate.assert_called_once()
assert mock_validate.call_args.kwargs["api_key"] == "deployment-key"


@pytest.mark.asyncio
async def test_async_video_remix_handler_uses_api_key_from_litellm_params():
"""Async remix handler should fall back to litellm_params api_key when api_key param is None."""
handler = BaseLLMHTTPHandler()
config = OpenAIVideoConfig()

with patch.object(config, "validate_environment") as mock_validate:
mock_validate.return_value = {"Authorization": "Bearer deployment-key"}

with patch.object(config, "transform_video_remix_request") as mock_transform:
mock_transform.return_value = ("https://api.openai.com/v1/videos/video_123/remix", {"prompt": "remix it"})

with patch.object(config, "transform_video_remix_response") as mock_resp:
mock_resp.return_value = MagicMock()

mock_client = MagicMock(spec=AsyncHTTPHandler)
mock_response = MagicMock(status_code=200)
mock_client.post = AsyncMock(return_value=mock_response)

with patch(
"litellm.llms.custom_httpx.llm_http_handler.get_async_httpx_client",
return_value=mock_client,
):
await handler.async_video_remix_handler(
video_id="video_123",
prompt="remix it",
video_remix_provider_config=config,
custom_llm_provider="openai",
litellm_params={"api_key": "deployment-key", "api_base": "https://api.openai.com/v1"},
logging_obj=MagicMock(),
timeout=5.0,
api_key=None,
)

mock_validate.assert_called_once()
assert mock_validate.call_args.kwargs["api_key"] == "deployment-key"


def test_video_remix_handler_prefers_explicit_api_key():
"""Sync remix handler should prefer explicit api_key over litellm_params."""
handler = BaseLLMHTTPHandler()
config = OpenAIVideoConfig()

with patch.object(config, "validate_environment") as mock_validate:
mock_validate.return_value = {"Authorization": "Bearer explicit-key"}

with patch.object(config, "transform_video_remix_request") as mock_transform:
mock_transform.return_value = ("https://api.openai.com/v1/videos/video_123/remix", {"prompt": "remix it"})

with patch.object(config, "transform_video_remix_response") as mock_resp:
mock_resp.return_value = MagicMock()

mock_client = MagicMock()
mock_client.post.return_value = MagicMock(status_code=200)

with patch(
"litellm.llms.custom_httpx.llm_http_handler._get_httpx_client",
return_value=mock_client,
):
handler.video_remix_handler(
video_id="video_123",
prompt="remix it",
video_remix_provider_config=config,
custom_llm_provider="openai",
litellm_params={"api_key": "deployment-key", "api_base": "https://api.openai.com/v1"},
logging_obj=MagicMock(),
timeout=5.0,
api_key="explicit-key",
_is_async=False,
)

mock_validate.assert_called_once()
assert mock_validate.call_args.kwargs["api_key"] == "explicit-key"


if __name__ == "__main__":
pytest.main([__file__])
Loading