Is your feature request related to a problem? Please describe.
The current @google/genai SDK does not offer a direct method to configure an HTTP/HTTPS proxy for its API requests. This makes it challenging to use the SDK's clients in common corporate or restricted network environments that require a proxy.
Describe the solution you'd like
I propose adding a fetchImplementation (or alternatively, fetch) property to the configuration object passed to the SDK's client constructors. This would allow developers to supply their own fetch implementation, making it easy to integrate libraries like http-proxy-agent to correctly route traffic.
Describe alternatives you've considered
-
Direct Proxy Options: Adding explicit proxy fields (e.g., { proxy: { host: '...' } }) is an option, but it's less flexible than fetchImplementation for handling complex authentication, custom certificates, or different agent behaviors.
-
Relying on Environment Variables: Using a global environment variable like HTTPS_PROXY is a significant drawback because it affects the entire Node.js process. This forces all outbound HTTPS requests from the application through the proxy, not just requests from this SDK. An explicit fetchImplementation option provides safe, instance-level control without causing unintended side effects.
Additional context
Here is a conceptual code example illustrating how the proposed solution would work.
import { GoogleGenAI } from '@google/genai';
import { fetch } from "undici";
import { ProxyAgent } from "proxy-agent";
const agent = new ProxyAgent();
const customFetchWithProxy = (url, options) => {
return fetch(url, { ...options, dispatcher: agent });
};
// Pass the custom fetch function during client initialization
const ai = new GoogleGenAI({
vertexai: true,
project: 'your_project_id',
location: 'us-central1',
fetchImplementation: customFetchWithProxy,
});
Is your feature request related to a problem? Please describe.
The current
@google/genaiSDK does not offer a direct method to configure an HTTP/HTTPS proxy for its API requests. This makes it challenging to use the SDK's clients in common corporate or restricted network environments that require a proxy.Describe the solution you'd like
I propose adding a
fetchImplementation(or alternatively,fetch) property to the configuration object passed to the SDK's client constructors. This would allow developers to supply their ownfetchimplementation, making it easy to integrate libraries likehttp-proxy-agentto correctly route traffic.Describe alternatives you've considered
Direct Proxy Options: Adding explicit proxy fields (e.g.,
{ proxy: { host: '...' } }) is an option, but it's less flexible thanfetchImplementationfor handling complex authentication, custom certificates, or different agent behaviors.Relying on Environment Variables: Using a global environment variable like
HTTPS_PROXYis a significant drawback because it affects the entire Node.js process. This forces all outbound HTTPS requests from the application through the proxy, not just requests from this SDK. An explicitfetchImplementationoption provides safe, instance-level control without causing unintended side effects.Additional context
Here is a conceptual code example illustrating how the proposed solution would work.