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
Support env var vertex credentials for passthrough + ignore space id on watsonx deployment (throws Json validation errors) (#11527)
Krish Dholakia2654d3b0b1f8
diff --git a/litellm/llms/watsonx/common_utils.py b/litellm/llms/watsonx/common_utils.pyindex d6f296c6081..c756be6d458 100644--- a/litellm/llms/watsonx/common_utils.py+++ b/litellm/llms/watsonx/common_utils.py@@ -38,7 +38,11 @@ def generate_iam_token(api_key=None, **params) -> str:headers = {}headers["Content-Type"] = "application/x-www-form-urlencoded"if api_key is None:- api_key = get_secret_str("WX_API_KEY") or get_secret_str("WATSONX_API_KEY") or get_secret_str("WATSONX_APIKEY")+ api_key = (+ get_secret_str("WX_API_KEY")+ or get_secret_str("WATSONX_API_KEY")+ or get_secret_str("WATSONX_APIKEY")+ )if api_key is None:raise ValueError("API key is required")headers["Accept"] = "application/json"@@ -280,13 +284,9 @@ class IBMWatsonXMixin:def _prepare_payload(self, model: str, api_params: WatsonXAPIParams) -> dict:payload: dict = {}if model.startswith("deployment/"):- if api_params["space_id"] is None:- raise WatsonXAIError(- status_code=401,- message="Error: space_id is required for models called using the 'deployment/' endpoint. Pass in the space_id as a parameter or set it in the WX_SPACE_ID environment variable.",- )- payload["space_id"] = api_params["space_id"]- return payload+ return (+ {}+ ) # Deployment models do not support 'space_id' or 'project_id' in their payloadpayload["model_id"] = modelpayload["project_id"] = api_params["project_id"]return payloaddiff --git a/litellm/proxy/pass_through_endpoints/passthrough_endpoint_router.py b/litellm/proxy/pass_through_endpoints/passthrough_endpoint_router.pyindex a02cacc3cc0..9335ce49bb7 100644--- a/litellm/proxy/pass_through_endpoints/passthrough_endpoint_router.py+++ b/litellm/proxy/pass_through_endpoints/passthrough_endpoint_router.py@@ -110,7 +110,7 @@ class PassthroughEndpointRouter:self,project_id: str,location: str,- vertex_credentials: VERTEX_CREDENTIALS_TYPES,+ vertex_credentials: Optional[VERTEX_CREDENTIALS_TYPES],):"""Add the vertex credentials for the given project-id, locationdiff --git a/litellm/router.py b/litellm/router.pyindex ae45212dccf..e8cba56b249 100644--- a/litellm/router.py+++ b/litellm/router.py@@ -4740,13 +4740,9 @@ class Router:or deployment.litellm_params.vertex_credentials)- if (- vertex_project is None- or vertex_location is None- or vertex_credentials is None- ):+ if vertex_project is None or vertex_location is None:raise ValueError(- "vertex_project, vertex_location, and vertex_credentials must be set in litellm_params for pass-through endpoints"+ "vertex_project, and vertex_location must be set in litellm_params for pass-through endpoints.")passthrough_endpoint_router.add_vertex_credentials(project_id=vertex_project,diff --git a/tests/llm_translation/test_watsonx.py b/tests/llm_translation/test_watsonx.pyindex d788541dada..e0c125a9017 100644--- a/tests/llm_translation/test_watsonx.py+++ b/tests/llm_translation/test_watsonx.py@@ -206,7 +206,7 @@ def test_watsonx_deployment_space_id(monkeypatch, watsonx_chat_completion_call,assert mock_post.call_count == 1json_data = json.loads(mock_post.call_args.kwargs["data"])- assert my_fake_space_id == json_data["space_id"]+ assert my_fake_space_id not in json_datadef test_watsonx_deployment_space_id_embedding(monkeypatch, watsonx_embedding_call):@@ -217,4 +217,4 @@ def test_watsonx_deployment_space_id_embedding(monkeypatch, watsonx_embedding_caassert mock_post.call_count == 1json_data = json.loads(mock_post.call_args.kwargs["data"])- assert my_fake_space_id == json_data["space_id"]+ assert my_fake_space_id not in json_datadiff --git a/tests/router_unit_tests/test_router_adding_deployments.py b/tests/router_unit_tests/test_router_adding_deployments.pyindex 55481394bb1..6e2a7b79733 100644--- a/tests/router_unit_tests/test_router_adding_deployments.py+++ b/tests/router_unit_tests/test_router_adding_deployments.py@@ -92,7 +92,7 @@ def test_initialize_deployment_for_pass_through_missing_params():# Test that initialization raises ValueErrorwith pytest.raises(ValueError,- match="vertex_project, vertex_location, and vertex_credentials must be set",+ match="vertex_project, and vertex_location must be set in litellm_params for pass-through endpoints",):router._initialize_deployment_for_pass_through(deployment=deployment,