Skip to content

feat(core): Add GOOGLE_GENAI_API_VERSION environment variable support - #16177

Merged
bdmorgan merged 10 commits into
google-gemini:mainfrom
deyim:dyim/add-api-version-env-var
Jan 29, 2026
Merged

bdmorgan merged 10 commits into
google-gemini:mainfrom
deyim:dyim/add-api-version-env-var

Conversation

@deyim

@deyim deyim commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds support for GOOGLE_GENAI_API_VERSION environment variable to allow enterprise users with internal API proxies to override the default API version (v1beta1) used by the SDK
  • This fixes 404 errors when proxies expect different API versions (e.g., v1 instead of v1beta1)

Details

  • packages/core/src/core/contentGenerator.ts: Read GOOGLE_GENAI_API_VERSION env var and pass it to the GoogleGenAI constructor when set
  • docs/cli/configuration.md: Added documentation for the new environment variable
  • packages/core/src/core/contentGenerator.test.ts: Added 3 test cases for the new functionality

Related Issues

How to Validate

  1. Unit tests: Run npm run test and verify the 3 new tests incontentGenerator.test.ts pass:
  • should pass apiVersion to GoogleGenAI when GOOGLE_GENAI_API_VERSION is set
  • should not include apiVersion when GOOGLE_GENAI_API_VERSION is not set
  • should pass apiVersion for Vertex AI when GOOGLE_GENAI_API_VERSION is set
  1. Manual testing with v1 API:
export GOOGLE_GENAI_API_VERSION="v1"
export GEMINI_API_KEY="your-api-key"
gemini

Verify requests use /v1/ in the API path instead of /v1beta1/

  1. Manual testing without env var (default behavior):
unset GOOGLE_GENAI_API_VERSION
gemini

Verify the SDK uses its default API version (v1beta1)

  1. Edge case - empty string:
export GOOGLE_GENAI_API_VERSION=""

Verify it behaves the same as unset (uses SDK default)

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@deyim
deyim requested a review from a team as a code owner January 8, 2026 18:45
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @deyim, 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 enhances the core functionality by enabling users to explicitly control the Google GenAI API version through a new environment variable, GOOGLE_GENAI_API_VERSION. This change is crucial for improving compatibility, particularly for enterprise environments that utilize internal API proxies requiring specific API versions, thereby preventing potential 404 errors and ensuring smoother integration.

Highlights

  • API Version Override: Introduced support for the GOOGLE_GENAI_API_VERSION environment variable, allowing users to explicitly specify the desired API version (e.g., v1) for Google GenAI requests, overriding the default v1beta1.
  • Enterprise Proxy Compatibility: This feature resolves 404 errors encountered by enterprise users whose internal API proxies expect different API versions, ensuring smoother integration and functionality within such environments.
  • Documentation and Testing: The new environment variable is fully documented in docs/cli/configuration.md and thoroughly tested with three new unit tests in contentGenerator.test.ts to ensure correct behavior across various scenarios, including Vertex AI usage.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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

@gemini-cli gemini-cli Bot added the area/enterprise Issues related to Telemetry, Policy, Quota / Licensing label Jan 8, 2026

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

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.

Code Review

This pull request introduces support for the GOOGLE_GENAI_API_VERSION environment variable, allowing users to override the default API version. The changes include updates to the documentation, new unit tests, and the core implementation. The implementation is mostly correct, but I've found an edge case where an empty string for the environment variable is not handled as intended, which could lead to failed API requests. I've provided a suggestion to fix this. The added tests are good, but it would be beneficial to also cover this edge case.

Comment thread packages/core/src/core/contentGenerator.ts Outdated
deyim and others added 2 commits January 8, 2026 10:50
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@deyim
deyim force-pushed the dyim/add-api-version-env-var branch from f94ee5f to 2a9ca55 Compare January 8, 2026 18:55
@sehoon38
sehoon38 requested a review from a team as a code owner January 21, 2026 04:12
@gemini-cli gemini-cli Bot added the priority/p1 Important and should be addressed in the near term. label Jan 22, 2026
@jacob314 jacob314 added the 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. label Jan 22, 2026
@bdmorgan

Copy link
Copy Markdown
Collaborator

This pull request is being closed because it is labeled as "🔒 maintainer only".

Issues or pull requests with this label are restricted to project maintainers due to the sensitive or complex nature of the task. We value your desire to contribute! Please consider helping us resolve other open issues, specifically those marked with the help wanted label.

@bdmorgan bdmorgan closed this Jan 23, 2026
@bdmorgan bdmorgan reopened this Jan 28, 2026
@bdmorgan bdmorgan added help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! and removed 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Jan 28, 2026
@bdmorgan

Copy link
Copy Markdown
Collaborator

I've reviewed and will approve. Can you resolve the merge conflicts in docs/cli/configuration.md?

@deyim

deyim commented Jan 29, 2026

Copy link
Copy Markdown
Contributor Author

I've reviewed and will approve. Can you resolve the merge conflicts in docs/cli/configuration.md?

Hey @bdmorgan, thanks for taking a look at it. I've updated the docs/get-started/configuration.md file.

@bdmorgan
bdmorgan enabled auto-merge January 29, 2026 21:35
@bdmorgan
bdmorgan force-pushed the dyim/add-api-version-env-var branch from 7e50328 to ffec5fe Compare January 29, 2026 22:32
@bdmorgan
bdmorgan added this pull request to the merge queue Jan 29, 2026
@bdmorgan

Copy link
Copy Markdown
Collaborator

@deyim thanks again for the pull request! there was one minor build error occurring that I hopefully fixed. If you test the main branch after this PR is in and see any issues, ping this PR and I can reopen. Thanks again!!

Merged via the queue into google-gemini:main with commit fdda3a2 Jan 29, 2026
25 checks passed
sidwan02 pushed a commit to sidwan02/gemini-cli-gemma that referenced this pull request Feb 6, 2026
…google-gemini#16177)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Bryan Morgan <[email protected]>
kuishou68 pushed a commit to iOfficeAI/gemini-cli-pro that referenced this pull request Feb 27, 2026
…google-gemini#16177)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Bryan Morgan <[email protected]>
@rwalle

rwalle commented Apr 7, 2026

Copy link
Copy Markdown

This change is not compatible with GOOGLE_GENAI_API_VERSION env var due to a missing change in sandbox.ts. I opened #24828 for the issue.

cocosheng-g pushed a commit that referenced this pull request May 6, 2026
…#16177)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Bryan Morgan <[email protected]>
@sripasg sripasg added the size/m A medium sized PR label Jun 2, 2026
software-0ficial pushed a commit to software-0ficial/gemini-cli that referenced this pull request Jul 9, 2026
…google-gemini#16177)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Bryan Morgan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/enterprise Issues related to Telemetry, Policy, Quota / Licensing help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p1 Important and should be addressed in the near term. size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support custom API version for enterprise proxy endpoints

5 participants