feat(models): allow configuring Vertex AI API version (v1/v1beta1)#6183
feat(models): allow configuring Vertex AI API version (v1/v1beta1)#6183vaibhav-patel wants to merge 10 commits into
Conversation
The Gemini model integration relied on the google-genai SDK's default API version, which is v1beta1 for the Vertex AI backend. Production users that need a stable, SLA-eligible endpoint had no supported way to opt into the GA v1 Vertex AI API short of subclassing Gemini and overriding api_client. Add an optional api_version field on Gemini and honor the GOOGLE_GENAI_API_VERSION environment variable as a fallback. The resolved version flows through the existing _base_url_and_api_version chokepoint, so it applies consistently to the standard api_client, the live API client, and the per-request http_options patching. Resolution order: a version embedded in base_url wins, then the api_version field, then GOOGLE_GENAI_API_VERSION, then the SDK default. When none is configured the behavior is unchanged, so existing users are unaffected. Fixes google#3246.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
@googlebot I signed it! |
|
Hi @vaibhav-patel , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the failing ci tests before we can proceed with a review. |
Reword the api_version docstring so it no longer embeds a literal googleapis.com URL, which tripped the hardcoded-endpoint mTLS check without changing the documented behavior.
|
HI @rohityan |
|
Hi @vaibhav-patel , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share. |
|
Hi @GWeale , can you please review this. |
Summary
ADK relies on the google-genai SDK's default API version, which is
v1beta1for the Vertex AI backend. Production users want to opt into the stable, GAv1Vertex AI endpoint for SLA eligibility, but today the only workaround is subclassingGeminiand overridingapi_client.This adds a clean, backward-compatible way to configure the API version:
api_versionfield onGemini(e.g.Gemini(model=..., api_version="v1")).GOOGLE_GENAI_API_VERSIONenvironment variable, honored as a fallback.The resolved version flows through the existing
_base_url_and_api_versionchokepoint, so it applies consistently to the standard client, the live API client, and the per-requesthttp_options.Resolution order: a version embedded in
base_urlwins, then theapi_versionfield, thenGOOGLE_GENAI_API_VERSION, then the SDK default. When nothing is configured, behavior is unchanged — existing users are unaffected.Usage
or set
GOOGLE_GENAI_API_VERSION=v1in the environment.Testing
tests/unittests/models/test_google_llm.pycovering the field, the env var, precedence rules, the live API path, and the request-config patching, plus an assertion that the default is unchanged.test_google_llm.pysuite passes (74 tests);pyinkandisortclean.Fixes #3246.