Skip to content

Commit b418311

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: Add "eu" as a supported service location for Vertex AI platform.
PiperOrigin-RevId: 896680569
1 parent eadce20 commit b418311

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public abstract class ApiClient implements AutoCloseable {
6868
private static final ImmutableSet<String> VALID_HTTP_METHODS =
6969
ImmutableSet.<String>builder().addAll(METHODS_WITH_BODY).add("GET").add("DELETE").build();
7070

71+
private static final ImmutableSet<String> MULTI_REGIONAL_LOCATIONS = ImmutableSet.of("us", "eu");
72+
7173
private static Optional<String> geminiBaseUrl = Optional.empty();
7274
private static Optional<String> vertexBaseUrl = Optional.empty();
7375

@@ -236,7 +238,9 @@ protected ApiClient(
236238
&& locationValue.equals("global")
237239
&& !customBaseUrl.isPresent())) {
238240
initHttpOptionsBuilder.baseUrl("https://aiplatform.googleapis.com");
239-
} else if (locationValue != null && locationValue.equals("us") && !customBaseUrl.isPresent()) {
241+
} else if (locationValue != null
242+
&& MULTI_REGIONAL_LOCATIONS.contains(locationValue)
243+
&& !customBaseUrl.isPresent()) {
240244
initHttpOptionsBuilder.baseUrl(
241245
String.format("https://aiplatform.%s.rep.googleapis.com", locationValue));
242246
} else if (locationValue != null && !customBaseUrl.isPresent()) {
@@ -713,7 +717,7 @@ static HttpOptions defaultHttpOptions(
713717
defaultHttpOptionsBuilder.baseUrl(customBaseUrl.get());
714718
} else if (apiKey.isPresent() || location.get().equalsIgnoreCase("global")) {
715719
defaultHttpOptionsBuilder.baseUrl("https://aiplatform.googleapis.com");
716-
} else if (location.get().equals("us")) {
720+
} else if (MULTI_REGIONAL_LOCATIONS.contains(location.get())) {
717721
defaultHttpOptionsBuilder.baseUrl(
718722
String.format("https://aiplatform.%s.rep.googleapis.com", location.get()));
719723
} else {

src/test/java/com/google/genai/HttpApiClientTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,22 @@ public void testInitHttpClientVertexWithProjectAndLocation() throws Exception {
679679
assertEquals("6", client.httpOptions.headers().get().get("X-Server-Timeout"));
680680
}
681681

682+
@Test
683+
public void testInitHttpClientVertexWithEuLocation() throws Exception {
684+
HttpApiClient client =
685+
new HttpApiClient(
686+
Optional.empty(),
687+
Optional.of(PROJECT),
688+
Optional.of("eu"),
689+
Optional.of(CREDENTIALS),
690+
Optional.empty(),
691+
Optional.empty());
692+
693+
assertEquals("eu", client.location());
694+
assertEquals(
695+
Optional.of("https://aiplatform.eu.rep.googleapis.com"), client.httpOptions.baseUrl());
696+
}
697+
682698
@Test
683699
public void testInitHttpClientVertexWithUsLocationAndCustomBaseUrl() throws Exception {
684700
HttpOptions httpOptions = HttpOptions.builder().baseUrl("https://custom-url.com").build();

0 commit comments

Comments
 (0)