Skip to content

Commit 2ab2065

Browse files
Poggeccicopybara-github
authored andcommitted
fix: Tracking headers not being added to default model use
PiperOrigin-RevId: 783028432
1 parent db21677 commit 2ab2065

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

core/src/main/java/com/google/adk/models/Gemini.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ public Builder vertexCredentials(VertexCredentials vertexCredentials) {
193193
*
194194
* @return A new {@link Gemini} instance.
195195
* @throws NullPointerException if modelName is null.
196-
* @throws IllegalStateException if none of apiKey, VertexCredentials, or an explicit apiClient
197-
* is set.
198196
*/
199197
public Gemini build() {
200198
Objects.requireNonNull(modelName, "modelName must be set.");
@@ -206,9 +204,11 @@ public Gemini build() {
206204
} else if (vertexCredentials != null) {
207205
return new Gemini(modelName, vertexCredentials);
208206
} else {
209-
throw new IllegalStateException(
210-
"Authentication strategy not set: Either apiKey, VertexCredentials, or an explicit"
211-
+ " apiClient must be provided.");
207+
return new Gemini(
208+
modelName,
209+
Client.builder()
210+
.httpOptions(HttpOptions.builder().headers(TRACKING_HEADERS).build())
211+
.build());
212212
}
213213
}
214214
}

core/src/main/java/com/google/adk/models/LlmRegistry.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.adk.models;
1818

19-
import com.google.genai.Client;
2019
import java.util.Map;
2120
import java.util.concurrent.ConcurrentHashMap;
2221

@@ -32,22 +31,12 @@ public interface LlmFactory {
3231
BaseLlm create(String modelName);
3332
}
3433

35-
/** API client for interacting with the Gemini model. */
36-
private static final Client geminiApiClient = Client.builder().build();
37-
3834
/** Map of model name patterns regex to factories. */
3935
private static final Map<String, LlmFactory> llmFactories = new ConcurrentHashMap<>();
4036

41-
/** Returns the singleton instance of the Gemini API client. */
42-
private static Client getGeminiApiClient() {
43-
return geminiApiClient;
44-
}
45-
4637
/** Registers default LLM factories, e.g. for Gemini models. */
4738
static {
48-
registerLlm(
49-
"gemini-.*",
50-
modelName -> Gemini.builder().modelName(modelName).apiClient(getGeminiApiClient()).build());
39+
registerLlm("gemini-.*", modelName -> Gemini.builder().modelName(modelName).build());
5140
}
5241

5342
/**

0 commit comments

Comments
 (0)