fix: use global endpoint for multi-region locations in Vertex AI #1263
+158
−5
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.
Summary
Multi-region locations (
us,eu,asia,europe,me,northamerica,southamerica,africa) require the global endpointaiplatform.googleapis.com, not{location}-aiplatform.googleapis.com.Problem
When using Vertex AI with multi-region locations like
usoreu, the SDK constructs an invalid URL:This returns an HTML 404 error because
us-aiplatform.googleapis.comdoesn't exist.Current Workaround
Users can work around this by setting the environment variable:
However, this forces all requests to use the global endpoint, which may not be desired for users who want to use specific regional endpoints for data residency or latency reasons.
Solution
The correct URL for multi-region locations uses the global endpoint with the location in the path:
This PR updates
baseUrlFromProjectLocation()to recognize all multi-region locations and route them to the global endpoint, while preserving the existing behavior for regional endpoints likeus-central1,europe-west1, etc.Multi-Region Locations
Per Google Cloud documentation:
globaluseuasiaeuropemenorthamericasouthamericaafricaTest Plan
us-central1,me-central1, etc.) continue to workgemini-2.0-flashmodel