Skip to content

fix(core): honor GOOGLE_GEMINI_BASE_URL and GOOGLE_VERTEX_BASE_URL#25357

Merged
scidomino merged 5 commits intogoogle-gemini:mainfrom
chrisjcthomas:fix/base-url-overrides
Apr 15, 2026
Merged

fix(core): honor GOOGLE_GEMINI_BASE_URL and GOOGLE_VERTEX_BASE_URL#25357
scidomino merged 5 commits intogoogle-gemini:mainfrom
chrisjcthomas:fix/base-url-overrides

Conversation

@chrisjcthomas
Copy link
Copy Markdown
Contributor

Fixes #15430

Summary

This change wires custom base URL overrides through the core content generator so they are passed to @google/genai via httpOptions.baseUrl.

What Changed

  • Added baseUrl to ContentGeneratorConfig
  • Resolved GOOGLE_GEMINI_BASE_URL for AuthType.USE_GEMINI
  • Resolved GOOGLE_VERTEX_BASE_URL for AuthType.USE_VERTEX_AI
  • Passed baseUrl into GoogleGenAI through httpOptions
  • Added validation so custom base URLs must be HTTPS unless they point to localhost
  • Added unit tests covering Gemini and Vertex overrides, localhost HTTP overrides, invalid URLs, and insecure non-local HTTP URLs

Why

The Gemini CLI uses @google/genai, which supports a custom base URL via httpOptions.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.ts
  • npm run typecheck

Notes

  • I attempted the repo pre-commit hook as part of commit flow, but it currently fails due to an existing ESLint/plugin crash in import/no-internal-modules rather than this patch.
  • The patch keeps localhost HTTP support for local proxies while requiring HTTPS for remote overrides.

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 14, 2026

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.

@chrisjcthomas
Copy link
Copy Markdown
Contributor Author

chrisjcthomas commented Apr 14, 2026

cc @scidomino since this touches the packages/core/src/core/contentGenerator* path and the Gemini/Vertex base URL override flow.

@gemini-cli gemini-cli Bot added priority/p3 Backlog - a good idea but not currently a priority. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Apr 14, 2026
@chrisjcthomas chrisjcthomas force-pushed the fix/base-url-overrides branch from 7e19a7b to 9fcaaf4 Compare April 14, 2026 03:55
@chrisjcthomas chrisjcthomas marked this pull request as ready for review April 14, 2026 04:00
@chrisjcthomas chrisjcthomas requested a review from a team as a code owner April 14, 2026 04:00
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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

  • Base URL Configuration: Implemented support for GOOGLE_GEMINI_BASE_URL and GOOGLE_VERTEX_BASE_URL environment variables to allow custom API endpoint overrides.
  • Security Validation: Added strict validation for custom base URLs, requiring HTTPS for remote endpoints while permitting HTTP for localhost.
  • Testing: Added comprehensive unit tests to verify environment variable resolution, explicit override precedence, and security validation logic.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +295 to +297
const envBaseUrl = config.vertexai
? process.env['GOOGLE_VERTEX_BASE_URL']
: process.env['GOOGLE_GEMINI_BASE_URL'];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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']
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update docs/reference/configuration.md to document these env vars

@chrisjcthomas
Copy link
Copy Markdown
Contributor Author

@scidomino Done! I've updated docs/reference/configuration.md to include documentation for GOOGLE_GEMINI_BASE_URL and GOOGLE_VERTEX_BASE_URL, including security requirements and usage examples.

@scidomino
Copy link
Copy Markdown
Collaborator

You have not updated the PR. Perhaps you forgot to push your changes?

@chrisjcthomas chrisjcthomas requested a review from a team as a code owner April 15, 2026 18:47
@chrisjcthomas
Copy link
Copy Markdown
Contributor Author

chrisjcthomas commented Apr 15, 2026

@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.

@scidomino scidomino enabled auto-merge April 15, 2026 19:26
@scidomino
Copy link
Copy Markdown
Collaborator

We have some flakey integration tests that are slowing down merges. Please don't update the PR while I work through this.

@scidomino scidomino added this pull request to the merge queue Apr 15, 2026
Merged via the queue into google-gemini:main with commit cb289e0 Apr 15, 2026
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p3 Backlog - a good idea but not currently a priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI ignores GOOGLE_GEMINI_BASE_URL and forces Cloud Auth/Endpoints

2 participants