-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
What would you like to be added?
Add support for GOOGLE_GENAI_API_VERSION environment variable in gemini-cli that passes through to the SDK
// In contentGenerator.ts
const apiVersionEnv = process.env['GOOGLE_GENAI_API_VERSION'];
const googleGenAI = new GoogleGenAI({
apiKey: config.apiKey === '' ? undefined : config.apiKey,
vertexai: config.vertexai,
httpOptions,
...(apiVersionEnv !== undefined && { apiVersion: apiVersionEnv }),
});
Use Case
Enterprise customers with internal API gateways/proxies that:
- Provide a custom endpoint URL
- Require specific authentication headers
- Expect a specific API version in the URL path (e.g., v1 instead of v1beta1)
Example Configuration
With this feature, enterprise users could configure:
export GOOGLE_VERTEX_BASE_URL="https://internal-proxy.company.com/"
export GOOGLE_API_KEY="<token>"
export GEMINI_API_KEY_AUTH_MECHANISM="bearer"
export GEMINI_CLI_CUSTOM_HEADERS="X-Custom-Header: value"
export GOOGLE_GENAI_API_VERSION="v1" # ← New
This would generate requests to:
https://internal-proxy.company.com/v1/publishers/google/models/gemini-3-pro-preview:generateContent
Why is this needed?
Enterprise customers using custom proxy endpoints need the ability to override the API version in the URL path. While gemini-cli and @google/genai SDK support custom base URLs and headers, there's currently no way to customize the API version, which is hardcoded to v1beta (Gemini API) or v1beta1 (Vertex AI). When using enterprise proxy/gateway endpoints, the proxy may expect a different API version than the SDK defaults. For example:
- SDK default (Vertex AI mode): v1beta1/publishers/google/models/{model}:generateContent
- Enterprise proxy expects: v1/publishers/google/models/{model}:generateContent
This results in 404 errors when using custom base URLs with enterprise proxies.
Current State
| Feature | Supported | Mechanism |
|---|---|---|
| Custom base URL | ✅ | GOOGLE_GEMINI_BASE_URL / GOOGLE_VERTEX_BASE_URL (via @google/genai) |
| Custom headers | ✅ | GEMINI_CLI_CUSTOM_HEADERS env var |
| Bearer token auth | ✅ | GEMINI_API_KEY_AUTH_MECHANISM=bearer env var |
| Custom API version | ❌ | Not supported |
The Gap
The @google/genai SDK already supports the apiVersion parameter in its constructor:
const googleGenAI = new GoogleGenAI({
apiKey: '...',
vertexai: true,
httpOptions: { ... },
apiVersion: 'v1', // ← SDK supports this
});
However, gemini-cli does not expose a way to pass this value through to the SDK. In contentGenerator.ts, the GoogleGenAI constructor is called without the apiVersion parameter:
const googleGenAI = new GoogleGenAI({
apiKey: config.apiKey === '' ? undefined : config.apiKey,
vertexai: config.vertexai,
httpOptions,
// apiVersion is missing
});
Additional context
No response