The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Merge branch 'main' into litellm_videos_bugs_2
Sameer Kankutebaed9fcea23b
diff --cc tests/test_litellm/test_video_generation.pyindex 32f54409a80,254209c1c07..567f7d53fe4--- a/tests/test_litellm/test_video_generation.py+++ b/tests/test_litellm/test_video_generation.py@@@ -839,251 -826,49 +844,295 @@@ def test_gemini_video_config_has_async_assert callable(getattr(cfg, "async_transform_video_content_response", None))+ def test_encode_video_id_with_provider_handles_azure_video_prefix():+ """+ Test that encode_video_id_with_provider correctly encodes Azure/OpenAI video IDs+ that start with 'video_' prefix.++ This test verifies the fix for the issue where Azure returns video IDs like+ 'video_69323201cf6081909263f751f89991e6', which were previously skipped+ from encoding, causing video status retrieval to default to 'openai' provider.+ """+ from litellm.types.videos.utils import (+ decode_video_id_with_provider,+ encode_video_id_with_provider,+ )++ # Test case: Azure returns a video ID starting with 'video_'+ raw_azure_video_id = "video_69323201cf6081909263f751f89991e6"+ provider = "azure"+ model_id = "azure/sora-2"++ # Encode the video ID with provider information+ encoded_id = encode_video_id_with_provider(+ video_id=raw_azure_video_id,+ provider=provider,+ model_id=model_id+ )++ # Verify the ID was encoded (should be different from the original)+ assert encoded_id != raw_azure_video_id+ assert encoded_id.startswith("video_")++ # Decode the encoded ID to verify provider information is preserved+ decoded = decode_video_id_with_provider(encoded_id)+ assert decoded.get("custom_llm_provider") == provider+ assert decoded.get("model_id") == model_id+ assert decoded.get("video_id") == raw_azure_video_id++ # Verify that encoding an already-encoded ID doesn't double-encode it+ encoded_twice = encode_video_id_with_provider(+ video_id=encoded_id,+ provider=provider,+ model_id=model_id+ )+ assert encoded_twice == encoded_id # Should return the same encoded ID+++class TestVideoEndpointsProxyLitellmParams:+ """Test that video proxy endpoints (status, content, remix) respect litellm_params from proxy config."""++ @pytest.fixture+ def client_with_vertex_config(self, monkeypatch):+ """Create a test client with a proxy config that includes Vertex AI model with litellm_params."""+ import asyncio+ import tempfile+ import yaml+ from fastapi import FastAPI+ from fastapi.testclient import TestClient+ from litellm.proxy.proxy_server import cleanup_router_config_variables, router, initialize+ from litellm.proxy.video_endpoints.endpoints import router as video_router++ # Clean up any existing router config+ cleanup_router_config_variables()++ # Create inline config+ config = {+ "model_list": [+ {+ "model_name": "vertex-ai-sora-2",+ "litellm_params": {+ "model": "vertex_ai/veo-2.0-generate-001",+ "vertex_project": "test-project-123",+ "vertex_location": "global",+ "vertex_credentials": "/path/to/test-credentials.json",+ }+ }+ ]+ }++ # Write config to temporary file+ with tempfile.NamedTemporaryFile(mode='w', suffix='.yaml', delete=False) as f:+ yaml.dump(config, f)+ config_fp = f.name++ try:+ # Initialize the proxy with the test config+ app = FastAPI()+ asyncio.run(initialize(config=config_fp, debug=True))+ app.include_router(router)+ app.include_router(video_router)++ return TestClient(app)+ finally:+ # Clean up temporary file+ import os+ if os.path.exists(config_fp):+ os.unlink(config_fp)++ @pytest.fixture+ def mock_video_generation_response(self):+ """Mock video generation response with encoded video_id."""+ from litellm.types.videos.utils import encode_video_id_with_provider++ # Create an encoded video_id that includes provider and model_id+ original_video_id = "projects/test-project-123/locations/global/publishers/google/models/veo-2.0-generate-001/operations/test-operation-123"+ encoded_video_id = encode_video_id_with_provider(+ video_id=original_video_id,+ provider="vertex_ai",+ model_id="veo-2.0-generate-001",+ )++ return VideoObject(+ id=encoded_video_id,+ object="video",+ status="processing",+ created_at=1712697600,+ model="vertex_ai/veo-2.0-generate-001",+ )++ @pytest.fixture+ def mock_video_status_response(self):+ """Mock video status response."""+ return VideoObject(+ id="video_test_123",+ object="video",+ status="completed",+ created_at=1712697600,+ completed_at=1712697660,+ model="vertex_ai/veo-2.0-generate-001",+ progress=100,+ )++ @pytest.fixture+ def mock_video_content_response(self):+ """Mock video content response (raw bytes)."""+ return b"fake_video_content_bytes"++ @pytest.mark.asyncio+ async def test_video_status_respects_litellm_params(+ self, client_with_vertex_config, mock_video_generation_response, mock_video_status_response+ ):+ """Test that video_status endpoint uses litellm_params from proxy config."""+ from unittest.mock import AsyncMock, MagicMock, patch++ # Create an encoded video_id+ encoded_video_id = mock_video_generation_response.id++ # Mock the router instance+ mock_router_instance = MagicMock()+ mock_router_instance.resolve_model_name_from_model_id.return_value = "vertex-ai-sora-2"+ mock_router_instance.model_names = {"vertex-ai-sora-2"}+ mock_router_instance.has_model_id.return_value = False++ # Mock route_request to capture the data being passed+ # route_request should return a coroutine (not await it), so we return a coroutine+ async def mock_route_request_func(*args, **kwargs):+ return mock_video_status_response++ # Create a coroutine that will be added to tasks+ def create_mock_coroutine(*args, **kwargs):+ return mock_route_request_func(*args, **kwargs)++ with patch("litellm.proxy.proxy_server.llm_router", mock_router_instance):+ with patch("litellm.proxy.common_request_processing.route_request", side_effect=create_mock_coroutine) as mock_route_request:+ # Make request to video_status endpoint+ response = client_with_vertex_config.get(+ f"/v1/videos/{encoded_video_id}",+ headers={"Authorization": "Bearer sk-1234"},+ )++ # Verify the endpoint was called+ assert response.status_code == 200, f"Response: {response.text}"++ # Verify that route_request was called+ assert mock_route_request.called+ call_args = mock_route_request.call_args+ # route_request is called with data as a keyword argument+ data_passed = call_args.kwargs.get("data", {}) if call_args.kwargs else (call_args.args[0] if call_args.args and len(call_args.args) > 0 else {})++ # Verify that model was resolved and added to data+ assert data_passed.get("model") == "vertex-ai-sora-2", (+ f"Expected model to be 'vertex-ai-sora-2', got '{data_passed.get('model')}'. "+ f"Full data: {data_passed}, call_args: {call_args}"+ )+ # Verify that custom_llm_provider is set from decoded video_id+ assert data_passed.get("custom_llm_provider") == "vertex_ai", (+ f"Expected custom_llm_provider to be 'vertex_ai', got '{data_passed.get('custom_llm_provider')}'. "+ f"Full data: {data_passed}"+ )++ @pytest.mark.asyncio+ async def test_video_content_respects_litellm_params(+ self, client_with_vertex_config, mock_video_generation_response, mock_video_content_response+ ):+ """Test that video_content endpoint uses litellm_params from proxy config."""+ from unittest.mock import AsyncMock, MagicMock, patch++ # Create an encoded video_id+ encoded_video_id = mock_video_generation_response.id++ # Mock the router instance+ mock_router_instance = MagicMock()+ mock_router_instance.resolve_model_name_from_model_id.return_value = "vertex-ai-sora-2"+ mock_router_instance.model_names = {"vertex-ai-sora-2"}+ mock_router_instance.has_model_id.return_value = False++ # Mock route_request to capture the data being passed+ # route_request should return a coroutine (not await it), so we return a coroutine+ async def mock_route_request_func(*args, **kwargs):+ return mock_video_content_response++ # Create a coroutine that will be added to tasks+ def create_mock_coroutine(*args, **kwargs):+ return mock_route_request_func(*args, **kwargs)++ with patch("litellm.proxy.proxy_server.llm_router", mock_router_instance):+ with patch("litellm.proxy.common_request_processing.route_request", side_effect=create_mock_coroutine) as mock_route_request:+ # Make request to video_content endpoint+ response = client_with_vertex_config.get(+ f"/v1/videos/{encoded_video_id}/content",+ headers={"Authorization": "Bearer sk-1234"},+ )++ # Verify the endpoint was called+ assert response.status_code == 200, f"Response: {response.text}"++ # Verify that route_request was called+ assert mock_route_request.called+ call_args = mock_route_request.call_args+ # route_request is called with data as a keyword argument+ data_passed = call_args.kwargs.get("data", {}) if call_args.kwargs else (call_args.args[0] if call_args.args and len(call_args.args) > 0 else {})++ # Verify that model was resolved and added to data+ assert data_passed.get("model") == "vertex-ai-sora-2", (+ f"Expected model to be 'vertex-ai-sora-2', got '{data_passed.get('model')}'. "+ f"Full data: {data_passed}, call_args: {call_args}"+ )+ # Verify that custom_llm_provider is correctly set from decoded video_id (not "openai")+ assert data_passed.get("custom_llm_provider") == "vertex_ai", (+ f"Expected custom_llm_provider to be 'vertex_ai', got '{data_passed.get('custom_llm_provider')}'. "+ f"Full data: {data_passed}"+ )++ @pytest.mark.asyncio+ async def test_video_content_preserves_custom_llm_provider_from_decoded_id(+ self, client_with_vertex_config, mock_video_generation_response, mock_video_content_response+ ):+ """Test that video_content preserves custom_llm_provider from decoded video_id."""+ from unittest.mock import AsyncMock, MagicMock, patch++ # Create an encoded video_id+ encoded_video_id = mock_video_generation_response.id++ # Mock the router instance+ mock_router_instance = MagicMock()+ mock_router_instance.resolve_model_name_from_model_id.return_value = "vertex-ai-sora-2"+ mock_router_instance.model_names = {"vertex-ai-sora-2"}+ mock_router_instance.has_model_id.return_value = False++ # Mock route_request to capture the data being passed+ # route_request should return a coroutine (not await it), so we return a coroutine+ async def mock_route_request_func(*args, **kwargs):+ return mock_video_content_response++ # Create a coroutine that will be added to tasks+ def create_mock_coroutine(*args, **kwargs):+ return mock_route_request_func(*args, **kwargs)++ with patch("litellm.proxy.proxy_server.llm_router", mock_router_instance):+ with patch("litellm.proxy.common_request_processing.route_request", side_effect=create_mock_coroutine) as mock_route_request:+ # Make request to video_content endpoint+ response = client_with_vertex_config.get(+ f"/v1/videos/{encoded_video_id}/content",+ headers={"Authorization": "Bearer sk-1234"},+ )++ # Verify the endpoint was called+ assert response.status_code == 200, f"Response: {response.text}"++ # Verify that route_request was called+ assert mock_route_request.called+ call_args = mock_route_request.call_args+ # route_request is called with data as a keyword argument+ data_passed = call_args.kwargs.get("data", {}) if call_args.kwargs else (call_args.args[0] if call_args.args and len(call_args.args) > 0 else {})++ # Most importantly: verify that custom_llm_provider is "vertex_ai" not "openai"+ # This was the bug we fixed - it was defaulting to "openai" before+ assert data_passed.get("custom_llm_provider") == "vertex_ai", (+ f"Expected custom_llm_provider to be 'vertex_ai', "+ f"but got '{data_passed.get('custom_llm_provider')}'. "+ f"Full data: {data_passed}, call_args: {call_args}"+ )if __name__ == "__main__":