google/generative-ai-go

Issue with custom proxy client and required API key

Closed this issue · 2 comments

Hi guys!
I've tried to setting up a proxy client following this previous issue suggestions by passing a custom http client with the proxy address and api key configured to the genai.NewClient, but I've got an error:

You need an API key to use this client.
Visit https://ai.google.dev to get one, put it in an environment variable like GEMINI_API_KEY,
then pass it as an option:
    genai.NewClient(ctx, option.WithAPIKey(os.Getenv("GEMINI_API_KEY")))
(If you're doing that already, then maybe the environment variable is empty or unset.)
Import the option package as "google.golang.org/api/option".

After looking through the source I've noticed a change made 2 months ago that makes the api key always required in the options struct. It ignores that the custom client is setting the api key in the RoundTrip method.

As commented in the previous issue here, there's a problem if you use both fields (option.WithAPIKey and option.WithHTTPClient) generating an error googleapi: Error 403:.

Is there any other way to configure a proxy client, or is this a bug?

@jba this is from #48

Thank you!