adk-java icon indicating copy to clipboard operation
adk-java copied to clipboard

Setting api key programmatically

Open joreilly opened this issue 1 year ago • 3 comments

Sorry if I missed something obvious but is there way to set api key (e.g. for Gemini) programmatically?

joreilly avatar Jun 26 '25 19:06 joreilly

you might try this:

return LlmAgent.builder()
                        .model(new Gemini("gemini-2.0-flash",
                                Client.builder()
                                        .vertexAI(false)
                                        .apiKey(GOOGLE_API_KEY)
                                        .build()))
                        .name(NAME)
                        .instruction("You are a helpful agent who can answer user questions about the time and weather in a city.")
                        .build();

Th1nK4data avatar Jun 27 '25 05:06 Th1nK4data

That worked, thanks!

joreilly avatar Jun 27 '25 10:06 joreilly

Also there is a simpler way that is coming out in 0.2.0 https://github.com/google/adk-java/blob/c8fed2db9b142696aca9468742c17ea283a73f4a/core/src/main/java/com/google/adk/models/Gemini.java#L92

Poggecci avatar Jun 30 '25 17:06 Poggecci