Skip to content

Commit 10fd612

Browse files
BenjaminKazemicopybara-github
authored andcommitted
chore: [vertexai] Introduce modules
PiperOrigin-RevId: 840409307
1 parent 4ce094b commit 10fd612

26 files changed

+465
-426
lines changed

src/main/java/com/google/genai/ApiClient.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.fasterxml.jackson.core.JsonProcessingException;
2323
import com.fasterxml.jackson.databind.ObjectMapper;
24+
import com.google.api.core.InternalApi;
2425
import com.google.auth.oauth2.GoogleCredentials;
2526
import com.google.common.base.Ascii;
2627
import com.google.common.collect.ImmutableMap;
@@ -45,7 +46,8 @@
4546
import org.jspecify.annotations.Nullable;
4647

4748
/** Interface for an API client which issues HTTP requests to the GenAI APIs. */
48-
abstract class ApiClient {
49+
@InternalApi
50+
public abstract class ApiClient {
4951

5052
// {x-version-update-start:google-genai:released}
5153
private static final String SDK_VERSION = "1.29.0";
@@ -437,10 +439,15 @@ public boolean vertexAI() {
437439
}
438440

439441
/** Returns the HttpClient for API calls. */
440-
OkHttpClient httpClient() {
442+
public OkHttpClient httpClient() {
441443
return httpClient;
442444
}
443445

446+
/** Returns the HTTP options for API calls. */
447+
public HttpOptions httpOptions() {
448+
return httpOptions;
449+
}
450+
444451
/**
445452
* Merges two maps recursively. If a key exists in both maps, the value from `source` overwrites
446453
* the value in `target`. If the value is a list, then update the whole list. A warning is logged
@@ -611,7 +618,7 @@ static String getApiKeyFromEnv() {
611618
* <li>vertexBaseUrl -> GOOGLE_VERTEX_BASE_URL: Base URL for Vertex AI APIs.
612619
* </ul>
613620
*/
614-
static ImmutableMap<String, String> defaultEnvironmentVariables() {
621+
public static ImmutableMap<String, String> defaultEnvironmentVariables() {
615622
ImmutableMap.Builder<String, String> mapBuilder = ImmutableMap.builder();
616623
String value;
617624
value = System.getenv("GOOGLE_API_KEY");
@@ -646,7 +653,8 @@ static ImmutableMap<String, String> defaultEnvironmentVariables() {
646653
}
647654

648655
/** Overrides the base URLs for the Gemini API and/or Vertex AI API. */
649-
static void setDefaultBaseUrls(Optional<String> geminiBaseUrl, Optional<String> vertexBaseUrl) {
656+
public static void setDefaultBaseUrls(
657+
Optional<String> geminiBaseUrl, Optional<String> vertexBaseUrl) {
650658
ApiClient.geminiBaseUrl = geminiBaseUrl;
651659
ApiClient.vertexBaseUrl = vertexBaseUrl;
652660
}

src/main/java/com/google/genai/ApiResponse.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
package com.google.genai;
1818

19+
import com.google.api.core.InternalApi;
1920
import okhttp3.Headers;
2021
import okhttp3.ResponseBody;
2122

2223
/** The API response contains a response to a call to the GenAI APIs. */
23-
abstract class ApiResponse implements AutoCloseable {
24+
@InternalApi
25+
public abstract class ApiResponse implements AutoCloseable {
2426
/** Gets the ResponseBody. */
2527
public abstract ResponseBody getBody();
2628

src/main/java/com/google/genai/AsyncBatches.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ CompletableFuture<BatchJob> privateCreate(
5151
String model, BatchJobSource src, CreateBatchJobConfig config) {
5252
BuiltRequest builtRequest = batches.buildRequestForPrivateCreate(model, src, config);
5353
return this.apiClient
54-
.asyncRequest("post", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
54+
.asyncRequest("post", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
5555
.thenApplyAsync(
5656
response -> {
5757
try (ApiResponse res = response) {
@@ -64,7 +64,7 @@ CompletableFuture<BatchJob> privateCreateEmbeddings(
6464
String model, EmbeddingsBatchJobSource src, CreateEmbeddingsBatchJobConfig config) {
6565
BuiltRequest builtRequest = batches.buildRequestForPrivateCreateEmbeddings(model, src, config);
6666
return this.apiClient
67-
.asyncRequest("post", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
67+
.asyncRequest("post", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
6868
.thenApplyAsync(
6969
response -> {
7070
try (ApiResponse res = response) {
@@ -85,7 +85,7 @@ CompletableFuture<BatchJob> privateCreateEmbeddings(
8585
public CompletableFuture<BatchJob> get(String name, GetBatchJobConfig config) {
8686
BuiltRequest builtRequest = batches.buildRequestForGet(name, config);
8787
return this.apiClient
88-
.asyncRequest("get", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
88+
.asyncRequest("get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
8989
.thenApplyAsync(
9090
response -> {
9191
try (ApiResponse res = response) {
@@ -105,7 +105,7 @@ public CompletableFuture<BatchJob> get(String name, GetBatchJobConfig config) {
105105
public CompletableFuture<Void> cancel(String name, CancelBatchJobConfig config) {
106106
BuiltRequest builtRequest = batches.buildRequestForCancel(name, config);
107107
return this.apiClient
108-
.asyncRequest("post", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
108+
.asyncRequest("post", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
109109
.thenAccept(
110110
response -> {
111111
try (ApiResponse res = response) {}
@@ -115,7 +115,7 @@ public CompletableFuture<Void> cancel(String name, CancelBatchJobConfig config)
115115
CompletableFuture<ListBatchJobsResponse> privateList(ListBatchJobsConfig config) {
116116
BuiltRequest builtRequest = batches.buildRequestForPrivateList(config);
117117
return this.apiClient
118-
.asyncRequest("get", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
118+
.asyncRequest("get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
119119
.thenApplyAsync(
120120
response -> {
121121
try (ApiResponse res = response) {
@@ -135,7 +135,8 @@ CompletableFuture<ListBatchJobsResponse> privateList(ListBatchJobsConfig config)
135135
public CompletableFuture<DeleteResourceJob> delete(String name, DeleteBatchJobConfig config) {
136136
BuiltRequest builtRequest = batches.buildRequestForDelete(name, config);
137137
return this.apiClient
138-
.asyncRequest("delete", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
138+
.asyncRequest(
139+
"delete", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
139140
.thenApplyAsync(
140141
response -> {
141142
try (ApiResponse res = response) {

src/main/java/com/google/genai/AsyncCaches.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public AsyncCaches(ApiClient apiClient) {
5454
public CompletableFuture<CachedContent> create(String model, CreateCachedContentConfig config) {
5555
BuiltRequest builtRequest = caches.buildRequestForCreate(model, config);
5656
return this.apiClient
57-
.asyncRequest("post", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
57+
.asyncRequest("post", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
5858
.thenApplyAsync(
5959
response -> {
6060
try (ApiResponse res = response) {
@@ -73,7 +73,7 @@ public CompletableFuture<CachedContent> create(String model, CreateCachedContent
7373
public CompletableFuture<CachedContent> get(String name, GetCachedContentConfig config) {
7474
BuiltRequest builtRequest = caches.buildRequestForGet(name, config);
7575
return this.apiClient
76-
.asyncRequest("get", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
76+
.asyncRequest("get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
7777
.thenApplyAsync(
7878
response -> {
7979
try (ApiResponse res = response) {
@@ -92,7 +92,8 @@ public CompletableFuture<DeleteCachedContentResponse> delete(
9292
String name, DeleteCachedContentConfig config) {
9393
BuiltRequest builtRequest = caches.buildRequestForDelete(name, config);
9494
return this.apiClient
95-
.asyncRequest("delete", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
95+
.asyncRequest(
96+
"delete", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
9697
.thenApplyAsync(
9798
response -> {
9899
try (ApiResponse res = response) {
@@ -111,7 +112,7 @@ public CompletableFuture<DeleteCachedContentResponse> delete(
111112
public CompletableFuture<CachedContent> update(String name, UpdateCachedContentConfig config) {
112113
BuiltRequest builtRequest = caches.buildRequestForUpdate(name, config);
113114
return this.apiClient
114-
.asyncRequest("patch", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
115+
.asyncRequest("patch", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
115116
.thenApplyAsync(
116117
response -> {
117118
try (ApiResponse res = response) {
@@ -123,7 +124,7 @@ public CompletableFuture<CachedContent> update(String name, UpdateCachedContentC
123124
CompletableFuture<ListCachedContentsResponse> privateList(ListCachedContentsConfig config) {
124125
BuiltRequest builtRequest = caches.buildRequestForPrivateList(config);
125126
return this.apiClient
126-
.asyncRequest("get", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
127+
.asyncRequest("get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
127128
.thenApplyAsync(
128129
response -> {
129130
try (ApiResponse res = response) {

src/main/java/com/google/genai/AsyncDocuments.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public AsyncDocuments(ApiClient apiClient) {
4444
public CompletableFuture<Document> get(String name, GetDocumentConfig config) {
4545
BuiltRequest builtRequest = documents.buildRequestForGet(name, config);
4646
return this.apiClient
47-
.asyncRequest("get", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
47+
.asyncRequest("get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
4848
.thenApplyAsync(
4949
response -> {
5050
try (ApiResponse res = response) {
@@ -56,7 +56,8 @@ public CompletableFuture<Document> get(String name, GetDocumentConfig config) {
5656
public CompletableFuture<Void> delete(String name, DeleteDocumentConfig config) {
5757
BuiltRequest builtRequest = documents.buildRequestForDelete(name, config);
5858
return this.apiClient
59-
.asyncRequest("delete", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
59+
.asyncRequest(
60+
"delete", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
6061
.thenAccept(
6162
response -> {
6263
try (ApiResponse res = response) {}
@@ -66,7 +67,7 @@ public CompletableFuture<Void> delete(String name, DeleteDocumentConfig config)
6667
CompletableFuture<ListDocumentsResponse> privateList(String parent, ListDocumentsConfig config) {
6768
BuiltRequest builtRequest = documents.buildRequestForPrivateList(parent, config);
6869
return this.apiClient
69-
.asyncRequest("get", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
70+
.asyncRequest("get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
7071
.thenApplyAsync(
7172
response -> {
7273
try (ApiResponse res = response) {

src/main/java/com/google/genai/AsyncFileSearchStores.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public AsyncFileSearchStores(ApiClient apiClient) {
6161
public CompletableFuture<FileSearchStore> create(CreateFileSearchStoreConfig config) {
6262
BuiltRequest builtRequest = fileSearchStores.buildRequestForCreate(config);
6363
return this.apiClient
64-
.asyncRequest("post", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
64+
.asyncRequest("post", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
6565
.thenApplyAsync(
6666
response -> {
6767
try (ApiResponse res = response) {
@@ -73,7 +73,7 @@ public CompletableFuture<FileSearchStore> create(CreateFileSearchStoreConfig con
7373
public CompletableFuture<FileSearchStore> get(String name, GetFileSearchStoreConfig config) {
7474
BuiltRequest builtRequest = fileSearchStores.buildRequestForGet(name, config);
7575
return this.apiClient
76-
.asyncRequest("get", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
76+
.asyncRequest("get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
7777
.thenApplyAsync(
7878
response -> {
7979
try (ApiResponse res = response) {
@@ -85,7 +85,8 @@ public CompletableFuture<FileSearchStore> get(String name, GetFileSearchStoreCon
8585
public CompletableFuture<Void> delete(String name, DeleteFileSearchStoreConfig config) {
8686
BuiltRequest builtRequest = fileSearchStores.buildRequestForDelete(name, config);
8787
return this.apiClient
88-
.asyncRequest("delete", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
88+
.asyncRequest(
89+
"delete", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
8990
.thenAccept(
9091
response -> {
9192
try (ApiResponse res = response) {}
@@ -95,7 +96,7 @@ public CompletableFuture<Void> delete(String name, DeleteFileSearchStoreConfig c
9596
CompletableFuture<ListFileSearchStoresResponse> privateList(ListFileSearchStoresConfig config) {
9697
BuiltRequest builtRequest = fileSearchStores.buildRequestForPrivateList(config);
9798
return this.apiClient
98-
.asyncRequest("get", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
99+
.asyncRequest("get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
99100
.thenApplyAsync(
100101
response -> {
101102
try (ApiResponse res = response) {
@@ -109,7 +110,7 @@ CompletableFuture<UploadToFileSearchStoreResumableResponse> privateUploadToFileS
109110
BuiltRequest builtRequest =
110111
fileSearchStores.buildRequestForPrivateUploadToFileSearchStore(fileSearchStoreName, config);
111112
return this.apiClient
112-
.asyncRequest("post", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
113+
.asyncRequest("post", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
113114
.thenApplyAsync(
114115
response -> {
115116
try (ApiResponse res = response) {
@@ -124,7 +125,7 @@ public CompletableFuture<ImportFileOperation> importFile(
124125
BuiltRequest builtRequest =
125126
fileSearchStores.buildRequestForImportFile(fileSearchStoreName, fileName, config);
126127
return this.apiClient
127-
.asyncRequest("post", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
128+
.asyncRequest("post", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
128129
.thenApplyAsync(
129130
response -> {
130131
try (ApiResponse res = response) {

src/main/java/com/google/genai/AsyncFiles.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public AsyncFiles(ApiClient apiClient) {
5252
CompletableFuture<ListFilesResponse> privateList(ListFilesConfig config) {
5353
BuiltRequest builtRequest = files.buildRequestForPrivateList(config);
5454
return this.apiClient
55-
.asyncRequest("get", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
55+
.asyncRequest("get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
5656
.thenApplyAsync(
5757
response -> {
5858
try (ApiResponse res = response) {
@@ -64,7 +64,7 @@ CompletableFuture<ListFilesResponse> privateList(ListFilesConfig config) {
6464
CompletableFuture<CreateFileResponse> privateCreate(File file, CreateFileConfig config) {
6565
BuiltRequest builtRequest = files.buildRequestForPrivateCreate(file, config);
6666
return this.apiClient
67-
.asyncRequest("post", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
67+
.asyncRequest("post", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
6868
.thenApplyAsync(
6969
response -> {
7070
try (ApiResponse res = response) {
@@ -83,7 +83,7 @@ CompletableFuture<CreateFileResponse> privateCreate(File file, CreateFileConfig
8383
public CompletableFuture<File> get(String name, GetFileConfig config) {
8484
BuiltRequest builtRequest = files.buildRequestForGet(name, config);
8585
return this.apiClient
86-
.asyncRequest("get", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
86+
.asyncRequest("get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
8787
.thenApplyAsync(
8888
response -> {
8989
try (ApiResponse res = response) {
@@ -102,7 +102,8 @@ public CompletableFuture<File> get(String name, GetFileConfig config) {
102102
public CompletableFuture<DeleteFileResponse> delete(String name, DeleteFileConfig config) {
103103
BuiltRequest builtRequest = files.buildRequestForDelete(name, config);
104104
return this.apiClient
105-
.asyncRequest("delete", builtRequest.path, builtRequest.body, builtRequest.httpOptions)
105+
.asyncRequest(
106+
"delete", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
106107
.thenApplyAsync(
107108
response -> {
108109
try (ApiResponse res = response) {

0 commit comments

Comments
 (0)