fix(core): honor GOOGLE_GEMINI_BASE_URL and GOOGLE_VERTEX_BASE_URL#25357
fix(core): honor GOOGLE_GEMINI_BASE_URL and GOOGLE_VERTEX_BASE_URL#25357scidomino merged 5 commits intogoogle-gemini:mainfrom
Conversation
|
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. |
|
cc @scidomino since this touches the |
7e19a7b to
9fcaaf4
Compare
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enables custom base URL configuration for the Gemini and Vertex AI clients by propagating environment variables into the SDK's httpOptions. It ensures that these overrides are securely validated, enforcing HTTPS for remote connections while maintaining flexibility for local development environments. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for overriding the base URL of the Gemini and Vertex AI services using environment variables (GOOGLE_GEMINI_BASE_URL and GOOGLE_VERTEX_BASE_URL). It includes a validation utility to enforce HTTPS for remote URLs and comprehensive unit tests. One review comment suggests improving the logic for selecting the environment variable by checking the authType instead of the vertexai flag, which ensures the correct URL is used even when credentials are provided by a proxy.
| const envBaseUrl = config.vertexai | ||
| ? process.env['GOOGLE_VERTEX_BASE_URL'] | ||
| : process.env['GOOGLE_GEMINI_BASE_URL']; |
There was a problem hiding this comment.
The logic for selecting the environment variable for the base URL should rely on the requested authType rather than the vertexai boolean. The vertexai property is only set to true if valid credentials (API key or Project/Location) are detected during configuration. However, a user providing a custom base URL via environment variables might be using a proxy that handles authentication or injects credentials, and thus might not have local credentials set. In such cases, config.vertexai would be undefined, causing the code to incorrectly fall back to GOOGLE_GEMINI_BASE_URL even when AuthType.USE_VERTEX_AI was explicitly requested or detected.
| const envBaseUrl = config.vertexai | |
| ? process.env['GOOGLE_VERTEX_BASE_URL'] | |
| : process.env['GOOGLE_GEMINI_BASE_URL']; | |
| const envBaseUrl = config.authType === AuthType.USE_VERTEX_AI | |
| ? process.env['GOOGLE_VERTEX_BASE_URL'] | |
| : process.env['GOOGLE_GEMINI_BASE_URL']; |
| if (!baseUrl) { | ||
| const envBaseUrl = | ||
| config.authType === AuthType.USE_VERTEX_AI | ||
| ? process.env['GOOGLE_VERTEX_BASE_URL'] |
There was a problem hiding this comment.
Update docs/reference/configuration.md to document these env vars
|
@scidomino Done! I've updated |
|
You have not updated the PR. Perhaps you forgot to push your changes? |
|
@scidomino Apologies for the confusion! I initially pushed to the wrong branch. The PR has been updated now with the documentation changes on fix/base-url-overrides. |
|
We have some flakey integration tests that are slowing down merges. Please don't update the PR while I work through this. |
cb289e0
Fixes #15430
Summary
This change wires custom base URL overrides through the core content generator so they are passed to
@google/genaiviahttpOptions.baseUrl.What Changed
baseUrltoContentGeneratorConfigGOOGLE_GEMINI_BASE_URLforAuthType.USE_GEMINIGOOGLE_VERTEX_BASE_URLforAuthType.USE_VERTEX_AIbaseUrlintoGoogleGenAIthroughhttpOptionsWhy
The Gemini CLI uses
@google/genai, which supports a custom base URL viahttpOptions.baseUrl. Before this change, the CLI propagated the environment variables but did not apply them when instantiating the SDK client.Validation
npm test -- src/core/contentGenerator.test.tsnpm run typecheckNotes
import/no-internal-modulesrather than this patch.