Skip to content

Commit 61de41f

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: support us region routing
FUTURE_COPYBARA_INTEGRATE_REVIEW=https://github.com/google-gemini/private-dotnet-genai/pull/56 from google-gemini:integration 95fde92a3f597a59389fc8259d69398a685b7b91 PiperOrigin-RevId: 885956883
1 parent 8e5dc09 commit 61de41f

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Google.GenAI.Tests/HttpApiClientTest.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,29 @@ public void VertexConstructor_LocationGlobal_SetsCorrectBaseUrl() {
270270
Assert.AreEqual("https://aiplatform.googleapis.com", client.HttpOptions.BaseUrl);
271271
}
272272

273+
[TestMethod]
274+
public void VertexConstructor_LocationUs_SetsCorrectBaseUrl() {
275+
var mockCredential = new Mock<ICredential>();
276+
var client = new HttpApiClient(vertexAI: true, project: "my-project", location: "us", credentials: mockCredential.Object);
277+
278+
Assert.AreEqual("my-project", client.Project);
279+
Assert.AreEqual("us", client.Location);
280+
Assert.IsTrue(client.VertexAI);
281+
Assert.AreEqual("https://aiplatform.us.rep.googleapis.com", client.HttpOptions.BaseUrl);
282+
}
283+
284+
[TestMethod]
285+
public void VertexConstructor_LocationUsAndCustomHttpOptions_SetsCorrectBaseUrl() {
286+
var mockCredential = new Mock<ICredential>();
287+
var customOptions = new Types.HttpOptions { BaseUrl = "https://my-custom-url.com/" };
288+
var client = new HttpApiClient(vertexAI: true, project: "my-project", location: "us", credentials: mockCredential.Object, httpOptions: customOptions);
289+
290+
Assert.AreEqual("my-project", client.Project);
291+
Assert.AreEqual("us", client.Location);
292+
Assert.IsTrue(client.VertexAI);
293+
Assert.AreEqual("https://my-custom-url.com/", client.HttpOptions.BaseUrl);
294+
}
295+
273296
[TestMethod]
274297
public void Constructor_HttpOptions_BaseUrlResourceScopeWithoutBaseUrl_ThrowsArgumentException() {
275298
var customOptions = new Types.HttpOptions { BaseUrlResourceScope = Types.ResourceScope.Collection, BaseUrl = null };

Google.GenAI/ApiClient.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ internal static HttpOptions GetDefaultHttpOptions(bool vertexAI, string? locatio
316316
{
317317
defaultHttpOptions.BaseUrl = "https://aiplatform.googleapis.com";
318318
}
319+
else if (location!.Equals("us"))
320+
{
321+
defaultHttpOptions.BaseUrl = $"https://aiplatform.{location}.rep.googleapis.com";
322+
}
319323
else
320324
{
321325
defaultHttpOptions.BaseUrl = $"https://{location}-aiplatform.googleapis.com";

0 commit comments

Comments
 (0)