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
fix(vertex-ai): encode Lyria predict URL path segments
Emerson Gomesabb655daa885
diff --git a/litellm/llms/vertex_ai/text_to_speech/transformation.py b/litellm/llms/vertex_ai/text_to_speech/transformation.pyindex 81f1cbd5157..17c4f0ed0c0 100644--- a/litellm/llms/vertex_ai/text_to_speech/transformation.py+++ b/litellm/llms/vertex_ai/text_to_speech/transformation.py@@ -17,6 +17,7 @@ from litellm.exceptions import UnsupportedParamsErrorfrom litellm.litellm_core_utils.audio_utils.utils import (speech_media_type_from_audio_bytes,)+from litellm.litellm_core_utils.url_utils import encode_url_path_segmentfrom litellm.llms.base_llm.text_to_speech.transformation import (BaseTextToSpeechConfig,TextToSpeechRequestData,@@ -570,17 +571,32 @@ class VertexAILyriaTextToSpeechConfig(VertexAITextToSpeechConfig):VertexAIInteractionsConfig,)- return VertexAIInteractionsConfig().get_complete_url(+ resolved_project: Final = project++ def mint_access_token(+ _credentials: VERTEX_CREDENTIALS_TYPES | None,+ project_id: str | None,+ ) -> tuple[str, str]:+ return "", project_id or resolved_project++ return VertexAIInteractionsConfig(mint_access_token=mint_access_token).get_complete_url(api_base=api_base,model=base_model,litellm_params={ # mutable-ok: interactions dispatch expects a concrete parameter dictionary**litellm_params,"vertex_project": project,+ "vertex_location": "global",},)location: Final = self.safe_get_vertex_ai_location(litellm_params) or self.get_default_vertex_location()base_url: Final = self.get_api_base(api_base=api_base, vertex_location=location).rstrip("/")- return f"{base_url}/v1/projects/{project}/locations/{location}/publishers/google/models/{base_model}:predict"+ encoded_project: Final = encode_url_path_segment(project, field_name="project")+ encoded_location: Final = encode_url_path_segment(location, field_name="location")+ encoded_model: Final = encode_url_path_segment(base_model, field_name="model")+ return (+ f"{base_url}/v1/projects/{encoded_project}/locations/{encoded_location}"+ f"/publishers/google/models/{encoded_model}:predict"+ )def transform_text_to_speech_request(self,diff --git a/tests/test_litellm/llms/vertex_ai/text_to_speech/test_transformation.py b/tests/test_litellm/llms/vertex_ai/text_to_speech/test_transformation.pyindex a1bb203e67e..3fc5278d3dd 100644--- a/tests/test_litellm/llms/vertex_ai/text_to_speech/test_transformation.py+++ b/tests/test_litellm/llms/vertex_ai/text_to_speech/test_transformation.py@@ -1,4 +1,5 @@import base64+from typing import Finalfrom unittest.mock import MagicMock, Mock, patchimport httpx@@ -259,6 +260,37 @@ class TestVertexAILyriaTextToSpeechConfig:"locations/europe-west4/publishers/google/models/lyria-002:predict")+ def test_get_complete_url_encodes_injected_predict_path_segments(self, monkeypatch: pytest.MonkeyPatch) -> None:+ injected: Final = (+ "victim-project/locations/us-central1/publishers/google/models/other-model:predict?ignored="+ )+ encoded: Final = (+ "victim-project%2Flocations%2Fus-central1%2Fpublishers%2Fgoogle"+ "%2Fmodels%2Fother-model%3Apredict%3Fignored%3D"+ )+ monkeypatch.setitem(+ litellm.model_cost,+ f"vertex_ai/{injected}",+ {+ "vertex_ai_audio_api": "lyria_predict",+ "supported_audio_formats": ["wav"],+ },+ )++ url: Final = VertexAILyriaTextToSpeechConfig().get_complete_url(+ model=injected,+ api_base="https://us-central1-aiplatform.googleapis.com",+ litellm_params={+ "vertex_project": injected,+ "vertex_location": injected,+ },+ )++ assert url == (+ "https://us-central1-aiplatform.googleapis.com"+ f"/v1/projects/{encoded}/locations/{encoded}/publishers/google/models/{encoded}:predict"+ )+def test_get_complete_url_for_lyria_3(self):config = VertexAILyriaTextToSpeechConfig()