diff --git a/examples/resources/sample_audio.mp3 b/examples/resources/sample_audio.mp3 new file mode 100644 index 00000000000..68a00666d3f Binary files /dev/null and b/examples/resources/sample_audio.mp3 differ diff --git a/examples/src/main/java/com/google/genai/examples/InteractionBasic.java b/examples/src/main/java/com/google/genai/examples/InteractionBasic.java new file mode 100644 index 00000000000..91f35a10609 --- /dev/null +++ b/examples/src/main/java/com/google/genai/examples/InteractionBasic.java @@ -0,0 +1,97 @@ +/* + * Copyright 2026 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Usage: + * + *
1a. If you are using Vertex AI, setup ADC to get credentials: + * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp + * + *
Then set Project, Location, and USE_VERTEXAI flag as environment variables: + * + *
export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT + * + *
export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION + * + *
export GOOGLE_GENAI_USE_VERTEXAI=true + * + *
1b. If you are using Gemini Developer API, set an API key environment variable. You can find a + * list of available API keys here: https://aistudio.google.com/app/apikey + * + *
export GOOGLE_API_KEY=YOUR_API_KEY + * + *
2. Compile the java package and run the sample code. + * + *
mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.InteractionBasic" + */ +package com.google.genai.examples; + +import com.google.genai.Client; +import com.google.genai.gaos.models.interactions.Content; +import com.google.genai.gaos.models.interactions.CreateModelInteraction; +import com.google.genai.gaos.models.interactions.Interaction; +import com.google.genai.gaos.models.interactions.InteractionsInput; +import com.google.genai.gaos.models.interactions.ModelOutputStep; +import com.google.genai.gaos.models.interactions.Step; +import com.google.genai.gaos.models.interactions.TextContent; +import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; + +/** An example of using the Unified Gen AI Java SDK to create a basic interaction. */ +public final class InteractionBasic { + public static void main(String[] args) { + Client client = new Client(); + + if (client.vertexAI()) { + System.out.println("Interactions API is not yet supported on Vertex"); + return; + } + + System.out.println("Using Gemini Developer API"); + + CreateModelInteraction params = + CreateModelInteraction.builder() + .input(InteractionsInput.of("Why is the sky blue?")) + .model(Constants.GEMINI_MODEL_NAME) + .build(); + + Interaction interaction = + client.interactions.create(CreateInteractionRequestBody.of(params)) + .interaction() + .orElseThrow(() -> new RuntimeException("Failed to create interaction")); + + System.out.println("Interaction ID: " + interaction.id().orElse("")); + System.out.println("Status: " + interaction.status()); + + // Print the text outputs from the interaction. + interaction.steps().ifPresent(steps -> { + for (Step step : steps) { + if (step.value() instanceof ModelOutputStep) { + ModelOutputStep modelOutput = (ModelOutputStep) step.value(); + modelOutput.content().ifPresent(contents -> { + for (Content content : contents) { + if (content.value() instanceof TextContent) { + TextContent text = (TextContent) content.value(); + System.out.println("Output: " + text.text()); + } + } + }); + } + } + }); + } + + private InteractionBasic() {} +} diff --git a/examples/src/main/java/com/google/genai/examples/InteractionCreate.java b/examples/src/main/java/com/google/genai/examples/InteractionCreate.java new file mode 100644 index 00000000000..fe420b7944e --- /dev/null +++ b/examples/src/main/java/com/google/genai/examples/InteractionCreate.java @@ -0,0 +1,104 @@ +/* + * Copyright 2026 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Usage: + * + *
1a. If you are using Vertex AI, setup ADC to get credentials: + * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp + * + *
Then set Project, Location, and USE_VERTEXAI flag as environment variables: + * + *
export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT + * + *
export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION + * + *
export GOOGLE_GENAI_USE_VERTEXAI=true + * + *
1b. If you are using Gemini Developer API, set an API key environment variable. You can find a + * list of available API keys here: https://aistudio.google.com/app/apikey + * + *
export GOOGLE_API_KEY=YOUR_API_KEY + * + *
2. Compile the java package and run the sample code. + * + *
mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.InteractionCreate" + */ +package com.google.genai.examples; + +import com.google.genai.Client; +import com.google.genai.gaos.models.interactions.Content; +import com.google.genai.gaos.models.interactions.CreateModelInteraction; +import com.google.genai.gaos.models.interactions.Interaction; +import com.google.genai.gaos.models.interactions.InteractionsInput; +import com.google.genai.gaos.models.interactions.ModelOutputStep; +import com.google.genai.gaos.models.interactions.Step; +import com.google.genai.gaos.models.interactions.TextContent; +import com.google.genai.gaos.models.operations.CreateInteractionRequestBody; + +/** An example of using the Unified Gen AI Java SDK to create an interaction. */ +public final class InteractionCreate { + public static void main(String[] args) { + // Instantiate the client. The client by default uses the Gemini Developer API. It gets the API + // key from the environment variable `GOOGLE_API_KEY`. Vertex AI API can be used by setting the + // environment variables `GOOGLE_CLOUD_LOCATION` and `GOOGLE_CLOUD_PROJECT`, as well as setting + // `GOOGLE_GENAI_USE_VERTEXAI` to "true". + // + // Note: Some services are only available in a specific API backend (Gemini or Vertex), you will + // get a `UnsupportedOperationException` if you try to use a service that is not available in + // the backend you are using. + Client client = new Client(); + + if (client.vertexAI()) { + System.out.println("Using Vertex AI"); + } else { + System.out.println("Using Gemini Developer API"); + } + + CreateModelInteraction params = + CreateModelInteraction.builder() + .input(InteractionsInput.of("What is your name?")) + .model(Constants.GEMINI_MODEL_NAME) + .build(); + + Interaction interaction = + client.interactions.create(CreateInteractionRequestBody.of(params)) + .interaction() + .orElseThrow(() -> new RuntimeException("Failed to create interaction")); + + System.out.println("Interaction ID: " + interaction.id().orElse("")); + System.out.println("Status: " + interaction.status()); + + // Print the text outputs from the interaction. + interaction.steps().ifPresent(steps -> { + for (Step step : steps) { + if (step.value() instanceof ModelOutputStep) { + ModelOutputStep modelOutput = (ModelOutputStep) step.value(); + modelOutput.content().ifPresent(contents -> { + for (Content content : contents) { + if (content.value() instanceof TextContent) { + TextContent text = (TextContent) content.value(); + System.out.println("Output: " + text.text()); + } + } + }); + } + } + }); + } + + private InteractionCreate() {} +} diff --git a/examples/src/main/java/com/google/genai/examples/InteractionCreateAsync.java b/examples/src/main/java/com/google/genai/examples/InteractionCreateAsync.java new file mode 100644 index 00000000000..fd296d9eab8 --- /dev/null +++ b/examples/src/main/java/com/google/genai/examples/InteractionCreateAsync.java @@ -0,0 +1,115 @@ +/* + * Copyright 2026 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Usage: + * + *
1a. If you are using Vertex AI, setup ADC to get credentials: + * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp + * + *
Then set Project, Location, and USE_VERTEXAI flag as environment variables: + * + *
export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT + * + *
export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION + * + *
export GOOGLE_GENAI_USE_VERTEXAI=true + * + *
1b. If you are using Gemini Developer API, set an API key environment variable. You can find a + * list of available API keys here: https://aistudio.google.com/app/apikey + * + *
export GOOGLE_API_KEY=YOUR_API_KEY + * + *
2. Compile the java package and run the sample code. + * + *
mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionCreateAsync"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.Content;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ModelOutputStep;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.interactions.TextContent;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import java.util.concurrent.CompletableFuture;
+
+/** An example of using the Unified Gen AI Java SDK to create an interaction asynchronously. */
+public final class InteractionCreateAsync {
+ public static void main(String[] args) {
+ // Instantiate the client. The client by default uses the Gemini Developer API. It gets the API
+ // key from the environment variable `GOOGLE_API_KEY`. Vertex AI API can be used by setting the
+ // environment variables `GOOGLE_CLOUD_LOCATION` and `GOOGLE_CLOUD_PROJECT`, as well as setting
+ // `GOOGLE_GENAI_USE_VERTEXAI` to "true".
+ //
+ // Note: Some services are only available in a specific API backend (Gemini or Vertex), you will
+ // get a `UnsupportedOperationException` if you try to use a service that is not available in
+ // the backend you are using.
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Using Vertex AI");
+ } else {
+ System.out.println("Using Gemini Developer API");
+ }
+
+ CreateModelInteraction params =
+ CreateModelInteraction.builder()
+ .input(InteractionsInput.of("What is your name?"))
+ .model(Constants.GEMINI_MODEL_NAME)
+ .build();
+
+ CompletableFuture 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionCreateAsyncStreaming"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.InteractionSSEEvent;
+import com.google.genai.gaos.models.interactions.InteractionSSEStreamEvent;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.StepDelta;
+import com.google.genai.gaos.models.interactions.StepDeltaData;
+import com.google.genai.gaos.models.interactions.TextDelta;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import java.util.concurrent.CompletableFuture;
+import org.reactivestreams.Subscriber;
+import org.reactivestreams.Subscription;
+
+/**
+ * An example of using the Unified Gen AI Java SDK to create a streaming interaction asynchronously.
+ */
+public final class InteractionCreateAsyncStreaming {
+ public static void main(String[] args) {
+ // Instantiate the client. The client by default uses the Gemini Developer API. It gets the API
+ // key from the environment variable `GOOGLE_API_KEY`. Vertex AI API can be used by setting the
+ // environment variables `GOOGLE_CLOUD_LOCATION` and `GOOGLE_CLOUD_PROJECT`, as well as setting
+ // `GOOGLE_GENAI_USE_VERTEXAI` to "true".
+ //
+ // Note: Some services are only available in a specific API backend (Gemini or Vertex), you will
+ // get a `UnsupportedOperationException` if you try to use a service that is not available in
+ // the backend you are using.
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Using Vertex AI");
+ } else {
+ System.out.println("Using Gemini Developer API");
+ }
+
+ CreateModelInteraction params =
+ CreateModelInteraction.builder()
+ .input(InteractionsInput.of("Tell me a story in 300 words."))
+ .model(Constants.GEMINI_MODEL_NAME)
+ .stream(true)
+ .build();
+
+ System.out.println("Streaming response:");
+ CompletableFuture 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionCreateStreaming"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.InteractionSSEEvent;
+import com.google.genai.gaos.models.interactions.InteractionSSEStreamEvent;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.StepDelta;
+import com.google.genai.gaos.models.interactions.StepDeltaData;
+import com.google.genai.gaos.models.interactions.TextDelta;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import com.google.genai.gaos.models.operations.CreateInteractionResponse;
+import com.google.genai.gaos.utils.EventStream;
+
+/**
+ * An example of using the Unified Gen AI Java SDK to create a streaming interaction synchronously.
+ */
+public final class InteractionCreateStreaming {
+ public static void main(String[] args) throws Exception {
+ // Instantiate the client. The client by default uses the Gemini Developer API. It gets the API
+ // key from the environment variable `GOOGLE_API_KEY`. Vertex AI API can be used by setting the
+ // environment variables `GOOGLE_CLOUD_LOCATION` and `GOOGLE_CLOUD_PROJECT`, as well as setting
+ // `GOOGLE_GENAI_USE_VERTEXAI` to "true".
+ //
+ // Note: Some services are only available in a specific API backend (Gemini or Vertex), you will
+ // get a `UnsupportedOperationException` if you try to use a service that is not available in
+ // the backend you are using.
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Using Vertex AI");
+ } else {
+ System.out.println("Using Gemini Developer API");
+ }
+
+ CreateModelInteraction params =
+ CreateModelInteraction.builder()
+ .input(InteractionsInput.of("Tell me a story in 300 words."))
+ .model(Constants.GEMINI_MODEL_NAME)
+ .stream(true)
+ .build();
+
+ CreateInteractionResponse response =
+ client.interactions.create(CreateInteractionRequestBody.of(params));
+
+ try (EventStream Deep Research is currently only available on Vertex AI.
+ *
+ * 1. Setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * 2. Set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=global
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 3. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionDeepResearch"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.CreateAgentInteraction;
+import com.google.genai.gaos.models.interactions.ErrorEvent;
+import com.google.genai.gaos.models.interactions.InteractionCompletedEvent;
+import com.google.genai.gaos.models.interactions.InteractionCreatedEvent;
+import com.google.genai.gaos.models.interactions.InteractionSSEEvent;
+import com.google.genai.gaos.models.interactions.InteractionSSEStreamEvent;
+import com.google.genai.gaos.models.interactions.InteractionStatusUpdate;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.StepDelta;
+import com.google.genai.gaos.models.interactions.StepDeltaData;
+import com.google.genai.gaos.models.interactions.StepStart;
+import com.google.genai.gaos.models.interactions.StepStop;
+import com.google.genai.gaos.models.interactions.TextDelta;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import com.google.genai.gaos.models.operations.CreateInteractionResponse;
+import com.google.genai.gaos.models.operations.GetInteractionByIdResponse;
+import com.google.genai.gaos.utils.EventStream;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * An example of using the Unified Gen AI Java SDK to run a Deep Research interaction on Vertex AI.
+ */
+public final class InteractionDeepResearch {
+ public static void main(String[] args) throws Exception {
+ // Instantiate the client. Deep Research requires Vertex AI.
+ // Ensure GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_LOCATION=global, and
+ // GOOGLE_GENAI_USE_VERTEXAI=true are set in your environment.
+ Client client = new Client();
+
+ if (!client.vertexAI()) {
+ System.err.println("Deep Research is only supported on Vertex AI. "
+ + "Please set GOOGLE_GENAI_USE_VERTEXAI=true.");
+ return;
+ }
+
+ System.out.println(
+ "Using Vertex AI Project: " + (client.project() != null ? client.project() : "unknown"));
+
+ CreateAgentInteraction params =
+ CreateAgentInteraction.builder()
+ .agent("deep-research-pro-preview-12-2025")
+ .input(InteractionsInput.of("I want to learn more about the history of Hadrian's Wall"))
+ .background(true)
+ .stream(true)
+ .build();
+
+ AtomicReference 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionFunctionCallingClientState"
+ */
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.Content;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.Function;
+import com.google.genai.gaos.models.interactions.FunctionCallStep;
+import com.google.genai.gaos.models.interactions.FunctionResultStep;
+import com.google.genai.gaos.models.interactions.FunctionResultStepResultUnion;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ModelOutputStep;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.interactions.TextContent;
+import com.google.genai.gaos.models.interactions.Tool;
+import com.google.genai.gaos.models.interactions.UserInputStep;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/** An example of using the Unified Gen AI Java SDK to perform client-side function calling. */
+public final class InteractionFunctionCallingClientState {
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex");
+ return;
+ }
+
+ System.out.println("Using Gemini Developer API");
+
+ // 1. Define the function (tool)
+ Map 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionFunctionCallingServerState"
+ */
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.Content;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.Function;
+import com.google.genai.gaos.models.interactions.FunctionCallStep;
+import com.google.genai.gaos.models.interactions.FunctionResultStep;
+import com.google.genai.gaos.models.interactions.FunctionResultStepResultUnion;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ModelOutputStep;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.interactions.TextContent;
+import com.google.genai.gaos.models.interactions.Tool;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * An example of using the Interactions API for multi-turn function calling where the state is
+ * managed by the server.
+ */
+public final class InteractionFunctionCallingServerState {
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex");
+ return;
+ }
+
+ System.out.println("Using Gemini Developer API");
+
+ // 1. Define the function (tool)
+ Map 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.InteractionGet"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.Content;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ModelOutputStep;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.interactions.TextContent;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+
+/** An example of using the Unified Gen AI Java SDK to retrieve an interaction. */
+public final class InteractionGet {
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex");
+ return;
+ }
+
+ System.out.println("Using Gemini Developer API");
+
+ // First, create an interaction to get an ID.
+ CreateModelInteraction createParams =
+ CreateModelInteraction.builder()
+ .input(InteractionsInput.of("Why is the sky blue?"))
+ .model(Constants.GEMINI_MODEL_NAME)
+ .build();
+
+ Interaction createdInteraction =
+ client.interactions.create(CreateInteractionRequestBody.of(createParams))
+ .interaction()
+ .orElseThrow(() -> new RuntimeException("Failed to create interaction"));
+ String id = createdInteraction.id().orElseThrow(() -> new RuntimeException("No ID returned"));
+ System.out.println("Created Interaction ID: " + id);
+
+ // Now, retrieve the interaction using the ID.
+ Interaction retrievedInteraction =
+ client.interactions.get(new com.google.genai.gaos.models.operations.GetInteractionByIdRequest(id))
+ .interaction()
+ .orElseThrow(() -> new RuntimeException("Failed to retrieve interaction"));
+ System.out.println("Retrieved Interaction ID: " + retrievedInteraction.id().orElse(""));
+ System.out.println("Status: " + retrievedInteraction.status());
+
+ // Print the text outputs from the retrieved interaction.
+ retrievedInteraction.steps().ifPresent(steps -> {
+ for (Step step : steps) {
+ if (step.value() instanceof ModelOutputStep) {
+ ModelOutputStep modelOutput = (ModelOutputStep) step.value();
+ modelOutput.content().ifPresent(contents -> {
+ for (Content content : contents) {
+ if (content.value() instanceof TextContent) {
+ TextContent text = (TextContent) content.value();
+ System.out.println("Output: " + text.text());
+ }
+ }
+ });
+ }
+ }
+ });
+ }
+
+ private InteractionGet() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalInputTextAndAudio.java b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalInputTextAndAudio.java
new file mode 100644
index 00000000000..f06705d351a
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalInputTextAndAudio.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2026 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Usage:
+ *
+ * 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionMultimodalInputTextAndAudio"
+ */
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableList;
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.AudioContent;
+import com.google.genai.gaos.models.interactions.AudioContentMimeType;
+import com.google.genai.gaos.models.interactions.Content;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.TextContent;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Base64;
+import java.util.List;
+
+/** Example of using the Interactions API with multimodal input (text and audio). */
+public final class InteractionMultimodalInputTextAndAudio {
+
+ private InteractionMultimodalInputTextAndAudio() {}
+
+ private static void createInteractions(Client client) {
+ String base64Audio;
+ try {
+ base64Audio = Base64.getEncoder().encodeToString(
+ Files.readAllBytes(Paths.get("./resources/sample_audio.mp3"))
+ );
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to read audio file", e);
+ }
+
+ Content textContent =
+ Content.of(TextContent.builder().text("Summarize this audio clip.").build());
+ Content audioContent =
+ Content.of(
+ AudioContent.builder()
+ .data(base64Audio)
+ .mimeType(AudioContentMimeType.AUDIO_MP3)
+ .build());
+
+ List 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionMultimodalInputTextAndImage"
+ */
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableList;
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.Content;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.ImageContent;
+import com.google.genai.gaos.models.interactions.ImageContentMimeType;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.TextContent;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Base64;
+import java.util.List;
+
+/** Example of using the Interactions API with multimodal input (text and image). */
+public final class InteractionMultimodalInputTextAndImage {
+
+ private static void createInteractions(Client client) {
+ String base64Image;
+ try {
+ base64Image = Base64.getEncoder().encodeToString(
+ Files.readAllBytes(Paths.get("./resources/shapes.jpg"))
+ );
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to read image file", e);
+ }
+
+ Content textContent =
+ Content.of(TextContent.builder().text("What is shown in this image?").build());
+ Content imageContent =
+ Content.of(
+ ImageContent.builder()
+ .data(base64Image)
+ .mimeType(ImageContentMimeType.IMAGE_JPEG)
+ .build());
+
+ List 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionMultimodalResponseAudio"
+ */
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableList;
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.GenerationConfig;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ResponseModality;
+import com.google.genai.gaos.models.interactions.SpeechConfig;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import java.util.Arrays;
+
+/** Example of generating audio using the Interactions API. */
+public final class InteractionMultimodalResponseAudio {
+
+ private static void createInteractions(Client client) {
+
+ SpeechConfig speechConfig = SpeechConfig.builder().voice("achernar").language("en-US").build();
+
+ GenerationConfig generationConfig =
+ GenerationConfig.builder().speechConfig(ImmutableList.of(speechConfig)).build();
+
+ CreateModelInteraction params =
+ CreateModelInteraction.builder()
+ .model("gemini-2.5-flash-preview-tts")
+ .responseModalities(ImmutableList.of(ResponseModality.AUDIO))
+ .generationConfig(generationConfig)
+ .input(InteractionsInput.of("Say cheerfully: Have a wonderful day!"))
+ .build();
+
+ Interaction interaction =
+ client.interactions.create(CreateInteractionRequestBody.of(params))
+ .interaction()
+ .orElseThrow(() -> new RuntimeException("Failed to create interaction"));
+
+ interaction.steps().ifPresent(steps -> {
+ int i = 1;
+ for (Step step : steps) {
+ System.out.println("Output " + i + ": " + step);
+ i++;
+ }
+ });
+ }
+
+ public static void main(String[] args) throws Exception {
+ Client client = new Client();
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex");
+ return;
+ }
+ createInteractions(client);
+ }
+
+ private InteractionMultimodalResponseAudio() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseAudioWithGenerateContent.java b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseAudioWithGenerateContent.java
new file mode 100644
index 00000000000..1c1498202fb
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseAudioWithGenerateContent.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2026 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Usage:
+ *
+ * 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionMultimodalResponseAudioWithGenerateContent"
+ */
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableList;
+import com.google.genai.Client;
+import com.google.genai.JsonSerializable;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.GenerationConfig;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ResponseModality;
+import com.google.genai.gaos.models.interactions.SpeechConfig;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import com.google.genai.types.GenerateContentConfig;
+import com.google.genai.types.GenerateContentResponse;
+
+/**
+ * An example of using the Unified Gen AI Java SDK to create an interaction with audio response and
+ * generate content with audio response.
+ */
+public final class InteractionMultimodalResponseAudioWithGenerateContent {
+ public static void main(String[] args) throws Exception {
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex");
+ return;
+ }
+
+ System.out.println("[Interactions] Start interactions multimodal response audio");
+
+ SpeechConfig speechConfig = SpeechConfig.builder().voice("achernar").language("en-US").build();
+
+ GenerationConfig generationConfig =
+ GenerationConfig.builder().speechConfig(ImmutableList.of(speechConfig)).build();
+
+ CreateModelInteraction params =
+ CreateModelInteraction.builder()
+ .model("gemini-2.5-flash-preview-tts")
+ .responseModalities(ImmutableList.of(ResponseModality.AUDIO))
+ .generationConfig(generationConfig)
+ .input(InteractionsInput.of("Say cheerfully: Have a wonderful day!"))
+ .build();
+
+ Interaction interaction =
+ client.interactions.create(CreateInteractionRequestBody.of(params))
+ .interaction()
+ .orElseThrow(() -> new RuntimeException("Failed to create interaction"));
+
+ System.out.println("Interaction ID: " + interaction.id().orElse(""));
+ System.out.println("Status: " + interaction.status());
+
+ interaction.steps().ifPresent(steps -> {
+ int stepIndex = 1;
+ for (Step step : steps) {
+ System.out.println("Step " + stepIndex + ": " + step);
+ stepIndex++;
+ }
+ });
+
+ System.out.println("[Generate Content] Start generate content");
+ GenerateContentConfig config =
+ GenerateContentConfig.builder().responseModalities(ImmutableList.of("AUDIO")).build();
+
+ GenerateContentResponse generateContentResponse =
+ client.models.generateContent(
+ "gemini-2.5-flash-preview-tts", "Say cheerfully: Have a wonderful day!", config);
+
+ System.out.println(
+ "Generate Content response: " + JsonSerializable.toJsonString(generateContentResponse));
+ }
+
+ private InteractionMultimodalResponseAudioWithGenerateContent() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseImage.java b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseImage.java
new file mode 100644
index 00000000000..bf55458539d
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseImage.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2026 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Usage:
+ *
+ * 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionMultimodalResponseImage"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ResponseModality;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import java.util.Arrays;
+
+/** Example of generating an image using the Interactions API. */
+public class InteractionMultimodalResponseImage {
+
+ private static void createInteractions(Client client) {
+
+ CreateModelInteraction params =
+ CreateModelInteraction.builder()
+ .model("gemini-2.5-flash-image")
+ .responseModalities(Arrays.asList(ResponseModality.IMAGE))
+ .input(InteractionsInput.of("Generate an image of a futuristic cityscape at sunset."))
+ .build();
+
+ Interaction interaction =
+ client.interactions.create(CreateInteractionRequestBody.of(params))
+ .interaction()
+ .orElseThrow(() -> new RuntimeException("Failed to create interaction"));
+
+ interaction.steps().ifPresent(steps -> {
+ int i = 1;
+ for (Step step : steps) {
+ System.out.println("Output " + i + ": " + step);
+ i++;
+ }
+ });
+ }
+
+ public static void main(String[] args) throws Exception {
+ Client client = new Client();
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex");
+ return;
+ }
+ createInteractions(client);
+ }
+
+ private InteractionMultimodalResponseImage() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseImageWithGenerateContent.java b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseImageWithGenerateContent.java
new file mode 100644
index 00000000000..72d202759e6
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionMultimodalResponseImageWithGenerateContent.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2026 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Usage:
+ *
+ * 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionMultimodalResponseImageWithGenerateContent"
+ */
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableList;
+import com.google.genai.Client;
+import com.google.genai.JsonSerializable;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ResponseModality;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import com.google.genai.types.GenerateContentConfig;
+import com.google.genai.types.GenerateContentResponse;
+
+/**
+ * An example of using the Unified Gen AI Java SDK to create an interaction with image response and
+ * generate content with image response.
+ */
+public final class InteractionMultimodalResponseImageWithGenerateContent {
+ public static void main(String[] args) throws Exception {
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex");
+ return;
+ }
+
+ System.out.println("[Interactions] Start interactions multimodal response image");
+
+ CreateModelInteraction params =
+ CreateModelInteraction.builder()
+ .model("gemini-2.5-flash-image")
+ .responseModalities(ImmutableList.of(ResponseModality.IMAGE))
+ .input(InteractionsInput.of("Generate an image of a futuristic cityscape at sunset."))
+ .build();
+
+ Interaction interaction =
+ client.interactions.create(CreateInteractionRequestBody.of(params))
+ .interaction()
+ .orElseThrow(() -> new RuntimeException("Failed to create interaction"));
+
+ System.out.println("Interaction ID: " + interaction.id().orElse(""));
+ System.out.println("Status: " + interaction.status());
+
+ interaction.steps().ifPresent(steps -> {
+ int stepIndex = 1;
+ for (Step step : steps) {
+ System.out.println("Step " + stepIndex + ": " + step);
+ stepIndex++;
+ }
+ });
+
+ System.out.println("[Generate Content] Start generate content");
+ GenerateContentConfig config =
+ GenerateContentConfig.builder().responseModalities(ImmutableList.of("TEXT", "IMAGE")).build();
+
+ GenerateContentResponse generateContentResponse =
+ client.models.generateContent(
+ "gemini-2.5-flash-image",
+ "Generate an image of a futuristic cityscape at sunset.",
+ config);
+
+ System.out.println(
+ "Generate Content response: " + JsonSerializable.toJsonString(generateContentResponse));
+ }
+
+ private InteractionMultimodalResponseImageWithGenerateContent() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionStateful.java b/examples/src/main/java/com/google/genai/examples/InteractionStateful.java
new file mode 100644
index 00000000000..a1ee3b3751c
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionStateful.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2026 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Usage:
+ *
+ * 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.InteractionStateful"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.Content;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ModelOutputStep;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.interactions.TextContent;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+
+/** An example of using the Unified Gen AI Java SDK to create a stateful interaction. */
+public final class InteractionStateful {
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex AI");
+ return;
+ }
+
+ System.out.println("Using Gemini Developer API");
+
+ System.out.println("User: What are the three largest cities in Spain?");
+ CreateModelInteraction params1 =
+ CreateModelInteraction.builder()
+ .input(InteractionsInput.of("What are the three largest cities in Spain?"))
+ .model(Constants.GEMINI_MODEL_NAME)
+ .build();
+
+ Interaction interaction1 =
+ client.interactions.create(CreateInteractionRequestBody.of(params1))
+ .interaction()
+ .orElseThrow(() -> new RuntimeException("Failed to create interaction"));
+ System.out.println("Model: ");
+ printOutput(interaction1);
+
+ System.out.println("\nUser: What is the most famous landmark in the second one?");
+ CreateModelInteraction params2 =
+ CreateModelInteraction.builder()
+ .input(InteractionsInput.of("What is the most famous landmark in the second one?"))
+ .model(Constants.GEMINI_MODEL_NAME)
+ .previousInteractionId(interaction1.id().orElseThrow(() -> new RuntimeException("No ID returned")))
+ .build();
+
+ Interaction interaction2 =
+ client.interactions.create(CreateInteractionRequestBody.of(params2))
+ .interaction()
+ .orElseThrow(() -> new RuntimeException("Failed to create interaction"));
+ System.out.println("Model: ");
+ printOutput(interaction2);
+ }
+
+ private static void printOutput(Interaction interaction) {
+ interaction.steps().ifPresent(steps -> {
+ for (Step step : steps) {
+ if (step.value() instanceof ModelOutputStep) {
+ ModelOutputStep modelOutput = (ModelOutputStep) step.value();
+ modelOutput.content().ifPresent(contents -> {
+ for (Content content : contents) {
+ if (content.value() instanceof TextContent) {
+ TextContent text = (TextContent) content.value();
+ System.out.println(text.text());
+ }
+ }
+ });
+ }
+ }
+ });
+ }
+
+ private InteractionStateful() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionStateless.java b/examples/src/main/java/com/google/genai/examples/InteractionStateless.java
new file mode 100644
index 00000000000..deadfdec7fd
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionStateless.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2026 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Usage:
+ *
+ * 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.InteractionStateless"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.Content;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ModelOutputStep;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.interactions.TextContent;
+import com.google.genai.gaos.models.interactions.UserInputStep;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An example of using the Unified Gen AI Java SDK to create a stateless interaction (multi-turn
+ * chat).
+ */
+public final class InteractionStateless {
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex");
+ return;
+ } else {
+ System.out.println("Using Gemini Developer API");
+ }
+
+ List 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.InteractionStreaming"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.InteractionSSEEvent;
+import com.google.genai.gaos.models.interactions.InteractionSSEStreamEvent;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.StepDelta;
+import com.google.genai.gaos.models.interactions.StepDeltaData;
+import com.google.genai.gaos.models.interactions.TextDelta;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import com.google.genai.gaos.models.operations.CreateInteractionResponse;
+import com.google.genai.gaos.utils.EventStream;
+
+/** An example of using the Unified Gen AI Java SDK to stream an interaction. */
+public final class InteractionStreaming {
+ public static void main(String[] args) throws Exception {
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex AI");
+ return;
+ }
+
+ System.out.println("Using Gemini Developer API");
+
+ CreateModelInteraction params =
+ CreateModelInteraction.builder()
+ .input(InteractionsInput.of("Tell me a story"))
+ .model(Constants.GEMINI_MODEL_NAME)
+ .stream(true)
+ .build();
+
+ CreateInteractionResponse response =
+ client.interactions.create(CreateInteractionRequestBody.of(params));
+
+ try (EventStream 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionStructuredOutputJson"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.CreateModelInteractionResponseFormat;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ResponseFormat;
+import com.google.genai.gaos.models.interactions.TextResponseFormat;
+import com.google.genai.gaos.models.interactions.TextResponseFormatMimeType;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Example of requesting structured JSON output using the Interactions API. */
+public class InteractionStructuredOutputJson {
+
+ private static void createInteractions(Client client) {
+
+ Map 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionToolCallWithCodeExecution"
+ */
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableList;
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.CodeExecution;
+import com.google.genai.gaos.models.interactions.Content;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ModelOutputStep;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.interactions.TextContent;
+import com.google.genai.gaos.models.interactions.Tool;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+
+/** An example of using the Interactions API with code execution tool. */
+public final class InteractionToolCallWithCodeExecution {
+ public static void main(String[] args) throws Exception {
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex");
+ return;
+ }
+
+ System.out.println("Using Gemini Developer API");
+
+ CodeExecution codeExecution = CodeExecution.builder().build();
+
+ CreateModelInteraction params =
+ CreateModelInteraction.builder()
+ .input(InteractionsInput.of("What is the sum of the first 100 integers?"))
+ .model(Constants.GEMINI_MODEL_NAME)
+ .tools(ImmutableList.of(Tool.of(codeExecution)))
+ .build();
+
+ Interaction interaction =
+ client.interactions.create(CreateInteractionRequestBody.of(params))
+ .interaction()
+ .orElseThrow(() -> new RuntimeException("Failed to create interaction"));
+
+ System.out.println("Interaction ID: " + interaction.id().orElse(""));
+ System.out.println("Status: " + interaction.status());
+
+ // Print the text outputs from the interaction.
+ interaction.steps().ifPresent(steps -> {
+ for (Step step : steps) {
+ if (step.value() instanceof ModelOutputStep) {
+ ModelOutputStep modelOutput = (ModelOutputStep) step.value();
+ modelOutput.content().ifPresent(contents -> {
+ for (Content content : contents) {
+ if (content.value() instanceof TextContent) {
+ TextContent text = (TextContent) content.value();
+ System.out.println("Output: " + text.text());
+ }
+ }
+ });
+ }
+ }
+ });
+ }
+
+ private InteractionToolCallWithCodeExecution() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithComputerUse.java b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithComputerUse.java
new file mode 100644
index 00000000000..3fa0a443686
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithComputerUse.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2026 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Usage:
+ *
+ * 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionToolCallWithComputerUse"
+ */
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableList;
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.ComputerUse;
+import com.google.genai.gaos.models.interactions.Content;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.EnvironmentEnum;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ModelOutputStep;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.interactions.TextContent;
+import com.google.genai.gaos.models.interactions.Tool;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+
+/**
+ * An example of using the Unified Gen AI Java SDK to create an interaction with computer use tool.
+ */
+public final class InteractionToolCallWithComputerUse {
+ public static void main(String[] args) throws Exception {
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex");
+ return;
+ } else {
+ System.out.println("Using Gemini Developer API");
+ }
+
+ ComputerUse computerUse =
+ ComputerUse.builder()
+ .environment(EnvironmentEnum.BROWSER)
+ .build();
+
+ CreateModelInteraction params =
+ CreateModelInteraction.builder()
+ .model("gemini-2.5-computer-use-preview-10-2025")
+ .input(
+ InteractionsInput.of(
+ "Search for highly rated smart fridges with touchscreen, 2 doors, around 25 cu ft,"
+ + " priced below 4000 dollars on Google Shopping. Create a bulleted list of the"
+ + " 3 cheapest options in the format of name, description, price in an"
+ + " easy-to-read layout."))
+ .tools(ImmutableList.of(Tool.of(computerUse)))
+ .build();
+
+ Interaction interaction =
+ client.interactions.create(CreateInteractionRequestBody.of(params))
+ .interaction()
+ .orElseThrow(() -> new RuntimeException("Failed to create interaction"));
+
+ System.out.println("Interaction ID: " + interaction.id().orElse(""));
+ System.out.println("Status: " + interaction.status());
+
+ // Print the text outputs from the interaction.
+ interaction.steps().ifPresent(steps -> {
+ for (Step step : steps) {
+ if (step.value() instanceof ModelOutputStep) {
+ ModelOutputStep modelOutput = (ModelOutputStep) step.value();
+ modelOutput.content().ifPresent(contents -> {
+ for (Content content : contents) {
+ if (content.value() instanceof TextContent) {
+ TextContent text = (TextContent) content.value();
+ System.out.println("Output: " + text.text());
+ }
+ }
+ });
+ }
+ }
+ });
+ }
+
+ private InteractionToolCallWithComputerUse() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithFunctions.java b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithFunctions.java
new file mode 100644
index 00000000000..b9d8e42d83c
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithFunctions.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2026 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Usage:
+ *
+ * 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionToolCallWithFunctions"
+ */
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.Content;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.Function;
+import com.google.genai.gaos.models.interactions.FunctionCallStep;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ModelOutputStep;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.interactions.TextContent;
+import com.google.genai.gaos.models.interactions.Tool;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+
+/** An example of using the Unified Gen AI Java SDK to perform tool calling with functions. */
+public final class InteractionToolCallWithFunctions {
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex AI");
+ return;
+ }
+
+ System.out.println("Using Gemini Developer API");
+
+ ImmutableMap 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionToolCallWithGoogleSearch"
+ */
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableList;
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.Content;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.GoogleSearch;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ModelOutputStep;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.interactions.TextContent;
+import com.google.genai.gaos.models.interactions.Tool;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+
+/** An example of using the Unified Gen AI Java SDK to perform tool calling with Google Search. */
+public final class InteractionToolCallWithGoogleSearch {
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex AI");
+ return;
+ }
+
+ System.out.println("Using Gemini Developer API");
+
+ GoogleSearch googleSearch = GoogleSearch.builder().build();
+
+ CreateModelInteraction params =
+ CreateModelInteraction.builder()
+ .input(InteractionsInput.of("Why is the sky blue"))
+ .model(Constants.GEMINI_MODEL_NAME)
+ .tools(ImmutableList.of(Tool.of(googleSearch)))
+ .build();
+
+ Interaction interaction =
+ client.interactions.create(CreateInteractionRequestBody.of(params))
+ .interaction()
+ .orElseThrow(() -> new RuntimeException("Failed to create interaction"));
+
+ System.out.println("Interaction ID: " + interaction.id().orElse(""));
+ System.out.println("Status: " + interaction.status());
+
+ interaction.steps().ifPresent(steps -> {
+ for (Step step : steps) {
+ if (step.value() instanceof ModelOutputStep) {
+ ModelOutputStep modelOutput = (ModelOutputStep) step.value();
+ modelOutput.content().ifPresent(contents -> {
+ for (Content content : contents) {
+ if (content.value() instanceof TextContent) {
+ TextContent text = (TextContent) content.value();
+ System.out.println("Output Text: " + text.text());
+ }
+ }
+ });
+ }
+ }
+ });
+ }
+
+ private InteractionToolCallWithGoogleSearch() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithMcpServer.java b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithMcpServer.java
new file mode 100644
index 00000000000..4f447dfd6d6
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithMcpServer.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2026 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Usage:
+ *
+ * 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionToolCallWithMcpServer"
+ */
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableList;
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.Content;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.MCPServer;
+import com.google.genai.gaos.models.interactions.ModelOutputStep;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.interactions.TextContent;
+import com.google.genai.gaos.models.interactions.Tool;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+
+/** An example of using the Interactions API with an MCP server tool. */
+public final class InteractionToolCallWithMcpServer {
+ public static void main(String[] args) throws Exception {
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex");
+ return;
+ }
+
+ System.out.println("Using Gemini Developer API");
+
+ MCPServer mcpServer =
+ MCPServer.builder()
+ .name("weather_service")
+ .url("https://gemini-api-demos.uc.r.appspot.com/mcp")
+ .build();
+
+ CreateModelInteraction params =
+ CreateModelInteraction.builder()
+ .input(InteractionsInput.of("What is the temperature today in London?"))
+ .systemInstruction(
+ "Today is 9-23-2025. Any dates before this are in the past, and any dates after"
+ + " this are in the future.")
+ .model(Constants.GEMINI_MODEL_NAME)
+ .tools(ImmutableList.of(Tool.of(mcpServer)))
+ .build();
+
+ Interaction interaction =
+ client.interactions.create(CreateInteractionRequestBody.of(params))
+ .interaction()
+ .orElseThrow(() -> new RuntimeException("Failed to create interaction"));
+
+ System.out.println("Interaction ID: " + interaction.id().orElse(""));
+ System.out.println("Status: " + interaction.status());
+
+ // Print the text outputs from the interaction.
+ interaction.steps().ifPresent(steps -> {
+ for (Step step : steps) {
+ if (step.value() instanceof ModelOutputStep) {
+ ModelOutputStep modelOutput = (ModelOutputStep) step.value();
+ modelOutput.content().ifPresent(contents -> {
+ for (Content content : contents) {
+ if (content.value() instanceof TextContent) {
+ TextContent text = (TextContent) content.value();
+ System.out.println("Output: " + text.text());
+ }
+ }
+ });
+ }
+ }
+ });
+ }
+
+ private InteractionToolCallWithMcpServer() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithUrlContext.java b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithUrlContext.java
new file mode 100644
index 00000000000..387f27b74a7
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionToolCallWithUrlContext.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2026 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Usage:
+ *
+ * 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionToolCallWithUrlContext"
+ */
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableList;
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.Content;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ModelOutputStep;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.interactions.TextContent;
+import com.google.genai.gaos.models.interactions.Tool;
+import com.google.genai.gaos.models.interactions.URLContext;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+
+/** An example of using the Interactions API with URL context tool. */
+public final class InteractionToolCallWithUrlContext {
+ public static void main(String[] args) throws Exception {
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex");
+ return;
+ }
+
+ System.out.println("Using Gemini Developer API");
+
+ URLContext urlContext = URLContext.builder().build();
+
+ CreateModelInteraction params =
+ CreateModelInteraction.builder()
+ .input(
+ InteractionsInput.of(
+ "Compare the ingredients and cooking times from the recipes at"
+ + " https://www.foodnetwork.com/recipes/ina-garten/perfect-roast-chicken-recipe-1940592"
+ + " and https://www.allrecipes.com/recipe/21151/simple-whole-roast-chicken/"))
+ .model(Constants.GEMINI_MODEL_NAME)
+ .tools(ImmutableList.of(Tool.of(urlContext)))
+ .build();
+
+ Interaction interaction =
+ client.interactions.create(CreateInteractionRequestBody.of(params))
+ .interaction()
+ .orElseThrow(() -> new RuntimeException("Failed to create interaction"));
+
+ System.out.println("Interaction ID: " + interaction.id().orElse(""));
+ System.out.println("Status: " + interaction.status());
+
+ // Print the text outputs from the interaction.
+ interaction.steps().ifPresent(steps -> {
+ for (Step step : steps) {
+ if (step.value() instanceof ModelOutputStep) {
+ ModelOutputStep modelOutput = (ModelOutputStep) step.value();
+ modelOutput.content().ifPresent(contents -> {
+ for (Content content : contents) {
+ if (content.value() instanceof TextContent) {
+ TextContent text = (TextContent) content.value();
+ System.out.println("Output: " + text.text());
+ }
+ }
+ });
+ }
+ }
+ });
+ }
+
+ private InteractionToolCallWithUrlContext() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionWithConfig.java b/examples/src/main/java/com/google/genai/examples/InteractionWithConfig.java
new file mode 100644
index 00000000000..db4cb7fe434
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionWithConfig.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2026 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Usage:
+ *
+ * 1a. If you are using Vertex AI, setup ADC to get credentials:
+ * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp
+ *
+ * Then set Project, Location, and USE_VERTEXAI flag as environment variables:
+ *
+ * export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT
+ *
+ * export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION
+ *
+ * export GOOGLE_GENAI_USE_VERTEXAI=true
+ *
+ * 1b. If you are using Gemini Developer API, set an API key environment variable. You can find a
+ * list of available API keys here: https://aistudio.google.com/app/apikey
+ *
+ * export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ * 2. Compile the java package and run the sample code.
+ *
+ * mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.InteractionWithConfig"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.gaos.models.interactions.Content;
+import com.google.genai.gaos.models.interactions.CreateModelInteraction;
+import com.google.genai.gaos.models.interactions.Interaction;
+import com.google.genai.gaos.models.interactions.InteractionsInput;
+import com.google.genai.gaos.models.interactions.ModelOutputStep;
+import com.google.genai.gaos.models.interactions.Step;
+import com.google.genai.gaos.models.interactions.TextContent;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+
+/** An example of using the Unified Gen AI Java SDK to create an interaction with config. */
+public final class InteractionWithConfig {
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ if (client.vertexAI()) {
+ System.out.println("Interactions API is not yet supported on Vertex AI");
+ return;
+ }
+
+ System.out.println("Using Gemini Developer API");
+
+ CreateModelInteraction params =
+ CreateModelInteraction.builder()
+ .input(InteractionsInput.of("Tell me a story"))
+ .model(Constants.GEMINI_MODEL_NAME)
+ .systemInstruction("You are a helpful assistant")
+ .build();
+
+ Interaction interaction =
+ client.interactions.create(CreateInteractionRequestBody.of(params))
+ .interaction()
+ .orElseThrow(() -> new RuntimeException("Failed to create interaction"));
+
+ System.out.println("Interaction ID: " + interaction.id().orElse(""));
+ System.out.println("Status: " + interaction.status());
+
+ interaction.steps().ifPresent(steps -> {
+ for (Step step : steps) {
+ if (step.value() instanceof ModelOutputStep) {
+ ModelOutputStep modelOutput = (ModelOutputStep) step.value();
+ modelOutput.content().ifPresent(contents -> {
+ for (Content content : contents) {
+ if (content.value() instanceof TextContent) {
+ TextContent text = (TextContent) content.value();
+ System.out.println("Output: " + text.text());
+ }
+ }
+ });
+ }
+ }
+ });
+ }
+
+ private InteractionWithConfig() {}
+}
diff --git a/pom.xml b/pom.xml
index 90f687c09f1..4804b6ccc10 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,6 +54,7 @@
You can use the Gemini API for use cases like reasoning across text and images, content generation,
+ * dialogue agents, summarization and classification systems, and more.
+ */
+@SuppressWarnings("all")
+public class AsyncGenAI {
+ private static final Headers _headers = Headers.EMPTY;
+
+ private final AsyncInteractions interactions;
+
+ private final AsyncWebhooks webhooks;
+
+ private final AsyncAgents agents;
+
+ public AsyncInteractions interactions() {
+ return interactions;
+ }
+
+ public AsyncWebhooks webhooks() {
+ return webhooks;
+ }
+
+ public AsyncAgents agents() {
+ return agents;
+ }
+
+ private final SDKConfiguration sdkConfiguration;
+ private final GenAI syncSDK;
+
+ AsyncGenAI(GenAI syncSDK, SDKConfiguration sdkConfiguration) {
+ this.syncSDK = syncSDK;
+ this.sdkConfiguration = sdkConfiguration;
+ this.interactions = new AsyncInteractions(syncSDK.interactions(), sdkConfiguration);
+ this.webhooks = new AsyncWebhooks(syncSDK.webhooks(), sdkConfiguration);
+ this.agents = new AsyncAgents(syncSDK.agents(), sdkConfiguration);
+ }
+
+ /**
+ * Switches to the sync SDK.
+ *
+ * @return The sync SDK
+ */
+ public GenAI sync() {
+ return syncSDK;
+ }
+}
diff --git a/src/main/java/com/google/genai/gaos/AsyncInteractions.java b/src/main/java/com/google/genai/gaos/AsyncInteractions.java
new file mode 100644
index 00000000000..7209bded0e3
--- /dev/null
+++ b/src/main/java/com/google/genai/gaos/AsyncInteractions.java
@@ -0,0 +1,277 @@
+/*
+* Copyright 2026 Google LLC
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+/*
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
+ */
+package com.google.genai.gaos;
+
+import static com.google.genai.gaos.operations.Operations.AsyncRequestOperation;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.google.genai.gaos.models.interactions.InteractionSSEStreamEvent;
+import com.google.genai.gaos.models.operations.CancelInteractionByIdRequest;
+import com.google.genai.gaos.models.operations.CreateInteractionRequest;
+import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
+import com.google.genai.gaos.models.operations.DeleteInteractionRequest;
+import com.google.genai.gaos.models.operations.GetInteractionByIdRequest;
+import com.google.genai.gaos.models.operations.async.CancelInteractionByIdRequestBuilder;
+import com.google.genai.gaos.models.operations.async.CancelInteractionByIdResponse;
+import com.google.genai.gaos.models.operations.async.CreateInteractionRequestBuilder;
+import com.google.genai.gaos.models.operations.async.CreateInteractionResponse;
+import com.google.genai.gaos.models.operations.async.DeleteInteractionRequestBuilder;
+import com.google.genai.gaos.models.operations.async.DeleteInteractionResponse;
+import com.google.genai.gaos.models.operations.async.GetInteractionByIdRequestBuilder;
+import com.google.genai.gaos.models.operations.async.GetInteractionByIdResponse;
+import com.google.genai.gaos.operations.CancelInteractionById;
+import com.google.genai.gaos.operations.CreateInteraction;
+import com.google.genai.gaos.operations.DeleteInteraction;
+import com.google.genai.gaos.operations.GetInteractionById;
+import com.google.genai.gaos.utils.Headers;
+import com.google.genai.gaos.utils.Options;
+import com.google.genai.gaos.utils.Utils;
+import com.google.genai.gaos.utils.reactive.EventStream;
+import java.lang.String;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+
+
+@SuppressWarnings("all")
+public class AsyncInteractions {
+ private static final Headers _headers = Headers.EMPTY;
+ private final SDKConfiguration sdkConfiguration;
+ private final Interactions syncSDK;
+
+ AsyncInteractions(Interactions syncSDK, SDKConfiguration sdkConfiguration) {
+ this.sdkConfiguration = sdkConfiguration;
+ this.syncSDK = syncSDK;
+ }
+
+ /**
+ * Switches to the sync SDK.
+ *
+ * @return The sync SDK
+ */
+ public Interactions sync() {
+ return syncSDK;
+ }
+
+
+ /**
+ * Creating an interaction
+ *
+ * Creates a new interaction.
+ *
+ * @return The async call builder
+ */
+ public CreateInteractionRequestBuilder create() {
+ return new CreateInteractionRequestBuilder(sdkConfiguration);
+ }
+
+ /**
+ * Creating an interaction
+ *
+ * Creates a new interaction.
+ *
+ * @param body The request body.
+ * @return {@code EventStream Creates a new interaction.
+ *
+ * @param apiVersion Which version of the API to use.
+ * @param body The request body.
+ * @param options additional options
+ * @return A reactive SSE publisher that emits events from the server.
+ * Can be consumed using reactive streams toolkits such as RxJava, Project Reactor, or Java 9+ Flow API.
+ */
+ public EventStream Retrieves the full details of a single interaction based on its `Interaction.id`.
+ *
+ * @return The async call builder
+ */
+ public GetInteractionByIdRequestBuilder get() {
+ return new GetInteractionByIdRequestBuilder(sdkConfiguration);
+ }
+
+ /**
+ * Retrieving an interaction
+ *
+ * Retrieves the full details of a single interaction based on its `Interaction.id`.
+ *
+ * @param request The request object containing all the parameters for the API call.
+ * @return {@code EventStream Retrieves the full details of a single interaction based on its `Interaction.id`.
+ *
+ * @param request The request object containing all the parameters for the API call.
+ * @param options additional options
+ * @return A reactive SSE publisher that emits events from the server.
+ * Can be consumed using reactive streams toolkits such as RxJava, Project Reactor, or Java 9+ Flow API.
+ */
+ public EventStream Deletes the interaction by id.
+ *
+ * @return The async call builder
+ */
+ public DeleteInteractionRequestBuilder delete() {
+ return new DeleteInteractionRequestBuilder(sdkConfiguration);
+ }
+
+ /**
+ * Deleting an interaction
+ *
+ * Deletes the interaction by id.
+ *
+ * @param id The unique identifier of the interaction to delete.
+ * @return {@code CompletableFuture Deletes the interaction by id.
+ *
+ * @param id The unique identifier of the interaction to delete.
+ * @param apiVersion Which version of the API to use.
+ * @param options additional options
+ * @return {@code CompletableFuture Cancels an interaction by id. This only applies to background interactions that are still running.
+ *
+ * @return The async call builder
+ */
+ public CancelInteractionByIdRequestBuilder cancel() {
+ return new CancelInteractionByIdRequestBuilder(sdkConfiguration);
+ }
+
+ /**
+ * Canceling an interaction
+ *
+ * Cancels an interaction by id. This only applies to background interactions that are still running.
+ *
+ * @param id The unique identifier of the interaction to cancel.
+ * @return {@code CompletableFuture Cancels an interaction by id. This only applies to background interactions that are still running.
+ *
+ * @param id The unique identifier of the interaction to cancel.
+ * @param apiVersion Which version of the API to use.
+ * @param options additional options
+ * @return {@code CompletableFuture It can generalize and seamlessly understand, operate across, and combine different types of
+ * information including language, images, audio, video, and code. You can use the Gemini API for use
+ * cases like reasoning across text and images, content generation, dialogue agents, summarization and
+ * classification systems, and more.
+ */
+@SuppressWarnings("all")
+public class GenAI {
+ private static final Headers _headers = Headers.EMPTY;
+
+
+ /**
+ * SERVERS contains the list of server urls available to the SDK.
+ */
+ public static final String[] SERVERS = {
+ /*
+ * Global Endpoint
+ */
+ "https://generativelanguage.googleapis.com",
+ };
+
+
+ private final Interactions interactions;
+
+
+ private final Webhooks webhooks;
+
+
+ private final Agents agents;
+
+
+ public Interactions interactions() {
+ return interactions;
+ }
+
+
+ public Webhooks webhooks() {
+ return webhooks;
+ }
+
+
+ public Agents agents() {
+ return agents;
+ }
+ private final AsyncGenAI asyncSDK;
+
+ /**
+ * The Builder class allows the configuration of a new instance of the SDK.
+ */
+ public static class Builder {
+
+ private final SDKConfiguration sdkConfiguration = new SDKConfiguration();
+ private String serverUrl;
+ private String server;
+
+
+ private Builder() {
+ }
+
+ /**
+ * Allows the default HTTP client to be overridden with a custom implementation.
+ *
+ * @param client The HTTP client to use for all requests.
+ * @return The builder instance.
+ */
+ public Builder client(HTTPClient client) {
+ this.sdkConfiguration.setClient(client);
+ return this;
+ }
+
+ /**
+ * Configures the SDK to use the provided security details.
+ *
+ * @param security The security details to use for all requests. Can be {@code null}.
+ * @return The builder instance.
+ */
+ public Builder security(com.google.genai.gaos.models.shared.Security security) {
+ this.sdkConfiguration.setSecuritySource(SecuritySource.of(security));
+ return this;
+ }
+
+ /**
+ * Configures the SDK to use a custom security source.
+ *
+ * @param securitySource The security source to use for all requests.
+ * @return The builder instance.
+ */
+ public Builder securitySource(SecuritySource securitySource) {
+ Utils.checkNotNull(securitySource, "securitySource");
+ this.sdkConfiguration.setSecuritySource(securitySource);
+ return this;
+ }
+
+ /**
+ * Overrides the default server URL.
+ *
+ * @param serverUrl The server URL to use for all requests.
+ * @return The builder instance.
+ */
+ public Builder serverURL(String serverUrl) {
+ this.serverUrl = serverUrl;
+ return this;
+ }
+
+ /**
+ * Overrides the default server URL with a templated URL populated with the provided parameters.
+ *
+ * @param serverUrl The server URL to use for all requests.
+ * @param params The parameters to use when templating the URL.
+ * @return The builder instance.
+ */
+ public Builder serverURL(String serverUrl, Map
+ * Convenience method that calls {@link HTTPClient#enableDebugLogging(boolean)}.
+ * {@link SpeakeasyHTTPClient} honors this setting. If you are using a custom HTTP client,
+ * it is up to the custom client to honor this setting.
+ * Creates a new interaction.
+ *
+ * @return The call builder
+ */
+ public CreateInteractionRequestBuilder create() {
+ return new CreateInteractionRequestBuilder(sdkConfiguration);
+ }
+
+ /**
+ * Creating an interaction
+ *
+ * Creates a new interaction.
+ *
+ * @param body The request body.
+ * @return The response from the API call
+ * @throws RuntimeException subclass if the API call fails
+ */
+ public CreateInteractionResponse create(CreateInteractionRequestBody body) {
+ return create(Optional.empty(), body, Optional.empty());
+ }
+
+ /**
+ * Creating an interaction
+ *
+ * Creates a new interaction.
+ *
+ * @param apiVersion Which version of the API to use.
+ * @param body The request body.
+ * @param options additional options
+ * @return The response from the API call
+ * @throws RuntimeException subclass if the API call fails
+ */
+ public CreateInteractionResponse create(
+ Optional Retrieves the full details of a single interaction based on its `Interaction.id`.
+ *
+ * @return The call builder
+ */
+ public GetInteractionByIdRequestBuilder get() {
+ return new GetInteractionByIdRequestBuilder(sdkConfiguration);
+ }
+
+ /**
+ * Retrieving an interaction
+ *
+ * Retrieves the full details of a single interaction based on its `Interaction.id`.
+ *
+ * @param request The request object containing all the parameters for the API call.
+ * @return The response from the API call
+ * @throws RuntimeException subclass if the API call fails
+ */
+ public GetInteractionByIdResponse get(GetInteractionByIdRequest request) {
+ return get(request, Optional.empty());
+ }
+
+ /**
+ * Retrieving an interaction
+ *
+ * Retrieves the full details of a single interaction based on its `Interaction.id`.
+ *
+ * @param request The request object containing all the parameters for the API call.
+ * @param options additional options
+ * @return The response from the API call
+ * @throws RuntimeException subclass if the API call fails
+ */
+ public GetInteractionByIdResponse get(GetInteractionByIdRequest request, Optional Deletes the interaction by id.
+ *
+ * @return The call builder
+ */
+ public DeleteInteractionRequestBuilder delete() {
+ return new DeleteInteractionRequestBuilder(sdkConfiguration);
+ }
+
+ /**
+ * Deleting an interaction
+ *
+ * Deletes the interaction by id.
+ *
+ * @param id The unique identifier of the interaction to delete.
+ * @return The response from the API call
+ * @throws RuntimeException subclass if the API call fails
+ */
+ public DeleteInteractionResponse delete(String id) {
+ return delete(id, Optional.empty(), Optional.empty());
+ }
+
+ /**
+ * Deleting an interaction
+ *
+ * Deletes the interaction by id.
+ *
+ * @param id The unique identifier of the interaction to delete.
+ * @param apiVersion Which version of the API to use.
+ * @param options additional options
+ * @return The response from the API call
+ * @throws RuntimeException subclass if the API call fails
+ */
+ public DeleteInteractionResponse delete(
+ String id, Optional Cancels an interaction by id. This only applies to background interactions that are still running.
+ *
+ * @return The call builder
+ */
+ public CancelInteractionByIdRequestBuilder cancel() {
+ return new CancelInteractionByIdRequestBuilder(sdkConfiguration);
+ }
+
+ /**
+ * Canceling an interaction
+ *
+ * Cancels an interaction by id. This only applies to background interactions that are still running.
+ *
+ * @param id The unique identifier of the interaction to cancel.
+ * @return The response from the API call
+ * @throws RuntimeException subclass if the API call fails
+ */
+ public CancelInteractionByIdResponse cancel(String id) {
+ return cancel(id, Optional.empty(), Optional.empty());
+ }
+
+ /**
+ * Canceling an interaction
+ *
+ * Cancels an interaction by id. This only applies to background interactions that are still running.
+ *
+ * @param id The unique identifier of the interaction to cancel.
+ * @param apiVersion Which version of the API to use.
+ * @param options additional options
+ * @return The response from the API call
+ * @throws RuntimeException subclass if the API call fails
+ */
+ public CancelInteractionByIdResponse cancel(
+ String id, Optional An agent definition for the CreateAgent API.
+ * This message is the target for annotation-parser-based JSON parsing.
+ * New format:
+ * {
+ * "id": "customer-sentinel",
+ * "base_agent": "",
+ * "system_instruction": "...",
+ * "base_environment": { "type": "remote", "sources": [...] },
+ * "tools": [ {"type": "code_execution"} ]
+ * }
+ */
+@SuppressWarnings("all")
+public class Agent {
+ /**
+ * The unique identifier for the agent.
+ */
+ @JsonInclude(Include.NON_ABSENT)
+ @JsonProperty("id")
+ private Optional> tools() {
+ return (Optional
>) tools;
+ }
+
+ /**
+ * The environment configuration for the agent.
+ */
+ @SuppressWarnings("unchecked")
+ @JsonIgnore
+ public Optional