fix: Append Vertex AI API paths to custom base URLs for proxy endpoints#1691
Closed
what-is-thy-bidding wants to merge 6 commits intogoogleapis:mainfrom
Closed
fix: Append Vertex AI API paths to custom base URLs for proxy endpoints#1691what-is-thy-bidding wants to merge 6 commits intogoogleapis:mainfrom
what-is-thy-bidding wants to merge 6 commits intogoogleapis:mainfrom
Conversation
Collaborator
|
Hi @what-is-thy-bidding |
Author
|
Closing this PR as a more cleaner and simpler solution is added in PR : #1701 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix Summary: Custom Base URL Model Path Appending
Problem
When using
vertexai=Truewith a custombase_url(e.g., for API gateway proxies like Autodesk APS), the SDK was not appending model-specific API paths to the base URL. This caused 404 errors because requests were being sent to:Instead of the correct path:
Root Cause
In
google/genai/_api_client.py, the_build_request()method had logic at lines 1071-1079 that prevented path appending for custom base URLs:When using a custom base URL without
project/location, the condition evaluated toFalse, and the model path was never appended.Solution
Following the pattern from commit
7bd1bde, the fix adds an additional condition to detect when theversioned_pathcontains model API paths that should be appended:The new condition checks if
versioned_pathcontains:publishers/- Vertex AI publisher paths/models- Model identifiers and list operations:- API method separators (e.g.,:generateContent)When any of these patterns are detected, the path is appended to the custom base URL.
Changes Made
1.
google/genai/_api_client.py(lines 1071-1084)2.
google/genai/tests/client/test_client_requests.pytest_build_request_with_custom_base_url_model_method_call()- Tests API method calls with colon (e.g.,:generateContent)test_build_request_with_custom_base_url_model_resource_path()- Tests model resource paths (e.g.,publishers/google/models/gemini-2.5-flash)test_build_request_with_custom_base_url_models_list()- Tests models list operations (e.g.,v1beta1/models)test_build_request_with_custom_base_url_no_env_vars()continues to pass, ensuring backward compatibilityTesting
All tests pass:
pytest google/genai/tests/client/test_client_requests.py -xvs # 14/14 passed (includes 3 new tests)Usage Example
For API gateway proxies like Autodesk APS:
Backward Compatibility
The fix maintains backward compatibility:
test/pathare NOT appended (existing behavior preserved)publishers/,/models, or:ARE appended (new behavior)Related Commits
This fix follows the pattern established in:
a00b67a- "fix: Do not use ADC if passing a base_url, no project, no location"7bd1bde- "fix: Support custom_base_url for Live and other APIs when project/location are unset"Visual Guide: Solution for Custom Base URL Path Appending
Client Setup with Custom Base URL
The Problem (Before Fix)
The Solution (After Fix)
Pattern Detection Flow
Test Coverage Matrix
API Call Types Covered
Type 1: Method Invocation (POST)
Type 2: Resource Fetching (GET)
Type 3: List Operations (GET)
Type 4: Simple Test Path (Should NOT Append)
Why Three Patterns?
Real-World Flow: Custom API Gateway Proxy
Summary
The solution uses three pattern detectors working together to ensure:
:detector)publishers/and/modelsdetectors)This provides 100% coverage of Vertex AI API operations for custom base URL proxies