Support for Custom Vertex AI Models via PSC Endpoint with api_base #15953
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title
Support for Custom Vertex AI Models via PSC Endpoint with api_base
Relevant issues
Fixes LIT-1096
Pre-Submission checklist
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitType
🐛 Bug Fix
🆕 New Feature
Changes
This PR adds comprehensive support for Vertex AI Private Service Connect (PSC) endpoints, allowing users to use custom
api_baseURLs for both completion and embedding requests. This enables access to privately deployed Vertex AI models through internal network endpoints.Key Features Added
PSC Endpoint URL Construction: Enhanced
_check_custom_proxy()to properly construct full PSC URLs with the format:Numeric Model ID Support: Modified routing logic to ensure numeric endpoint IDs (common for custom deployments) properly use the HTTP-based handler that respects
api_base.Comprehensive Parameter Passing: Updated all Vertex AI handlers to pass necessary parameters (
vertex_project,vertex_location,vertex_api_version) for proper PSC URL construction.Bug Fix: Fixed a pre-existing JSON serialization bug in Vertex AI embeddings where non-serializable objects were being passed to TypedDict constructors.
Technical Changes
Core URL Construction (
litellm/llms/vertex_ai/vertex_llm_base.py)_check_custom_proxy()to detect PSC endpoints and construct full URL pathsRouting Logic (
litellm/llms/vertex_ai/common_utils.py)get_vertex_ai_model_route()to route numeric model IDs withapi_baseto the HTTP-based handlerapi_baseHandler Updates
Updated all Vertex AI handlers to pass required parameters:
vertex_gemma_models/main.pyvertex_model_garden/main.pycontext_caching/vertex_ai_context_caching.pybatches/handler.pyBug Fix (
litellm/llms/vertex_ai/vertex_embeddings/transformation.py)optional_paramsto only include valid TypedDict fieldsClientSessionand other non-serializable objects from being passed to JSON serializationUsage Example
Or specify in config.yaml: