I need to use the google-generativeai Python library with routing its api requests through a proxy. However, the library doesn't natively support passing proxy configurations directly when initializing the client.
Feature Request
Add support for passing proxy configurations (e.g., as part of client_options) directly to the google-generativeai client, ensuring all network requests—including file uploads—are routed through the proxy.
What problem are you trying to solve with this feature?
This would avoid the need for global proxy settings or reverse proxies, offering a cleaner and more robust solution in network-restricted environments.
Any other information you'd like to share?
I have tried the following approaches, each with limitations:
Global Environment Variables (os.environ['HTTP_PROXY'], os.environ['HTTPS_PROXY)
This works but affects all network requests globally, which is problematic in my multi-threaded, multi-process environment of the project. Managing when to apply or remove these settings isn't practical.
Reverse Proxy with Custom API Endpoint
Since genai.configure() supports api_endpoint parameter, I created a custom route on my project that routes requests as a reverse proxy. This works for model.generate_content function but fails with the genai.upload_file function, as it hardcodes Google's endpoint, bypassing the custom API endpoint.
Description of the feature request:
I need to use the
google-generativeai
Python library with routing its api requests through a proxy. However, the library doesn't natively support passing proxy configurations directly when initializing the client.Feature Request
Add support for passing proxy configurations (e.g., as part of
client_options
) directly to thegoogle-generativeai
client, ensuring all network requests—including file uploads—are routed through the proxy.What problem are you trying to solve with this feature?
This would avoid the need for global proxy settings or reverse proxies, offering a cleaner and more robust solution in network-restricted environments.
Any other information you'd like to share?
I have tried the following approaches, each with limitations:
Global Environment Variables (
os.environ['HTTP_PROXY']
,os.environ['HTTPS_PROXY
)Reverse Proxy with Custom API Endpoint
genai.configure()
supportsapi_endpoint
parameter, I created a custom route on my project that routes requests as a reverse proxy. This works formodel.generate_content
function but fails with thegenai.upload_file
function, as it hardcodes Google's endpoint, bypassing the custom API endpoint.