p2 =
+ client.async.interactions.create(
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input("What is quantum computing?")
+ .build());
+
+ p1.thenAccept(i -> System.out.println("Request 1 completed: " + i.id()));
+ p2.thenAccept(i -> System.out.println("Request 2 completed: " + i.id()));
+
+ CompletableFuture.allOf(p1, p2)
+ .thenRun(() -> System.out.println("\nAll parallel requests completed!"));
+
+ CompletableFuture.allOf(p1, p2).join();
+
+ System.out.println("\n=== Example completed ===");
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+
+ if (interaction.outputs().isPresent() && !interaction.outputs().get().isEmpty()) {
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ System.out.println(" Text: " + ((TextContent) output).text().orElse("(empty)"));
+ } else {
+ System.out.println(" " + output.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ private InteractionsAsyncCreate() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsAudioContent.java b/examples/src/main/java/com/google/genai/examples/InteractionsAudioContent.java
new file mode 100644
index 00000000000..e265cb76348
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsAudioContent.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.AudioContent;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.TextContent;
+
+/**
+ * Example demonstrating audio transcription and analysis using AudioContent with the Interactions
+ * API.
+ *
+ * This example shows:
+ *
+ * Using AudioContent.fromUri() to analyze audio from a URL
+ * Using AudioContent.fromData() to analyze base64-encoded audio
+ *
+ *
+ * To run this example:
+ *
+ * Set the GOOGLE_API_KEY environment variable: {@code export GOOGLE_API_KEY=YOUR_API_KEY}
+ * Compile the examples: {@code mvn clean compile}
+ * Run: {@code mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsAudioContent"}
+ *
+ *
+ * Note: The Interactions API is currently in beta.
+ */
+public final class InteractionsAudioContent {
+
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: Audio Content Example ===\n");
+
+ try {
+ // ===== PART 1: Audio from URI =====
+ System.out.println("--- PART 1: Audio from URI ---\n");
+
+ String audioUri = "https://storage.googleapis.com/cloud-samples-data/speech/brooklyn_bridge.mp3";
+ AudioContent audioContent = AudioContent.fromUri(audioUri, "audio/mp3");
+ TextContent textPrompt = TextContent.builder()
+ .text("Transcribe this audio.")
+ .build();
+
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .inputFromContents(textPrompt, audioContent)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ Interaction response = client.interactions.create(config);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ printResults(response);
+
+ // ===== PART 2: Audio from Inline Data (base64) =====
+ System.out.println("\n--- PART 2: Audio from Inline Data (Base64) ---\n");
+
+ // Small WAV file header encoded as base64
+ String base64Data = "UklGRiQAAABXQVZFZm10IBAAAAABAAEAQB8AAAB9AAACABAAZGF0YQAAAAA=";
+ AudioContent audioFromData = AudioContent.fromData(base64Data, "audio/wav");
+ TextContent textPrompt2 = TextContent.builder()
+ .text("What do you hear in this audio?")
+ .build();
+
+ CreateInteractionConfig config2 =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .inputFromContents(textPrompt2, audioFromData)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config2.toJson());
+ System.out.println();
+
+ Interaction response2 = client.interactions.create(config2);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response2.toJson());
+ System.out.println();
+
+ printResults(response2);
+
+ System.out.println("\n=== Example completed ===");
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+
+ if (interaction.outputs().isPresent() && !interaction.outputs().get().isEmpty()) {
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ System.out.println(" Text: " + ((TextContent) output).text().orElse("(empty)"));
+ } else {
+ System.out.println(" " + output.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ private InteractionsAudioContent() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsCancelExample.java b/examples/src/main/java/com/google/genai/examples/InteractionsCancelExample.java
new file mode 100644
index 00000000000..9e6f16282d9
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsCancelExample.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CancelInteractionConfig;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.GetInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.TextContent;
+
+/**
+ * Example: Cancel Interaction API
+ *
+ *
Demonstrates the interactions.cancel() API for background interactions.
+ *
+ *
Note: Only interactions created with background=true can be cancelled.
+ *
+ *
To run this example:
+ *
+ * Set the GOOGLE_API_KEY environment variable: {@code export GOOGLE_API_KEY=YOUR_API_KEY}
+ * Compile the examples: {@code mvn clean compile}
+ * Run: {@code mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsCancelExample"}
+ *
+ *
+ * Note: The Interactions API is currently in beta.
+ */
+public final class InteractionsCancelExample {
+
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: Cancel Example ===\n");
+
+ try {
+ // ===== STEP 1: Create Background Interaction =====
+ System.out.println("--- STEP 1: Create Background Interaction ---\n");
+
+ CreateInteractionConfig createConfig =
+ CreateInteractionConfig.builder()
+ .agent("deep-research-pro-preview-12-2025")
+ .input("Write an essay about space exploration.")
+ .background(true)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(createConfig.toJson());
+ System.out.println();
+
+ Interaction interaction = client.interactions.create(createConfig);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(interaction.toJson());
+ System.out.println();
+
+ printResults(interaction);
+
+ String interactionId = interaction.id();
+
+ // ===== STEP 2: Cancel the Interaction =====
+ System.out.println("\n--- STEP 2: Cancel the Interaction ---\n");
+
+ try {
+ CancelInteractionConfig cancelConfig = CancelInteractionConfig.builder().build();
+ Interaction cancelled = client.interactions.cancel(interactionId, cancelConfig);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(cancelled.toJson());
+ System.out.println();
+
+ printResults(cancelled);
+ } catch (Exception e) {
+ System.out.println("Results:");
+ System.out.println(" Cancel failed: " + e.getMessage());
+ System.out.println(" (May happen if interaction completed too quickly)");
+ }
+
+ // ===== STEP 3: Verify Final State =====
+ System.out.println("\n--- STEP 3: Verify Final State ---\n");
+
+ try {
+ GetInteractionConfig getConfig = GetInteractionConfig.builder().build();
+ Interaction retrieved = client.interactions.get(interactionId, getConfig);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(retrieved.toJson());
+ System.out.println();
+
+ printResults(retrieved);
+ } catch (Exception e) {
+ System.out.println("Results:");
+ System.out.println(" Get failed: " + e.getMessage());
+ }
+
+ System.out.println("\n=== Example completed ===");
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+
+ if (interaction.outputs().isPresent() && !interaction.outputs().get().isEmpty()) {
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ System.out.println(" Text: " + ((TextContent) output).text().orElse("(empty)"));
+ } else {
+ System.out.println(" " + output.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ private InteractionsCancelExample() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsCodeExecution.java b/examples/src/main/java/com/google/genai/examples/InteractionsCodeExecution.java
new file mode 100644
index 00000000000..fe9f9fad30d
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsCodeExecution.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2025 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:
+ *
+ *
Note: The Interactions API is currently only available via the Gemini Developer API (not
+ * Vertex AI).
+ *
+ *
1. 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
+ *
+ *
mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsCodeExecution"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.CodeExecutionCallContent;
+import com.google.genai.types.interactions.content.CodeExecutionResultContent;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.TextContent;
+import com.google.genai.types.interactions.tools.CodeExecution;
+
+/**
+ * Example: Code Execution Tool with the Interactions API
+ *
+ *
Demonstrates how to use the CodeExecution to enable the model to execute code as part of
+ * generation. The model can write and run code to solve problems.
+ *
+ *
Note: The Interactions API is in beta and subject to change.
+ */
+public final class InteractionsCodeExecution {
+
+ public static void main(String[] args) {
+ // Instantiate the client. The client gets the API key from the environment variable
+ // `GOOGLE_API_KEY`.
+ //
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: Code Execution Tool Example ===\n");
+
+ // ===== STEP 1: Create CodeExecution =====
+ System.out.println("STEP 1: Create CodeExecution\n");
+
+ CodeExecution codeTool = CodeExecution.builder().build();
+
+ System.out.println("CodeExecution created successfully\n");
+
+ // ===== STEP 2: Create interaction with Code Execution enabled =====
+ System.out.println("---\n");
+ System.out.println("STEP 2: Create interaction with Code Execution enabled\n");
+
+ String userQuestion =
+ "Calculate the first 20 Fibonacci numbers and find their sum. "
+ + "Show me the code and the result.";
+ System.out.println("User: " + userQuestion + "\n");
+
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input(userQuestion)
+ .tools(codeTool)
+ .build();
+
+ // Print the request JSON
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ Interaction response = client.interactions.create(config);
+
+ // Print the response JSON
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ // ===== STEP 3: Extract and display the results =====
+ System.out.println("---\n");
+ System.out.println("STEP 3: Extract and display the results\n");
+
+ System.out.println("Response received. Interaction ID: " + response.id());
+ System.out.println();
+
+ if (response.outputs().isPresent()) {
+ for (Content content : response.outputs().get()) {
+ if (content instanceof TextContent) {
+ System.out.println("Text: " + ((TextContent) content).text().orElse("(empty)"));
+ System.out.println();
+ } else if (content instanceof CodeExecutionCallContent) {
+ CodeExecutionCallContent codeCall = (CodeExecutionCallContent) content;
+ System.out.println("Code Execution Call:");
+ System.out.println(" ID: " + codeCall.id());
+ if (codeCall.arguments().isPresent()) {
+ System.out.println(" Language: " + codeCall.arguments().get().language().orElse("N/A"));
+ System.out.println(" Code:");
+ System.out.println(" ---");
+ System.out.println(codeCall.arguments().get().code().orElse("(empty)"));
+ System.out.println(" ---");
+ }
+ System.out.println();
+ } else if (content instanceof CodeExecutionResultContent) {
+ CodeExecutionResultContent codeResult = (CodeExecutionResultContent) content;
+ System.out.println("Code Execution Result:");
+ System.out.println(" Call ID: " + codeResult.callId().orElse("N/A"));
+ System.out.println(" Is Error: " + codeResult.isError().orElse(false));
+ System.out.println(" Result:");
+ System.out.println(" ---");
+ System.out.println(codeResult.result().orElse("(empty)"));
+ System.out.println(" ---");
+ System.out.println();
+ }
+ }
+ }
+
+ System.out.println("\n=== Example completed ===");
+ }
+
+ private InteractionsCodeExecution() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsComputerUse.java b/examples/src/main/java/com/google/genai/examples/InteractionsComputerUse.java
new file mode 100644
index 00000000000..18f6d265a22
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsComputerUse.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright 2025 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:
+ *
+ *
Note: The Interactions API is currently only available via the Gemini Developer API (not
+ * Vertex AI).
+ *
+ *
IMPORTANT: Computer Use tool may require special API access. This example demonstrates the
+ * configuration but may not work without proper authorization.
+ *
+ *
1. 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
+ *
+ *
mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsComputerUse"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.TextContent;
+import com.google.genai.types.interactions.tools.ComputerUse;
+
+/**
+ * Example: Computer Use Tool with the Interactions API
+ *
+ *
Demonstrates how to use the ComputerUse to enable the model to interact with a computer
+ * environment. This tool allows the model to control applications, browse web pages, and perform
+ * other computer-based tasks.
+ *
+ *
IMPORTANT NOTES:
+ *
+ * This feature may require special API access and authorization.
+ * ComputerUse is a configuration-only tool - it enables a capability but does not
+ * have explicit call/result content types in the SDK.
+ * Results from computer use operations are returned as standard content types like
+ * TextContent or ImageContent (e.g., screenshots).
+ * Unlike FunctionCallContent or CodeExecutionCallContent, there are no
+ * ComputerUseCallContent or ComputerUseResultContent types.
+ *
+ *
+ * Note: The Interactions API is in beta and subject to change.
+ */
+public final class InteractionsComputerUse {
+
+ public static void main(String[] args) {
+ // Instantiate the client. The client gets the API key from the environment variable
+ // `GOOGLE_API_KEY`.
+ //
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: Computer Use Tool Example ===\n");
+
+ System.out.println(
+ "IMPORTANT: Computer Use tool may require special API access and authorization.\n");
+
+ // ===== STEP 1: Create ComputerUse =====
+ System.out.println("STEP 1: Create ComputerUse\n");
+
+ // Configure the computer use environment
+ // Common environments: "browser" for web browsing, "desktop" for full desktop access
+ //
+ // IMPORTANT: ComputerUse is a configuration that enables computer use capabilities.
+ // Unlike FunctionCall or CodeExecution, it does NOT have corresponding
+ // ComputerUseCallContent or ComputerUseResultContent types.
+ // Results are returned as standard content types (TextContent, ImageContent, etc.)
+ ComputerUse computerTool =
+ ComputerUse.builder()
+ .environment("browser")
+ // Optionally exclude predefined functions
+ // .excludedPredefinedFunctions("function1", "function2")
+ .build();
+
+ System.out.println("ComputerUse created successfully");
+ System.out.println("Environment: " + computerTool.environment().orElse("default"));
+ System.out.println();
+
+ // ===== STEP 2: Create interaction with Computer Use enabled =====
+ System.out.println("---\n");
+ System.out.println("STEP 2: Create interaction with Computer Use enabled\n");
+
+ String userQuestion = "Navigate to https://www.example.com and tell me what you see.";
+ System.out.println("User: " + userQuestion + "\n");
+
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input(userQuestion)
+ .tools(computerTool)
+ .build();
+
+ // Print the request JSON
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ try {
+ Interaction response = client.interactions.create(config);
+
+ // Print the response JSON
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ // ===== STEP 3: Extract and display the results =====
+ System.out.println("---\n");
+ System.out.println("STEP 3: Extract and display the results\n");
+
+ System.out.println("Response received. Interaction ID: " + response.id());
+ System.out.println();
+
+ if (response.outputs().isPresent()) {
+ for (Content content : response.outputs().get()) {
+ System.out.println("Content Type: " + content.getClass().getSimpleName());
+
+ if (content instanceof TextContent) {
+ System.out.println("Text: " + ((TextContent) content).text().orElse("(empty)"));
+ System.out.println();
+ }
+
+ // IMPORTANT: ComputerUse does NOT have dedicated content types
+ // (no ComputerUseCallContent or ComputerUseResultContent).
+ //
+ // Instead, computer use operations return results as:
+ // - TextContent: For textual responses and descriptions
+ // - ImageContent: For screenshots of computer actions
+ // - Other standard content types as needed
+ //
+ // This is different from tools like FunctionCall, CodeExecution, etc.,
+ // which have explicit call/result content type pairs.
+ }
+ }
+
+ System.out.println("\n=== Example completed successfully ===");
+
+ } catch (Exception e) {
+ System.err.println("\n=== Error occurred ===");
+ System.err.println("Error: " + e.getMessage());
+ System.err.println(
+ "\nNote: Computer Use tool may require special API access or authorization.");
+ System.err.println("Please check:");
+ System.err.println(" 1. Your API key has Computer Use permissions");
+ System.err.println(" 2. The feature is enabled for your account");
+ System.err.println(" 3. You're using a model that supports Computer Use");
+ e.printStackTrace();
+ }
+ }
+
+ private InteractionsComputerUse() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsCreateExample.java b/examples/src/main/java/com/google/genai/examples/InteractionsCreateExample.java
new file mode 100644
index 00000000000..a54de14389e
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsCreateExample.java
@@ -0,0 +1,290 @@
+/*
+ * Copyright 2025 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:
+ *
+ *
Note: The Interactions API is currently only available via the Gemini Developer API (not
+ * Vertex AI).
+ *
+ *
1. 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
+ *
+ *
mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsCreateExample"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.GetInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.AudioContent;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.DocumentContent;
+import com.google.genai.types.interactions.content.ImageContent;
+import com.google.genai.types.interactions.content.TextContent;
+import com.google.genai.types.interactions.content.ThoughtContent;
+import com.google.genai.types.interactions.content.VideoContent;
+
+/**
+ * Example: Create Interaction with All Content Types
+ *
+ *
Demonstrates interactions.create() with all available INPUT content types:
+ *
+ *
+ * TextContent - Plain text input
+ * ImageContent - Image via URL
+ * AudioContent - Audio via URL
+ * VideoContent - Video via URL
+ * DocumentContent - PDF document via URL
+ *
+ *
+ * Also shows all possible OUTPUT content types that may be returned.
+ *
+ *
Note: The Interactions API is in beta and subject to change.
+ */
+public final class InteractionsCreateExample {
+
+ public static void main(String[] args) {
+ // Instantiate the client. The client gets the API key from the environment variable
+ // `GOOGLE_API_KEY`.
+ //
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: All Content Types Example ===\n");
+
+ try {
+ // ===== PART 1: TextContent =====
+ System.out.println("--- PART 1: TextContent ---\n");
+
+ TextContent textContent = TextContent.builder()
+ .text("What is the meaning of life?")
+ .build();
+
+ CreateInteractionConfig textConfig =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .inputFromContents(textContent)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(textConfig.toJson());
+ System.out.println();
+
+ Interaction textResponse = client.interactions.create(textConfig);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(textResponse.toJson());
+ System.out.println();
+
+ printResults(textResponse);
+
+ // ===== PART 2: ImageContent =====
+ System.out.println("\n--- PART 2: ImageContent ---\n");
+
+ String imageUri = "https://storage.googleapis.com/generativeai-downloads/images/cake.jpg";
+ ImageContent imageContent = ImageContent.fromUri(imageUri, "image/jpeg");
+ TextContent imagePrompt = TextContent.builder()
+ .text("Describe this image in detail.")
+ .build();
+
+ CreateInteractionConfig imageConfig =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .inputFromContents(imagePrompt, imageContent)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(imageConfig.toJson());
+ System.out.println();
+
+ Interaction imageResponse = client.interactions.create(imageConfig);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(imageResponse.toJson());
+ System.out.println();
+
+ printResults(imageResponse);
+
+ // ===== PART 3: AudioContent =====
+ System.out.println("\n--- PART 3: AudioContent ---\n");
+
+ String audioUri = "https://storage.googleapis.com/cloud-samples-data/speech/brooklyn_bridge.mp3";
+ AudioContent audioContent = AudioContent.fromUri(audioUri, "audio/mp3");
+ TextContent audioPrompt = TextContent.builder()
+ .text("Transcribe this audio.")
+ .build();
+
+ CreateInteractionConfig audioConfig =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .inputFromContents(audioPrompt, audioContent)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(audioConfig.toJson());
+ System.out.println();
+
+ Interaction audioResponse = client.interactions.create(audioConfig);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(audioResponse.toJson());
+ System.out.println();
+
+ printResults(audioResponse);
+
+ // ===== PART 4: VideoContent =====
+ System.out.println("\n--- PART 4: VideoContent ---\n");
+
+ String videoUri = "https://storage.googleapis.com/cloud-samples-data/generative-ai/video/pixel8.mp4";
+ VideoContent videoContent = VideoContent.fromUri(videoUri, "video/mp4");
+ TextContent videoPrompt = TextContent.builder()
+ .text("Describe what happens in this video.")
+ .build();
+
+ CreateInteractionConfig videoConfig =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .inputFromContents(videoPrompt, videoContent)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(videoConfig.toJson());
+ System.out.println();
+
+ Interaction videoResponse = client.interactions.create(videoConfig);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(videoResponse.toJson());
+ System.out.println();
+
+ printResults(videoResponse);
+
+ // ===== PART 5: DocumentContent (PDF) =====
+ System.out.println("\n--- PART 5: DocumentContent ---\n");
+
+ String pdfUri = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf";
+ DocumentContent documentContent = DocumentContent.fromUri(pdfUri, "application/pdf");
+ TextContent docPrompt = TextContent.builder()
+ .text("Summarize the main points of this document.")
+ .build();
+
+ CreateInteractionConfig docConfig =
+ CreateInteractionConfig.builder()
+ .model("gemini-3-pro-preview")
+ .inputFromContents(docPrompt, documentContent)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(docConfig.toJson());
+ System.out.println();
+
+ Interaction docResponse = client.interactions.create(docConfig);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(docResponse.toJson());
+ System.out.println();
+
+ printResults(docResponse);
+
+ // ===== PART 6: Multiple Content Types Combined =====
+ System.out.println("\n--- PART 6: Multiple Content Types Combined ---\n");
+
+ // Note: Using gemini-3-pro-preview for multi-modal (image + video) combined requests
+ ImageContent cakeImage = ImageContent.fromUri(
+ "https://storage.googleapis.com/generativeai-downloads/images/cake.jpg", "image/jpeg");
+ VideoContent pixelVideo = VideoContent.fromUri(
+ "https://storage.googleapis.com/cloud-samples-data/generative-ai/video/pixel8.mp4", "video/mp4");
+ TextContent multiPrompt = TextContent.builder()
+ .text("Compare the cake image with what you see in the video. Are they related?")
+ .build();
+
+ CreateInteractionConfig multiConfig =
+ CreateInteractionConfig.builder()
+ .model("gemini-3-pro-preview")
+ .inputFromContents(multiPrompt, cakeImage, pixelVideo)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(multiConfig.toJson());
+ System.out.println();
+
+ Interaction multiResponse = client.interactions.create(multiConfig);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(multiResponse.toJson());
+ System.out.println();
+
+ printResults(multiResponse);
+
+ // ===== PART 7: Verify with Get API =====
+ System.out.println("\n--- PART 7: Verify Last Interaction (Get API) ---\n");
+
+ GetInteractionConfig getConfig = GetInteractionConfig.builder().build();
+
+ Interaction retrieved = client.interactions.get(multiResponse.id(), getConfig);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(retrieved.toJson());
+ System.out.println();
+
+ printResults(retrieved);
+
+ System.out.println("\n=== Example completed ===");
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ /** Prints extracted results from the interaction response. */
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+
+ if (!interaction.outputs().isPresent() || interaction.outputs().get().isEmpty()) {
+ System.out.println(" Outputs: (none)");
+ return;
+ }
+
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ TextContent t = (TextContent) output;
+ String text = t.text().orElse("(empty)");
+ System.out.println(" Text: " + text);
+ } else if (output instanceof ThoughtContent) {
+ ThoughtContent tc = (ThoughtContent) output;
+ System.out.println(" ThoughtContent:");
+ System.out.println(" signature: " + tc.signature().orElse("(none)"));
+ if (tc.summary().isPresent()) {
+ System.out.println(" summaries: " + tc.summary().get().size());
+ }
+ } else {
+ System.out.println(" " + output.getClass().getSimpleName());
+ }
+ }
+ }
+
+ private InteractionsCreateExample() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsDeleteExample.java b/examples/src/main/java/com/google/genai/examples/InteractionsDeleteExample.java
new file mode 100644
index 00000000000..ca98a506be4
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsDeleteExample.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.DeleteInteractionConfig;
+import com.google.genai.types.interactions.DeleteInteractionResponse;
+import com.google.genai.types.interactions.GetInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.TextContent;
+
+/**
+ * Example: Delete Interaction API
+ *
+ *
Demonstrates the interactions.delete() API to delete an interaction.
+ *
+ *
To run this example:
+ *
+ * Set the GOOGLE_API_KEY environment variable: {@code export GOOGLE_API_KEY=YOUR_API_KEY}
+ * Compile the examples: {@code mvn clean compile}
+ * Run: {@code mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsDeleteExample"}
+ *
+ *
+ * Note: The Interactions API is currently in beta.
+ */
+public final class InteractionsDeleteExample {
+
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: Delete Example ===\n");
+
+ try {
+ // ===== STEP 1: Create an Interaction =====
+ System.out.println("--- STEP 1: Create an Interaction ---\n");
+
+ CreateInteractionConfig createConfig =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input("What is the capital of France?")
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(createConfig.toJson());
+ System.out.println();
+
+ Interaction interaction = client.interactions.create(createConfig);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(interaction.toJson());
+ System.out.println();
+
+ printResults(interaction);
+
+ String interactionId = interaction.id();
+
+ // ===== STEP 2: Delete the Interaction =====
+ System.out.println("\n--- STEP 2: Delete the Interaction ---\n");
+
+ DeleteInteractionConfig deleteConfig = DeleteInteractionConfig.builder().build();
+ DeleteInteractionResponse deleteResponse =
+ client.interactions.delete(interactionId, deleteConfig);
+
+ System.out.println("Results:");
+ System.out.println(" Deleted interaction: " + interactionId);
+ System.out.println(" Response: " + deleteResponse);
+
+ // ===== STEP 3: Verify Deletion =====
+ System.out.println("\n--- STEP 3: Verify Deletion (Get should fail) ---\n");
+
+ try {
+ GetInteractionConfig getConfig = GetInteractionConfig.builder().build();
+ client.interactions.get(interactionId, getConfig);
+ System.out.println("ERROR: Should have thrown an exception!");
+ } catch (Exception e) {
+ System.out.println("Results:");
+ System.out.println(" Error: " + e.getMessage());
+ System.out.println(" (Expected - interaction was deleted)");
+ }
+
+ System.out.println("\n=== Example completed ===");
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+
+ if (interaction.outputs().isPresent() && !interaction.outputs().get().isEmpty()) {
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ System.out.println(" Text: " + ((TextContent) output).text().orElse("(empty)"));
+ } else {
+ System.out.println(" " + output.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ private InteractionsDeleteExample() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsDocumentContent.java b/examples/src/main/java/com/google/genai/examples/InteractionsDocumentContent.java
new file mode 100644
index 00000000000..cd477ae88d2
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsDocumentContent.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.DocumentContent;
+import com.google.genai.types.interactions.content.TextContent;
+
+/**
+ * Example demonstrating document analysis using DocumentContent with the Interactions API.
+ *
+ *
This example shows:
+ *
+ * Using DocumentContent.fromUri() to analyze a document from a URL
+ * Using DocumentContent.fromData() to analyze base64-encoded documents
+ *
+ *
+ * To run this example:
+ *
+ * Set the GOOGLE_API_KEY environment variable: {@code export GOOGLE_API_KEY=YOUR_API_KEY}
+ * Compile the examples: {@code mvn clean compile}
+ * Run: {@code mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsDocumentContent"}
+ *
+ *
+ * Note: The Interactions API is currently in beta.
+ */
+public final class InteractionsDocumentContent {
+
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: Document Content Example ===\n");
+
+ try {
+ // ===== PART 1: Document from URI =====
+ System.out.println("--- PART 1: Document from URI ---\n");
+
+ String documentUri = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf";
+ DocumentContent documentContent = DocumentContent.fromUri(documentUri, "application/pdf");
+ TextContent textPrompt = TextContent.builder()
+ .text("Summarize this document.")
+ .build();
+
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-3-pro-preview")
+ .inputFromContents(textPrompt, documentContent)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ Interaction response = client.interactions.create(config);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ printResults(response);
+
+ // ===== PART 2: Document from Inline Data (base64) =====
+ System.out.println("\n--- PART 2: Document from Inline Data (Base64) ---\n");
+
+ // Minimal valid PDF document (1 page with "Hello World")
+ String base64Data =
+ "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5kb2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKL01lZGlhQm94IFswIDAgNjEyIDc5Ml0KPj4KZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovUmVzb3VyY2VzIDw8Ci9Gb250IDw8Ci9GMSA0IDAgUgo+Pgo+PgovQ29udGVudHMgNSAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL1R5cGUgL0ZvbnQKL1N1YnR5cGUgL1R5cGUxCi9CYXNlRm9udCAvSGVsdmV0aWNhCj4+CmVuZG9iago1IDAgb2JqCjw8Ci9MZW5ndGggNDQKPj4Kc3RyZWFtCkJUCi9GMSA0OCBUZgoxMCA3MDAgVGQKKEhlbGxvIFdvcmxkKSBUagpFVAplbmRzdHJlYW0KZW5kb2JqCnhyZWYKMCA2CjAwMDAwMDAwMDAgNjU1MzUgZgogCjAwMDAwMDAwMTUgMDAwMDAgbiAKMDAwMDAwMDA2NCAwMDAwMCBuIAowMDAwMDAwMTUxIDAwMDAwIG4gCjAwMDAwMDAyNjIgMDAwMDAgbiAKMDAwMDAwMDM0OSAwMDAwMCBuIAp0cmFpbGVyCjw8Ci9TaXplIDYKL1Jvb3QgMSAwIFIKPj4Kc3RhcnR4cmVmCjQ0MgolJUVPRgo=";
+ DocumentContent documentFromData = DocumentContent.fromData(base64Data, "application/pdf");
+ TextContent textPrompt2 = TextContent.builder()
+ .text("What is the content of this document?")
+ .build();
+
+ CreateInteractionConfig config2 =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .inputFromContents(textPrompt2, documentFromData)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config2.toJson());
+ System.out.println();
+
+ Interaction response2 = client.interactions.create(config2);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response2.toJson());
+ System.out.println();
+
+ printResults(response2);
+
+ System.out.println("\n=== Example completed ===");
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+
+ if (interaction.outputs().isPresent() && !interaction.outputs().get().isEmpty()) {
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ System.out.println(" Text: " + ((TextContent) output).text().orElse("(empty)"));
+ } else {
+ System.out.println(" " + output.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ private InteractionsDocumentContent() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsFileSearch.java b/examples/src/main/java/com/google/genai/examples/InteractionsFileSearch.java
new file mode 100644
index 00000000000..6553a8e685b
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsFileSearch.java
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2025 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:
+ *
+ *
Note: The Interactions API is currently only available via the Gemini Developer API (not
+ * Vertex AI).
+ *
+ *
IMPORTANT: This example requires file search stores to be created beforehand.
+ *
+ *
Setup Instructions:
+ *
+ *
1. Create a file search store using the Google AI API:
+ *
+ *
Using gcloud CLI or API:
+ *
+ *
curl -X POST https://generativelanguage.googleapis.com/v1beta/fileSearchStores \
+ *
+ *
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
+ *
+ *
-H "Content-Type: application/json" \
+ *
+ *
-d '{"displayName": "my-document-store"}'
+ *
+ *
2. Upload files to the store:
+ *
+ *
curl -X POST
+ * https://generativelanguage.googleapis.com/v1beta/fileSearchStores/STORE_NAME/documents \
+ *
+ *
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
+ *
+ *
-F "file=@/path/to/document.pdf"
+ *
+ *
3. Set an API key environment variable:
+ *
+ *
export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ *
4. Update the store name in this example to match your created store.
+ *
+ *
5. Compile and run:
+ *
+ *
mvn clean compile
+ *
+ *
mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsFileSearch"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.FileSearchResult;
+import com.google.genai.types.interactions.content.FileSearchResultContent;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.TextContent;
+import com.google.genai.types.interactions.tools.FileSearch;
+
+/**
+ * Example: File Search Tool with the Interactions API
+ *
+ *
Demonstrates how to use the FileSearch to enable the model to search through file stores.
+ * This is useful for RAG (Retrieval-Augmented Generation) use cases where you want the model to
+ * answer questions based on your documents.
+ *
+ *
IMPORTANT: Requires file search stores to be created beforehand. See usage instructions
+ * above.
+ *
+ *
Note: The Interactions API is in beta and subject to change.
+ */
+public final class InteractionsFileSearch {
+
+ public static void main(String[] args) {
+ // Instantiate the client. The client gets the API key from the environment variable
+ // `GOOGLE_API_KEY`.
+ //
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: File Search Tool Example ===\n");
+
+ System.out.println("IMPORTANT: This example requires file search stores to be created.\n");
+ System.out.println("See the file header comments for setup instructions.\n");
+
+ // ===== STEP 1: Create FileSearch =====
+ System.out.println("STEP 1: Create FileSearch\n");
+
+ // Configure the file search tool
+ // Update the store names to match your created file search stores
+ FileSearch fileSearchTool =
+ FileSearch.builder()
+ .fileSearchStoreNames(
+ "my-document-store-1",
+ "my-document-store-2" // You can search across multiple stores
+ )
+ .topK(10) // Maximum number of results to return
+ // Optional: Add metadata filter
+ // .metadataFilter(ImmutableMap.of("category", "technical", "year", 2025))
+ .build();
+
+ System.out.println("FileSearch created successfully");
+ System.out.println(
+ "Store Names: " + fileSearchTool.fileSearchStoreNames().orElse(java.util.List.of()));
+ System.out.println("Top K: " + fileSearchTool.topK().orElse(10));
+ System.out.println();
+
+ // ===== STEP 2: Create interaction with File Search enabled =====
+ System.out.println("---\n");
+ System.out.println("STEP 2: Create interaction with File Search enabled\n");
+
+ String userQuestion =
+ "What are the main features described in the documentation? "
+ + "Please search through the uploaded files.";
+ System.out.println("User: " + userQuestion + "\n");
+
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input(userQuestion)
+ .tools(fileSearchTool)
+ .build();
+
+ // Print the request JSON
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ try {
+ Interaction response = client.interactions.create(config);
+
+ // Print the response JSON
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ // ===== STEP 3: Extract and display the results =====
+ System.out.println("---\n");
+ System.out.println("STEP 3: Extract and display the results\n");
+
+ System.out.println("Response received. Interaction ID: " + response.id());
+ System.out.println();
+
+ if (response.outputs().isPresent()) {
+ for (Content content : response.outputs().get()) {
+ if (content instanceof TextContent) {
+ System.out.println("Text: " + ((TextContent) content).text().orElse("(empty)"));
+ System.out.println();
+ } else if (content instanceof FileSearchResultContent) {
+ FileSearchResultContent searchResult = (FileSearchResultContent) content;
+ System.out.println("File Search Result:");
+
+ if (searchResult.result().isPresent()) {
+ for (FileSearchResult result : searchResult.result().get()) {
+ System.out.println(" Title: " + result.title().orElse("N/A"));
+ System.out.println(" File Search Store: " + result.fileSearchStore().orElse("N/A"));
+
+ if (result.text().isPresent()) {
+ String text = result.text().get();
+ System.out.println(" Text (first 500 chars):");
+ System.out.println(" ---");
+ System.out.println(text.length() > 500 ? text.substring(0, 500) + "..." : text);
+ System.out.println(" ---");
+ System.out.println(" Total text length: " + text.length() + " chars");
+ }
+ }
+ }
+ System.out.println();
+ }
+ }
+ }
+
+ System.out.println("\n=== Example completed successfully ===");
+
+ } catch (Exception e) {
+ System.err.println("\n=== Error occurred ===");
+ System.err.println("Error: " + e.getMessage());
+ System.err.println("\nNote: This example requires file search stores to be created.");
+ System.err.println("Please check:");
+ System.err.println(" 1. File search stores exist with the names specified");
+ System.err.println(" 2. Files have been uploaded to the stores");
+ System.err.println(" 3. Your API key has access to the stores");
+ System.err.println(" 4. The store names in this example match your actual store names");
+ e.printStackTrace();
+ }
+ }
+
+ private InteractionsFileSearch() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsFunctionCalling.java b/examples/src/main/java/com/google/genai/examples/InteractionsFunctionCalling.java
new file mode 100644
index 00000000000..aedfdacb3a5
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsFunctionCalling.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.genai.Client;
+import com.google.genai.types.Schema;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.FunctionCallContent;
+import com.google.genai.types.interactions.content.FunctionResultContent;
+import com.google.genai.types.interactions.content.TextContent;
+import com.google.genai.types.interactions.tools.Function;
+import java.util.Map;
+
+/**
+ * Example: Function Calling with the Interactions API
+ *
+ *
Demonstrates manual function calling where you define functions, extract calls from responses,
+ * execute them, and send results back.
+ *
+ *
To run this example:
+ *
+ * Set the GOOGLE_API_KEY environment variable: {@code export GOOGLE_API_KEY=YOUR_API_KEY}
+ * Compile the examples: {@code mvn clean compile}
+ * Run: {@code mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsFunctionCalling"}
+ *
+ *
+ * Note: The Interactions API is currently in beta.
+ */
+public final class InteractionsFunctionCalling {
+
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: Function Calling Example ===\n");
+
+ try {
+ // ===== STEP 1: Define the Function =====
+ System.out.println("--- STEP 1: Define the Function ---\n");
+
+ Function weatherTool =
+ Function.builder()
+ .name("get_weather")
+ .description("Get the current weather for a location")
+ .parameters(
+ Schema.builder()
+ .type("object")
+ .properties(
+ Map.of(
+ "location",
+ Schema.builder()
+ .type("string")
+ .description("The city name")
+ .build()))
+ .required("location")
+ .build())
+ .build();
+
+ System.out.println("Function defined: get_weather\n");
+
+ // ===== STEP 2: First Request - Ask about weather =====
+ System.out.println("--- STEP 2: First Request (triggers function call) ---\n");
+
+ CreateInteractionConfig config1 =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input("What's the weather like in Paris?")
+ .tools(weatherTool)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config1.toJson());
+ System.out.println();
+
+ Interaction response1 = client.interactions.create(config1);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response1.toJson());
+ System.out.println();
+
+ printResults(response1);
+
+ // Extract function call
+ FunctionCallContent functionCall = extractFunctionCall(response1);
+ if (functionCall == null) {
+ System.out.println("ERROR: Expected a function call but didn't receive one.");
+ return;
+ }
+
+ System.out.println(" Function Call ID: " + functionCall.id());
+ System.out.println(" Function Name: " + functionCall.name());
+ System.out.println(" Arguments: " + functionCall.arguments());
+
+ // ===== STEP 3: Execute Function and Send Result =====
+ System.out.println("\n--- STEP 3: Execute Function and Send Result ---\n");
+
+ Map weatherResult = executeGetWeather(functionCall.arguments());
+ System.out.println("Function executed. Result: " + weatherResult + "\n");
+
+ FunctionResultContent functionResult =
+ FunctionResultContent.builder()
+ .id(functionCall.id())
+ .name(functionCall.name())
+ .result(weatherResult)
+ .build();
+
+ CreateInteractionConfig config2 =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .inputFromContents(functionResult)
+ .previousInteractionId(response1.id())
+ .tools(weatherTool)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config2.toJson());
+ System.out.println();
+
+ Interaction response2 = client.interactions.create(config2);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response2.toJson());
+ System.out.println();
+
+ printResults(response2);
+
+ System.out.println("\n=== Example completed ===");
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static Map executeGetWeather(Map arguments) {
+ String location = (String) arguments.getOrDefault("location", "Unknown");
+ return ImmutableMap.of(
+ "location", location,
+ "temperature", "22",
+ "unit", "celsius",
+ "condition", "sunny with a few clouds");
+ }
+
+ private static FunctionCallContent extractFunctionCall(Interaction interaction) {
+ if (interaction.outputs().isPresent()) {
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof FunctionCallContent) {
+ return (FunctionCallContent) output;
+ }
+ }
+ }
+ return null;
+ }
+
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+
+ if (interaction.outputs().isPresent() && !interaction.outputs().get().isEmpty()) {
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ System.out.println(" Text: " + ((TextContent) output).text().orElse("(empty)"));
+ } else if (output instanceof FunctionCallContent) {
+ System.out.println(" FunctionCallContent:");
+ } else {
+ System.out.println(" " + output.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ private InteractionsFunctionCalling() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsGetExample.java b/examples/src/main/java/com/google/genai/examples/InteractionsGetExample.java
new file mode 100644
index 00000000000..f4848d7c989
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsGetExample.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.GetInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.TextContent;
+
+/**
+ * Example: Get Interaction API
+ *
+ * Demonstrates the interactions.get() API to retrieve an interaction by ID.
+ *
+ *
To run this example:
+ *
+ * Set the GOOGLE_API_KEY environment variable: {@code export GOOGLE_API_KEY=YOUR_API_KEY}
+ * Compile the examples: {@code mvn clean compile}
+ * Run: {@code mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsGetExample"}
+ *
+ *
+ * Note: The Interactions API is currently in beta.
+ */
+public final class InteractionsGetExample {
+
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: Get Example ===\n");
+
+ try {
+ // ===== STEP 1: Create an Interaction =====
+ System.out.println("--- STEP 1: Create an Interaction ---\n");
+
+ CreateInteractionConfig createConfig =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input("Explain quantum computing in 2-3 sentences.")
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(createConfig.toJson());
+ System.out.println();
+
+ Interaction interaction = client.interactions.create(createConfig);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(interaction.toJson());
+ System.out.println();
+
+ printResults(interaction);
+
+ // ===== STEP 2: Get Interaction by ID =====
+ System.out.println("\n--- STEP 2: Get Interaction by ID ---\n");
+
+ String interactionId = interaction.id();
+ GetInteractionConfig getConfig = GetInteractionConfig.builder().build();
+
+ Interaction retrieved = client.interactions.get(interactionId, getConfig);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(retrieved.toJson());
+ System.out.println();
+
+ printResults(retrieved);
+
+ System.out.println("\n=== Example completed ===");
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+
+ if (interaction.outputs().isPresent() && !interaction.outputs().get().isEmpty()) {
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ System.out.println(" Text: " + ((TextContent) output).text().orElse("(empty)"));
+ } else {
+ System.out.println(" " + output.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ private InteractionsGetExample() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsGoogleSearch.java b/examples/src/main/java/com/google/genai/examples/InteractionsGoogleSearch.java
new file mode 100644
index 00000000000..b544da2767f
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsGoogleSearch.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.GoogleSearchResult;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.GoogleSearchCallContent;
+import com.google.genai.types.interactions.content.GoogleSearchResultContent;
+import com.google.genai.types.interactions.content.TextContent;
+import com.google.genai.types.interactions.tools.GoogleSearch;
+import java.util.List;
+
+/**
+ * Example: Google Search Tool with the Interactions API
+ *
+ *
Demonstrates how to use the GoogleSearch tool to enable the model to search the web.
+ *
+ *
To run this example:
+ *
+ * Set the GOOGLE_API_KEY environment variable: {@code export GOOGLE_API_KEY=YOUR_API_KEY}
+ * Compile the examples: {@code mvn clean compile}
+ * Run: {@code mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsGoogleSearch"}
+ *
+ *
+ * Note: The Interactions API is currently in beta.
+ */
+public final class InteractionsGoogleSearch {
+
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: Google Search Tool Example ===\n");
+
+ try {
+ GoogleSearch searchTool = GoogleSearch.builder().build();
+
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input("What are the latest developments in quantum computing in 2025?")
+ .tools(searchTool)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ Interaction response = client.interactions.create(config);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ printResults(response);
+
+ System.out.println("\n=== Example completed ===");
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+
+ if (!interaction.outputs().isPresent() || interaction.outputs().get().isEmpty()) {
+ System.out.println(" Outputs: (none)");
+ return;
+ }
+
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ System.out.println(" Text: " + ((TextContent) output).text().orElse("(empty)"));
+ } else if (output instanceof GoogleSearchCallContent) {
+ GoogleSearchCallContent searchCall = (GoogleSearchCallContent) output;
+ System.out.println(" GoogleSearchCall: id=" + searchCall.id());
+ if (searchCall.arguments().isPresent()) {
+ System.out.println(" queries: " + searchCall.arguments().get().queries().orElse(List.of()));
+ }
+ } else if (output instanceof GoogleSearchResultContent) {
+ GoogleSearchResultContent searchResult = (GoogleSearchResultContent) output;
+ System.out.println(" GoogleSearchResult: callId=" + searchResult.callId().orElse("N/A"));
+ if (searchResult.result().isPresent()) {
+ List results = searchResult.result().get();
+ System.out.println(" results count: " + results.size());
+ for (int i = 0; i < Math.min(3, results.size()); i++) {
+ GoogleSearchResult result = results.get(i);
+ System.out.println(" [" + (i + 1) + "] " + result.title().orElse("N/A"));
+ }
+ }
+ } else {
+ System.out.println(" " + output.getClass().getSimpleName());
+ }
+ }
+ }
+
+ private InteractionsGoogleSearch() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsImageContent.java b/examples/src/main/java/com/google/genai/examples/InteractionsImageContent.java
new file mode 100644
index 00000000000..a1a90262aa5
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsImageContent.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.ImageContent;
+import com.google.genai.types.interactions.content.TextContent;
+
+/**
+ * Example demonstrating image analysis using ImageContent with the Interactions API.
+ *
+ * This example shows:
+ *
+ * Using ImageContent.fromUri() to analyze an image from a URL
+ * Using ImageContent.fromData() to analyze a base64-encoded image
+ *
+ *
+ * To run this example:
+ *
+ * Set the GOOGLE_API_KEY environment variable: {@code export GOOGLE_API_KEY=YOUR_API_KEY}
+ * Compile the examples: {@code mvn clean compile}
+ * Run: {@code mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsImageContent"}
+ *
+ *
+ * Note: The Interactions API is currently in beta.
+ */
+public final class InteractionsImageContent {
+
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: Image Content Example ===\n");
+
+ try {
+ // ===== PART 1: Image from URI =====
+ System.out.println("--- PART 1: Image from URI ---\n");
+
+ String imageUri = "https://storage.googleapis.com/generativeai-downloads/images/cake.jpg";
+ ImageContent imageContent = ImageContent.fromUri(imageUri, "image/jpeg");
+ TextContent textPrompt = TextContent.builder()
+ .text("Describe what you see in this image.")
+ .build();
+
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .inputFromContents(textPrompt, imageContent)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ Interaction response = client.interactions.create(config);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ printResults(response);
+
+ // ===== PART 2: Image from Inline Data (base64) =====
+ System.out.println("\n--- PART 2: Image from Inline Data (Base64) ---\n");
+
+ // Small 1x1 red pixel PNG encoded as base64
+ String base64Data =
+ "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==";
+ ImageContent imageFromData = ImageContent.fromData(base64Data, "image/png");
+ TextContent textPrompt2 = TextContent.builder()
+ .text("What color is this image?")
+ .build();
+
+ CreateInteractionConfig config2 =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .inputFromContents(textPrompt2, imageFromData)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config2.toJson());
+ System.out.println();
+
+ Interaction response2 = client.interactions.create(config2);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response2.toJson());
+ System.out.println();
+
+ printResults(response2);
+
+ System.out.println("\n=== Example completed ===");
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+
+ if (interaction.outputs().isPresent() && !interaction.outputs().get().isEmpty()) {
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ System.out.println(" Text: " + ((TextContent) output).text().orElse("(empty)"));
+ } else {
+ System.out.println(" " + output.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ private InteractionsImageContent() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsMcpServer.java b/examples/src/main/java/com/google/genai/examples/InteractionsMcpServer.java
new file mode 100644
index 00000000000..d24646f524a
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsMcpServer.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright 2025 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:
+ *
+ *
Note: The Interactions API is currently only available via the Gemini Developer API (not
+ * Vertex AI).
+ *
+ *
IMPORTANT: This example requires a running MCP (Model Context Protocol) server.
+ *
+ *
Setup Instructions:
+ *
+ *
1. Set up an MCP server. You can use one of the reference implementations:
+ *
+ *
- MCP Server SDK: https://github.com/modelcontextprotocol/servers
+ *
+ *
- Example: Weather MCP Server (Python)
+ *
+ *
pip install mcp
+ *
+ *
python -m mcp.server.weather --port 8080
+ *
+ *
2. Set an API key environment variable:
+ *
+ *
export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ *
3. Update the MCP server URL in this example to point to your running MCP server.
+ *
+ *
4. Compile and run:
+ *
+ *
mvn clean compile
+ *
+ *
mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsMcpServer"
+ */
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.McpServerToolCallContent;
+import com.google.genai.types.interactions.content.McpServerToolResultContent;
+import com.google.genai.types.interactions.content.TextContent;
+import com.google.genai.types.interactions.tools.McpServer;
+
+/**
+ * Example: MCP Server Tool with the Interactions API
+ *
+ *
Demonstrates how to use the McpServer to enable the model to interact with an MCP (Model
+ * Context Protocol) server. This allows integration with external tools and services that implement
+ * the MCP protocol.
+ *
+ *
IMPORTANT: Requires a running MCP server. See usage instructions above.
+ *
+ *
Note: The Interactions API is in beta and subject to change.
+ */
+public final class InteractionsMcpServer {
+
+ public static void main(String[] args) {
+ // Instantiate the client. The client gets the API key from the environment variable
+ // `GOOGLE_API_KEY`.
+ //
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: MCP Server Tool Example ===\n");
+
+ System.out.println("IMPORTANT: This example requires a running MCP server.\n");
+ System.out.println("See the file header comments for setup instructions.\n");
+
+ // ===== STEP 1: Create McpServer =====
+ System.out.println("STEP 1: Create McpServer\n");
+
+ // Configure the MCP server connection
+ // Update these values to match your MCP server setup
+ McpServer mcpTool =
+ McpServer.builder()
+ .name("my-mcp-server")
+ .url("http://localhost:8080/mcp") // Update this URL to your MCP server
+ // Optional: Add custom headers if your MCP server requires authentication
+ .headers(
+ ImmutableMap.of(
+ "Content-Type", "application/json"
+ // "Authorization", "Bearer YOUR_TOKEN"
+ ))
+ // Optional: Restrict to specific tools from the MCP server
+ // .allowedTools("weather", "calculator")
+ .build();
+
+ System.out.println("McpServer created successfully");
+ System.out.println("Name: " + mcpTool.name().orElse("N/A"));
+ System.out.println("URL: " + mcpTool.url().orElse("N/A"));
+ System.out.println();
+
+ // ===== STEP 2: Create interaction with MCP Server enabled =====
+ System.out.println("---\n");
+ System.out.println("STEP 2: Create interaction with MCP Server enabled\n");
+
+ String userQuestion =
+ "What's the weather like in San Francisco? "
+ + "(This uses the MCP server's weather tool)";
+ System.out.println("User: " + userQuestion + "\n");
+
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input(userQuestion)
+ .tools(mcpTool)
+ .build();
+
+ // Print the request JSON
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ try {
+ Interaction response = client.interactions.create(config);
+
+ // Print the response JSON
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ // ===== STEP 3: Extract and display the results =====
+ System.out.println("---\n");
+ System.out.println("STEP 3: Extract and display the results\n");
+
+ System.out.println("Response received. Interaction ID: " + response.id());
+ System.out.println();
+
+ if (response.outputs().isPresent()) {
+ for (Content content : response.outputs().get()) {
+ if (content instanceof TextContent) {
+ System.out.println("Text: " + ((TextContent) content).text().orElse("(empty)"));
+ System.out.println();
+ } else if (content instanceof McpServerToolCallContent) {
+ McpServerToolCallContent mcpCall = (McpServerToolCallContent) content;
+ System.out.println("MCP Server Tool Call:");
+ System.out.println(" ID: " + mcpCall.id());
+ System.out.println(" Tool Name: " + mcpCall.name());
+ System.out.println(" Server Name: " + mcpCall.serverName());
+ System.out.println(" Arguments: " + mcpCall.arguments());
+ System.out.println();
+ } else if (content instanceof McpServerToolResultContent) {
+ McpServerToolResultContent mcpResult = (McpServerToolResultContent) content;
+ System.out.println("MCP Server Tool Result:");
+ System.out.println(" Call ID: " + mcpResult.callId());
+ System.out.println(" Tool Name: " + mcpResult.name().orElse("N/A"));
+ System.out.println(" Server Name: " + mcpResult.serverName().orElse("N/A"));
+ System.out.println(" Result: " + mcpResult.result());
+ System.out.println();
+ }
+ }
+ }
+
+ System.out.println("\n=== Example completed successfully ===");
+
+ } catch (Exception e) {
+ System.err.println("\n=== Error occurred ===");
+ System.err.println("Error: " + e.getMessage());
+ System.err.println("\nNote: This example requires a running MCP server.");
+ System.err.println("Please check:");
+ System.err.println(" 1. Your MCP server is running and accessible");
+ System.err.println(" 2. The URL in this example matches your MCP server endpoint");
+ System.err.println(" 3. Any required authentication headers are configured");
+ System.err.println(" 4. Your firewall allows connections to the MCP server");
+ e.printStackTrace();
+ }
+ }
+
+ private InteractionsMcpServer() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsMediaResolution.java b/examples/src/main/java/com/google/genai/examples/InteractionsMediaResolution.java
new file mode 100644
index 00000000000..ab1b25894dc
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsMediaResolution.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.MediaResolution;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.ImageContent;
+import com.google.genai.types.interactions.content.TextContent;
+
+/**
+ * Example demonstrating MediaResolution with ImageContent in the Interactions API.
+ *
+ *
This example shows how to specify image resolution when analyzing images.
+ *
+ *
To run this example:
+ *
+ * Set the GOOGLE_API_KEY environment variable: {@code export GOOGLE_API_KEY=YOUR_API_KEY}
+ * Compile the examples: {@code mvn clean compile}
+ * Run: {@code mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsMediaResolution"}
+ *
+ *
+ * Note: The Interactions API is currently in beta.
+ */
+public final class InteractionsMediaResolution {
+
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: Media Resolution Example ===\n");
+
+ try {
+ String imageUri = "https://storage.googleapis.com/generativeai-downloads/images/cake.jpg";
+
+ // Create ImageContent with HIGH resolution
+ MediaResolution resolution = new MediaResolution(MediaResolution.Known.HIGH);
+ ImageContent imageContent = ImageContent.builder()
+ .uri(imageUri)
+ .mimeType(new com.google.genai.types.interactions.ImageMimeType("image/jpeg"))
+ .resolution(resolution)
+ .build();
+
+ TextContent textPrompt = TextContent.builder()
+ .text("Describe this image in detail.")
+ .build();
+
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .inputFromContents(textPrompt, imageContent)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ Interaction response = client.interactions.create(config);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ printResults(response);
+
+ System.out.println("\n=== Example completed ===");
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+
+ if (interaction.outputs().isPresent() && !interaction.outputs().get().isEmpty()) {
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ System.out.println(" Text: " + ((TextContent) output).text().orElse("(empty)"));
+ } else {
+ System.out.println(" " + output.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ private InteractionsMediaResolution() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsMultiTurnConversation.java b/examples/src/main/java/com/google/genai/examples/InteractionsMultiTurnConversation.java
new file mode 100644
index 00000000000..e5624d16d03
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsMultiTurnConversation.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.Turn;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.TextContent;
+
+/**
+ * Example: Multi-Turn Conversation with Turn objects
+ *
+ *
Demonstrates a multi-turn conversation using Turn objects with role assignment.
+ *
+ *
To run this example:
+ *
+ * Set the GOOGLE_API_KEY environment variable: {@code export GOOGLE_API_KEY=YOUR_API_KEY}
+ * Compile the examples: {@code mvn clean compile}
+ * Run: {@code mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsMultiTurnConversation"}
+ *
+ *
+ * Note: The Interactions API is currently in beta.
+ */
+public final class InteractionsMultiTurnConversation {
+
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: Multi-Turn Conversation Example ===\n");
+
+ try {
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .inputFromTurns(
+ Turn.builder()
+ .role("user")
+ .content(TextContent.builder().text("I'm planning a trip to Paris.").build())
+ .build(),
+ Turn.builder()
+ .role("model")
+ .content(TextContent.builder()
+ .text("That's wonderful! Paris is a beautiful city. What would you like to know?")
+ .build())
+ .build(),
+ Turn.builder()
+ .role("user")
+ .content(TextContent.builder().text("What are the top 3 must-see attractions?").build())
+ .build())
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ Interaction response = client.interactions.create(config);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ printResults(response);
+
+ System.out.println("\n=== Example completed ===");
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+
+ if (interaction.outputs().isPresent() && !interaction.outputs().get().isEmpty()) {
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ System.out.println(" Text: " + ((TextContent) output).text().orElse("(empty)"));
+ } else {
+ System.out.println(" " + output.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ private InteractionsMultiTurnConversation() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsMultipleContents.java b/examples/src/main/java/com/google/genai/examples/InteractionsMultipleContents.java
new file mode 100644
index 00000000000..9721e9573bf
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsMultipleContents.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.TextContent;
+
+/**
+ * Example: Single Turn with Multiple Content Items
+ *
+ *
Demonstrates using Content objects to send multiple content items in a single turn.
+ *
+ *
To run this example:
+ *
+ * Set the GOOGLE_API_KEY environment variable: {@code export GOOGLE_API_KEY=YOUR_API_KEY}
+ * Compile the examples: {@code mvn clean compile}
+ * Run: {@code mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsMultipleContents"}
+ *
+ *
+ * Note: The Interactions API is currently in beta.
+ */
+public final class InteractionsMultipleContents {
+
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: Multiple Contents Example ===\n");
+
+ try {
+ TextContent content1 = TextContent.builder()
+ .text("Tell me about the Eiffel Tower.")
+ .build();
+ TextContent content2 = TextContent.builder()
+ .text("Keep it brief, under 50 words.")
+ .build();
+
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .inputFromContents(content1, content2)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ Interaction response = client.interactions.create(config);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ printResults(response);
+
+ System.out.println("\n=== Example completed ===");
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+
+ if (interaction.outputs().isPresent() && !interaction.outputs().get().isEmpty()) {
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ System.out.println(" Text: " + ((TextContent) output).text().orElse("(empty)"));
+ } else {
+ System.out.println(" " + output.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ private InteractionsMultipleContents() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsMultipleToolsLifecycle.java.backup b/examples/src/main/java/com/google/genai/examples/InteractionsMultipleToolsLifecycle.java.backup
new file mode 100644
index 00000000000..282c5190e55
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsMultipleToolsLifecycle.java.backup
@@ -0,0 +1,592 @@
+/*
+ * Copyright 2025 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:
+ *
+ *
Note: The Interactions API is currently only available via the Gemini Developer API (not
+ * Vertex AI).
+ *
+ *
1. 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
+ *
+ *
mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsMultipleToolsLifecycle"
+ */
+package com.google.genai.examples;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.genai.Client;
+import com.google.genai.types.Schema;
+import com.google.genai.types.interactions.CancelInteractionConfig;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.DeleteInteractionConfig;
+import com.google.genai.types.interactions.DeleteInteractionResponse;
+import com.google.genai.types.interactions.GetInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.FunctionCallContent;
+import com.google.genai.types.interactions.content.TextContent;
+import com.google.genai.types.interactions.tools.CodeExecutionTool;
+import com.google.genai.types.interactions.tools.FunctionTool;
+import com.google.genai.types.interactions.tools.GoogleSearchTool;
+import com.google.genai.types.interactions.tools.Tool;
+import com.google.genai.types.interactions.tools.UrlContextTool;
+import java.lang.reflect.Method;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Example: Multiple Tools with Full Interaction Lifecycle
+ *
+ *
Demonstrates:
+ *
+ *
+ * CREATE - Create an interaction with multiple tools:
+ *
+ * FunctionTool with AFC (Automatic Function Calling)
+ * FunctionTool without AFC (Manual Function Calling)
+ * GoogleSearchTool (Web search)
+ * UrlContextTool (URL content retrieval)
+ * CodeExecutionTool (Code execution)
+ *
+ * GET - Retrieve interaction and validate it matches CREATE response
+ * CANCEL - Cancel the interaction
+ * GET after CANCEL - Verify status changed to CANCELLED
+ * DELETE - Delete the interaction
+ * GET after DELETE - Verify interaction is deleted (should fail)
+ *
+ *
+ * All requests and responses are logged and validated.
+ *
+ *
Note: The Interactions API is in beta and subject to change.
+ */
+public final class InteractionsMultipleToolsLifecycle {
+
+ private static final String SEPARATOR = "=".repeat(80);
+ private static final String SUB_SEPARATOR = "-".repeat(80);
+ private static final DateTimeFormatter TIMESTAMP_FORMAT =
+ DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
+
+ public static void main(String[] args) throws Exception {
+ // Instantiate the client
+ Client client = new Client();
+
+ System.out.println(SEPARATOR);
+ System.out.println("Interactions API: Multiple Tools Full Lifecycle Example");
+ System.out.println(SEPARATOR);
+ System.out.println();
+
+ try {
+ // ========================================
+ // STEP 1: CREATE - Create interaction with multiple tools
+ // ========================================
+ Interaction createResponse = stepCreate(client);
+
+ // ========================================
+ // STEP 2: GET - Retrieve and validate
+ // ========================================
+ Interaction getResponse = stepGet(client, createResponse);
+
+ // ========================================
+ // STEP 3: CANCEL - Cancel the interaction
+ // ========================================
+ Interaction cancelResponse = stepCancel(client, createResponse.id());
+
+ // ========================================
+ // STEP 4: GET after CANCEL - Verify cancelled
+ // ========================================
+ Interaction getAfterCancelResponse = stepGetAfterCancel(client, createResponse.id());
+
+ // ========================================
+ // STEP 5: DELETE - Delete the interaction
+ // ========================================
+ DeleteInteractionResponse deleteResponse = stepDelete(client, createResponse.id());
+
+ // ========================================
+ // STEP 6: GET after DELETE - Verify deleted
+ // ========================================
+ stepGetAfterDelete(client, createResponse.id());
+
+ System.out.println();
+ System.out.println(SEPARATOR);
+ System.out.println("✅ ALL LIFECYCLE STEPS COMPLETED SUCCESSFULLY");
+ System.out.println(SEPARATOR);
+
+ } catch (Exception e) {
+ System.err.println();
+ System.err.println(SEPARATOR);
+ System.err.println("❌ ERROR: " + e.getMessage());
+ System.err.println(SEPARATOR);
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+ // ==================================================================================
+ // STEP 1: CREATE
+ // ==================================================================================
+
+ private static Interaction stepCreate(Client client) throws Exception {
+ printStepHeader("STEP 1: CREATE", "Create interaction with multiple tools");
+
+ // Define all tools
+ List tools = new ArrayList<>();
+
+ // 1. FunctionTool WITH AFC (Automatic Function Calling)
+ System.out.println("Configuring FunctionTool WITH AFC (getWeather)...");
+ Method getWeatherMethod =
+ InteractionsMultipleToolsLifecycle.class.getMethod("getWeather", String.class);
+ FunctionTool afcFunctionTool =
+ FunctionTool.fromMethod("Get the current weather for a city", getWeatherMethod);
+ tools.add(afcFunctionTool);
+ System.out.println(" ✓ AFC enabled: " + afcFunctionTool.method().isPresent());
+
+ // 2. FunctionTool WITHOUT AFC (Manual Function Calling)
+ System.out.println("Configuring FunctionTool WITHOUT AFC (calculateSum)...");
+ FunctionTool manualFunctionTool =
+ FunctionTool.builder()
+ .name("calculate_sum")
+ .description("Calculate the sum of two numbers")
+ .parameters(
+ Schema.builder()
+ .type("object")
+ .properties(
+ Map.of(
+ "a",
+ Schema.builder()
+ .type("number")
+ .description("First number")
+ .build(),
+ "b",
+ Schema.builder()
+ .type("number")
+ .description("Second number")
+ .build()))
+ .required("a", "b")
+ .build())
+ .build();
+ tools.add(manualFunctionTool);
+ System.out.println(" ✓ Manual mode (no method): " + !manualFunctionTool.method().isPresent());
+
+ // 3. GoogleSearchTool
+ System.out.println("Configuring GoogleSearchTool...");
+ GoogleSearchTool googleSearchTool = GoogleSearchTool.builder().build();
+ tools.add(googleSearchTool);
+ System.out.println(" ✓ Google Search enabled");
+
+ // 4. UrlContextTool
+ System.out.println("Configuring UrlContextTool...");
+ UrlContextTool urlContextTool = UrlContextTool.builder().build();
+ tools.add(urlContextTool);
+ System.out.println(" ✓ URL Context enabled");
+
+ // 5. CodeExecutionTool
+ System.out.println("Configuring CodeExecutionTool...");
+ CodeExecutionTool codeExecutionTool = CodeExecutionTool.builder().build();
+ tools.add(codeExecutionTool);
+ System.out.println(" ✓ Code Execution enabled");
+
+ System.out.println();
+ System.out.println("Total tools configured: " + tools.size());
+ System.out.println();
+
+ // Create the interaction config
+ String userInput = "What's the weather like in Tokyo? Also calculate 42 + 58.";
+ System.out.println("User Input: " + userInput);
+ System.out.println();
+
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input(userInput)
+ .tools(tools)
+ // .background(true) // Disabled: gemini-2.5-flash doesn't support background mode
+ .build();
+
+ // Print request
+ printSubSection("CREATE REQUEST");
+ System.out.println("Model: " + config.model().orElse("N/A"));
+ System.out.println("Input: " + config.input().getValue().toString());
+ System.out.println("Background: " + config.background().orElse(false));
+ System.out.println("Tools count: " + config.tools().map(List::size).orElse(0));
+ System.out.println();
+
+ // Make the API call
+ System.out.println("Calling client.interactions.create()...");
+ long startTime = System.currentTimeMillis();
+ Interaction response = client.interactions.create(config);
+ long duration = System.currentTimeMillis() - startTime;
+
+ // Print response
+ printSubSection("CREATE RESPONSE");
+ printInteractionDetails(response, duration);
+
+ // Save response
+ saveResponse("1_create_response.json", response.toJson());
+
+ System.out.println();
+ return response;
+ }
+
+ // ==================================================================================
+ // STEP 2: GET
+ // ==================================================================================
+
+ private static Interaction stepGet(Client client, Interaction createResponse) {
+ printStepHeader("STEP 2: GET", "Retrieve interaction and validate");
+
+ String interactionId = createResponse.id();
+ System.out.println("Interaction ID: " + interactionId);
+ System.out.println();
+
+ // Print request
+ printSubSection("GET REQUEST");
+ System.out.println("Interaction ID: " + interactionId);
+ System.out.println();
+
+ // Make the API call
+ System.out.println("Calling client.interactions.get()...");
+ long startTime = System.currentTimeMillis();
+ GetInteractionConfig config = GetInteractionConfig.builder().build();
+ Interaction response = client.interactions.get(interactionId, config);
+ long duration = System.currentTimeMillis() - startTime;
+
+ // Print response
+ printSubSection("GET RESPONSE");
+ printInteractionDetails(response, duration);
+
+ // Save response
+ saveResponse("2_get_response.json", response.toJson());
+
+ // Validate GET matches CREATE
+ printSubSection("VALIDATION: GET vs CREATE");
+ validateInteractions(createResponse, response, "CREATE", "GET");
+
+ System.out.println();
+ return response;
+ }
+
+ // ==================================================================================
+ // STEP 3: CANCEL
+ // ==================================================================================
+
+ private static Interaction stepCancel(Client client, String interactionId) {
+ printStepHeader("STEP 3: CANCEL", "Cancel the interaction");
+
+ System.out.println("Interaction ID: " + interactionId);
+ System.out.println();
+
+ // Print request
+ printSubSection("CANCEL REQUEST");
+ System.out.println("Interaction ID: " + interactionId);
+ System.out.println();
+
+ // Make the API call
+ System.out.println("Calling client.interactions.cancel()...");
+ long startTime = System.currentTimeMillis();
+ CancelInteractionConfig config = CancelInteractionConfig.builder().build();
+ Interaction response = client.interactions.cancel(interactionId, config);
+ long duration = System.currentTimeMillis() - startTime;
+
+ // Print response
+ printSubSection("CANCEL RESPONSE");
+ printInteractionDetails(response, duration);
+
+ // Save response
+ saveResponse("3_cancel_response.json", response.toJson());
+
+ System.out.println();
+ return response;
+ }
+
+ // ==================================================================================
+ // STEP 4: GET after CANCEL
+ // ==================================================================================
+
+ private static Interaction stepGetAfterCancel(Client client, String interactionId) {
+ printStepHeader("STEP 4: GET after CANCEL", "Verify status changed to CANCELLED");
+
+ System.out.println("Interaction ID: " + interactionId);
+ System.out.println();
+
+ // Print request
+ printSubSection("GET (after CANCEL) REQUEST");
+ System.out.println("Interaction ID: " + interactionId);
+ System.out.println();
+
+ // Make the API call
+ System.out.println("Calling client.interactions.get()...");
+ long startTime = System.currentTimeMillis();
+ GetInteractionConfig config = GetInteractionConfig.builder().build();
+ Interaction response = client.interactions.get(interactionId, config);
+ long duration = System.currentTimeMillis() - startTime;
+
+ // Print response
+ printSubSection("GET (after CANCEL) RESPONSE");
+ printInteractionDetails(response, duration);
+
+ // Save response
+ saveResponse("4_get_after_cancel_response.json", response.toJson());
+
+ // Validate status is CANCELLED
+ printSubSection("VALIDATION: Status should be CANCELLED");
+ String status = response.status().toString();
+ if ("CANCELLED".equals(status)) {
+ System.out.println("✅ PASS: Status is CANCELLED");
+ } else {
+ System.out.println("❌ FAIL: Expected status CANCELLED, got: " + status);
+ }
+
+ System.out.println();
+ return response;
+ }
+
+ // ==================================================================================
+ // STEP 5: DELETE
+ // ==================================================================================
+
+ private static DeleteInteractionResponse stepDelete(Client client, String interactionId) {
+ printStepHeader("STEP 5: DELETE", "Delete the interaction");
+
+ System.out.println("Interaction ID: " + interactionId);
+ System.out.println();
+
+ // Print request
+ printSubSection("DELETE REQUEST");
+ System.out.println("Interaction ID: " + interactionId);
+ System.out.println();
+
+ // Make the API call
+ System.out.println("Calling client.interactions.delete()...");
+ long startTime = System.currentTimeMillis();
+ DeleteInteractionConfig config = DeleteInteractionConfig.builder().build();
+ DeleteInteractionResponse response = client.interactions.delete(interactionId, config);
+ long duration = System.currentTimeMillis() - startTime;
+
+ // Print response
+ printSubSection("DELETE RESPONSE");
+ System.out.println("Duration: " + duration + "ms");
+ System.out.println("HTTP Response: " + response.sdkHttpResponse().orElse(null));
+ System.out.println();
+
+ // Save response
+ saveResponse("5_delete_response.json", response.toJson());
+
+ System.out.println();
+ return response;
+ }
+
+ // ==================================================================================
+ // STEP 6: GET after DELETE
+ // ==================================================================================
+
+ private static void stepGetAfterDelete(Client client, String interactionId) {
+ printStepHeader("STEP 6: GET after DELETE", "Verify interaction is deleted (should fail)");
+
+ System.out.println("Interaction ID: " + interactionId);
+ System.out.println();
+
+ // Print request
+ printSubSection("GET (after DELETE) REQUEST");
+ System.out.println("Interaction ID: " + interactionId);
+ System.out.println();
+
+ // Make the API call - expect this to fail
+ System.out.println("Calling client.interactions.get() (expecting error)...");
+ try {
+ long startTime = System.currentTimeMillis();
+ GetInteractionConfig config = GetInteractionConfig.builder().build();
+ Interaction response = client.interactions.get(interactionId, config);
+ long duration = System.currentTimeMillis() - startTime;
+
+ // If we get here, the interaction was NOT deleted (unexpected)
+ printSubSection("GET (after DELETE) RESPONSE - UNEXPECTED SUCCESS");
+ System.out.println("❌ UNEXPECTED: GET succeeded after DELETE");
+ printInteractionDetails(response, duration);
+ saveResponse("6_get_after_delete_response_unexpected.json", response.toJson());
+
+ } catch (Exception e) {
+ // Expected: GET should fail because interaction was deleted
+ printSubSection("GET (after DELETE) RESPONSE - EXPECTED ERROR");
+ System.out.println("✅ PASS: GET failed as expected after DELETE");
+ System.out.println("Error type: " + e.getClass().getSimpleName());
+ System.out.println("Error message: " + e.getMessage());
+
+ // Save error
+ saveResponse(
+ "6_get_after_delete_error.txt",
+ "Error Type: " + e.getClass().getName() + "\nMessage: " + e.getMessage());
+ }
+
+ System.out.println();
+ }
+
+ // ==================================================================================
+ // HELPER METHODS
+ // ==================================================================================
+
+ /**
+ * AFC-enabled function: Get weather for a city.
+ *
+ * This method is public and static so it can be invoked via reflection for AFC.
+ */
+ public static Map getWeather(String location) {
+ System.out.println(" [AFC] Executing getWeather(\"" + location + "\")");
+ return ImmutableMap.of(
+ "location", location,
+ "temperature", "18",
+ "unit", "celsius",
+ "condition", "partly cloudy",
+ "humidity", "65%");
+ }
+
+ private static void printStepHeader(String stepTitle, String description) {
+ System.out.println(SEPARATOR);
+ System.out.println(stepTitle + ": " + description);
+ System.out.println(SEPARATOR);
+ System.out.println();
+ }
+
+ private static void printSubSection(String title) {
+ System.out.println(SUB_SEPARATOR);
+ System.out.println(title);
+ System.out.println(SUB_SEPARATOR);
+ }
+
+ private static void printInteractionDetails(Interaction interaction, long duration) {
+ System.out.println("Duration: " + duration + "ms");
+ System.out.println("ID: " + interaction.id());
+ System.out.println("Status: " + interaction.status());
+ System.out.println("Model: " + interaction.model().orElse("N/A"));
+ System.out.println("Created: " + interaction.created().map(Object::toString).orElse("N/A"));
+ System.out.println("Updated: " + interaction.updated().map(Object::toString).orElse("N/A"));
+
+ // Print outputs
+ if (interaction.outputs().isPresent() && !interaction.outputs().get().isEmpty()) {
+ System.out.println();
+ System.out.println("Outputs (" + interaction.outputs().get().size() + "):");
+ int index = 1;
+ for (Content output : interaction.outputs().get()) {
+ System.out.println(" [" + index + "] " + getContentTypeDescription(output));
+ if (output instanceof TextContent) {
+ TextContent textContent = (TextContent) output;
+ String text = textContent.text().orElse("(empty)");
+ // Truncate long text
+ if (text.length() > 100) {
+ System.out.println(" " + text.substring(0, 100) + "...");
+ } else {
+ System.out.println(" " + text);
+ }
+ } else if (output instanceof FunctionCallContent) {
+ FunctionCallContent fc = (FunctionCallContent) output;
+ System.out.println(" Function: " + fc.name());
+ System.out.println(" Arguments: " + fc.arguments());
+ }
+ index++;
+ }
+ } else {
+ System.out.println("Outputs: (none)");
+ }
+
+ // Print AFC history if present
+ if (interaction.automaticFunctionCallingHistory().isPresent()) {
+ List history = interaction.automaticFunctionCallingHistory().get();
+ System.out.println();
+ System.out.println("AFC History (" + history.size() + " interactions):");
+ for (int i = 0; i < history.size(); i++) {
+ System.out.println(" [" + (i + 1) + "] " + history.get(i).id());
+ }
+ }
+
+ System.out.println();
+ }
+
+ private static String getContentTypeDescription(Content content) {
+ if (content instanceof TextContent) {
+ return "TextContent";
+ } else if (content instanceof FunctionCallContent) {
+ return "FunctionCallContent";
+ } else {
+ return content.getClass().getSimpleName();
+ }
+ }
+
+ private static void validateInteractions(
+ Interaction expected, Interaction actual, String expectedLabel, String actualLabel) {
+ boolean allPassed = true;
+
+ // Validate ID
+ if (expected.id().equals(actual.id())) {
+ System.out.println("✅ ID matches: " + expected.id());
+ } else {
+ System.out.println(
+ "❌ ID mismatch: " + expectedLabel + "=" + expected.id() + ", " + actualLabel + "="
+ + actual.id());
+ allPassed = false;
+ }
+
+ // Validate Status
+ String expectedStatus = expected.status().toString();
+ String actualStatus = actual.status().toString();
+ if (expectedStatus.equals(actualStatus)) {
+ System.out.println("✅ Status matches: " + expectedStatus);
+ } else {
+ System.out.println(
+ "❌ Status mismatch: " + expectedLabel + "=" + expectedStatus + ", " + actualLabel + "="
+ + actualStatus);
+ allPassed = false;
+ }
+
+ // Validate Model
+ String expectedModel = expected.model().orElse("N/A");
+ String actualModel = actual.model().orElse("N/A");
+ if (expectedModel.equals(actualModel)) {
+ System.out.println("✅ Model matches: " + expectedModel);
+ } else {
+ System.out.println(
+ "❌ Model mismatch: " + expectedLabel + "=" + expectedModel + ", " + actualLabel + "="
+ + actualModel);
+ allPassed = false;
+ }
+
+ // Summary
+ System.out.println();
+ if (allPassed) {
+ System.out.println("✅ ALL VALIDATIONS PASSED");
+ } else {
+ System.out.println("❌ SOME VALIDATIONS FAILED");
+ }
+ }
+
+ private static void saveResponse(String filename, String content) {
+ String timestamp = LocalDateTime.now().format(TIMESTAMP_FORMAT);
+ System.out.println("📝 Response saved to: interaction_lifecycle_logs/" + filename);
+ System.out.println(" Timestamp: " + timestamp);
+ // In a real implementation, you would write to file here
+ // For now, just log that we would save it
+ }
+
+ private InteractionsMultipleToolsLifecycle() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsPreviousInteractionId.java b/examples/src/main/java/com/google/genai/examples/InteractionsPreviousInteractionId.java
new file mode 100644
index 00000000000..984c7ccb237
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsPreviousInteractionId.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.Usage;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.TextContent;
+
+/**
+ * Example: Conversation Continuity with previousInteractionId
+ *
+ * Demonstrates how to link interactions using previousInteractionId to maintain conversation
+ * context across separate API calls. This example verifies context is preserved by asking for
+ * 10 random numbers, then asking the model to perform various math operations on them:
+ * addition, multiplication, and calculating mean/median/mode.
+ *
+ *
To run this example:
+ *
+ *
+ * Set the GOOGLE_API_KEY environment variable: {@code export GOOGLE_API_KEY=YOUR_API_KEY}
+ * Compile the examples: {@code mvn clean compile}
+ * Run: {@code mvn exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionsPreviousInteractionId"}
+ *
+ *
+ * Note: The Interactions API is currently in beta.
+ */
+public final class InteractionsPreviousInteractionId {
+
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: Previous Interaction ID Example ===\n");
+
+ try {
+ // ===== First Interaction =====
+ System.out.println("--- First Interaction ---\n");
+
+ CreateInteractionConfig config1 =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input("Give me 10 random numbers less than 50.")
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config1.toJson());
+ System.out.println();
+
+ Interaction response1 = client.interactions.create(config1);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response1.toJson());
+ System.out.println();
+
+ printResults(response1);
+
+ // ===== Second Interaction (linked to first) =====
+ System.out.println("\n--- Second Interaction (linked) ---\n");
+
+ CreateInteractionConfig config2 =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input("Add all the numbers you just gave me.")
+ .previousInteractionId(response1.id())
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config2.toJson());
+ System.out.println();
+
+ Interaction response2 = client.interactions.create(config2);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response2.toJson());
+ System.out.println();
+
+ printResults(response2);
+
+ // ===== Third Interaction (linked to second) =====
+ System.out.println("\n--- Third Interaction (linked) ---\n");
+
+ CreateInteractionConfig config3 =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input("Now multiply all those original numbers together.")
+ .previousInteractionId(response2.id())
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config3.toJson());
+ System.out.println();
+
+ Interaction response3 = client.interactions.create(config3);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response3.toJson());
+ System.out.println();
+
+ printResults(response3);
+
+ // ===== Fourth Interaction (linked to third) =====
+ System.out.println("\n--- Fourth Interaction (linked) ---\n");
+
+ CreateInteractionConfig config4 =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input("which number is the greatest ? .")
+ .previousInteractionId(response3.id())
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config4.toJson());
+ System.out.println();
+
+ Interaction response4 = client.interactions.create(config4);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response4.toJson());
+ System.out.println();
+
+ printResults(response4);
+
+ System.out.println("\n=== Example completed ===");
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+ if (interaction.previousInteractionId().isPresent()) {
+ System.out.println(
+ " Previous Interaction ID: " + interaction.previousInteractionId().get());
+ }
+
+ if (interaction.outputs().isPresent() && !interaction.outputs().get().isEmpty()) {
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ System.out.println(" Text: " + ((TextContent) output).text().orElse("(empty)"));
+ } else {
+ System.out.println(" " + output.getClass().getSimpleName());
+ }
+ }
+ }
+
+ if (interaction.usage().isPresent()) {
+ Usage usage = interaction.usage().get();
+ System.out.println(" Usage:");
+ System.out.println(" Input tokens: " + usage.totalInputTokens().orElse(0));
+ System.out.println(" Output tokens: " + usage.totalOutputTokens().orElse(0));
+ System.out.println(" Total tokens: " + usage.totalTokens().orElse(0));
+ }
+ }
+
+ private InteractionsPreviousInteractionId() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsTextAnnotations.java b/examples/src/main/java/com/google/genai/examples/InteractionsTextAnnotations.java
new file mode 100644
index 00000000000..cd9f0bf743b
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsTextAnnotations.java
@@ -0,0 +1,204 @@
+/*
+ * Copyright 2025 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:
+ *
+ *
Note: The Interactions API is currently only available via the Gemini Developer API (not
+ * Vertex AI).
+ *
+ *
1. Set an API key environment variable:
+ *
+ *
export GOOGLE_API_KEY=YOUR_API_KEY
+ *
+ *
2. Compile and run:
+ *
+ *
mvn clean compile
+ *
+ *
mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsTextAnnotations"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.Annotation;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.TextContent;
+import java.util.List;
+
+/**
+ * TextContent Annotations Testing Example
+ *
+ *
This example demonstrates testing for the annotations field in TextContent responses
+ * from the Interactions API. The annotations field provides citation information for
+ * model-generated content.
+ *
+ *
Structure: TextContent contains:
+ * - type: "text"
+ * - text: The actual text content
+ * - annotations: Optional array of Annotation objects for citations
+ *
+ *
Each Annotation contains:
+ * - start_index: Start byte position of cited segment
+ * - end_index: End byte position of cited segment (exclusive)
+ * - source: Source reference (URL, title, etc.)
+ *
+ *
This example tests various prompts to see if the API returns annotations.
+ *
+ *
Note: The Interactions API is in beta and subject to change.
+ */
+public final class InteractionsTextAnnotations {
+
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ System.out.println("=== TextContent Annotations Testing Example ===\n");
+ System.out.println("Testing if the Interactions API returns annotations in TextContent\n");
+
+ // Test Case 1: Simple factual question
+ testAnnotations(
+ client,
+ "Test Case 1: Simple Factual Question",
+ "What is the capital of France?");
+
+ // Test Case 2: Question that might trigger citations
+ testAnnotations(
+ client,
+ "Test Case 2: Request with Explicit Citation Request",
+ "Tell me about climate change and cite your sources.");
+
+ // Test Case 3: Research-oriented question
+ testAnnotations(
+ client,
+ "Test Case 3: Research Question",
+ "What are the latest advancements in quantum computing? Please provide citations.");
+
+ // Test Case 4: Grounding/search request
+ testAnnotations(
+ client,
+ "Test Case 4: Grounding Request",
+ "Search for information about the Paris Agreement and summarize it with citations.");
+
+ System.out.println("\n=== All test cases completed ===");
+ }
+
+ /**
+ * Test helper that makes an API call and checks for annotations in the response.
+ */
+ private static void testAnnotations(Client client, String testName, String prompt) {
+ System.out.println("\n--- " + testName + " ---\n");
+
+ try {
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input(prompt)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ Interaction response = client.interactions.create(config);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ analyzeAnnotations(response);
+
+ } catch (Exception e) {
+ System.err.println("ERROR in " + testName + ":");
+ System.err.println(" Exception: " + e.getClass().getName());
+ System.err.println(" Message: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Analyzes interaction outputs to find and display annotations.
+ */
+ private static void analyzeAnnotations(Interaction interaction) {
+ System.out.println("Results:");
+
+ if (!interaction.outputs().isPresent() || interaction.outputs().get().isEmpty()) {
+ System.out.println(" ❌ No outputs found in response");
+ return;
+ }
+
+ boolean foundAnnotations = false;
+ int textContentCount = 0;
+ int totalAnnotations = 0;
+
+ for (Content content : interaction.outputs().get()) {
+ if (content instanceof TextContent) {
+ textContentCount++;
+ TextContent textContent = (TextContent) content;
+
+ System.out.println("\n TextContent #" + textContentCount + ":");
+ System.out.println(" Text: " + textContent.text().orElse("(empty)"));
+
+ if (textContent.annotations().isPresent() && !textContent.annotations().get().isEmpty()) {
+ foundAnnotations = true;
+ List annotations = textContent.annotations().get();
+ totalAnnotations += annotations.size();
+
+ System.out.println(" ✅ ANNOTATIONS FOUND: " + annotations.size() + " annotation(s)");
+
+ for (int i = 0; i < annotations.size(); i++) {
+ Annotation ann = annotations.get(i);
+ System.out.println("\n Annotation " + (i + 1) + ":");
+ System.out.println(" Start Index: " + ann.startIndex().orElse(null));
+ System.out.println(" End Index: " + ann.endIndex().orElse(null));
+ System.out.println(" Source: " + ann.source().orElse("(none)"));
+
+ // Show the cited text segment if indices are present
+ if (ann.startIndex().isPresent()
+ && ann.endIndex().isPresent()
+ && textContent.text().isPresent()) {
+ String text = textContent.text().get();
+ int start = ann.startIndex().get();
+ int end = ann.endIndex().get();
+ if (start >= 0 && end <= text.length() && start < end) {
+ String citedText = text.substring(start, end);
+ System.out.println(" Cited Text: \"" + citedText + "\"");
+ }
+ }
+ }
+ } else {
+ System.out.println(" ❌ No annotations found in this TextContent");
+ }
+ }
+ }
+
+ System.out.println("\n SUMMARY:");
+ System.out.println(" Total TextContent blocks: " + textContentCount);
+ System.out.println(" Total annotations found: " + totalAnnotations);
+
+ if (foundAnnotations) {
+ System.out.println(" ✅ SUCCESS: The API returned annotations!");
+ } else {
+ System.out.println(" ⚠️ The API did not return annotations for this request.");
+ System.out.println(" This could mean:");
+ System.out.println(" - The model didn't use external sources");
+ System.out.println(" - The annotations feature may not be enabled yet");
+ System.out.println(" - This specific prompt didn't trigger citations");
+ }
+ }
+
+ private InteractionsTextAnnotations() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsThoughtContent.java b/examples/src/main/java/com/google/genai/examples/InteractionsThoughtContent.java
new file mode 100644
index 00000000000..3e25df03dff
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsThoughtContent.java
@@ -0,0 +1,295 @@
+/*
+ * Copyright 2025 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:
+ *
+ * Note: The Interactions API is currently only available via the Gemini Developer API (not
+ * Vertex AI).
+ *
+ *
1. 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
+ *
+ *
mvn exec:java
+ * -Dexec.mainClass="com.google.genai.examples.InteractionsThoughtContent"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.ImageContent;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.TextContent;
+import com.google.genai.types.interactions.content.ThoughtContent;
+import com.google.genai.types.interactions.content.ThoughtSummaryContent;
+import java.util.List;
+
+/**
+ * ThoughtContent Testing Example
+ *
+ *
This example tests the ThoughtContent functionality to understand how the model's internal
+ * reasoning is exposed through the Interactions API.
+ *
+ *
Structure: ThoughtContent contains:
+ * - signature: A cryptographic signature for the thought
+ * - summary: Optional list of Content (TextContent, ImageContent, etc.)
+ *
+ *
The summary field matches Python's structure: Optional[List[Union[TextContent, ImageContent]]]
+ * allowing the model to provide reasoning summaries with both text and visual elements.
+ *
+ *
Test Cases: 1. Simple Math Reasoning - Basic arithmetic with step-by-step thinking 2. Complex
+ * Logic Puzzle - Multi-step reasoning task 3. Reasoning with extended thinking mode
+ *
+ *
Note: The Interactions API is in beta and subject to change.
+ */
+public final class InteractionsThoughtContent {
+
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ System.out.println("=== ThoughtContent Testing Example ===\n");
+ System.out.println("Testing model's internal reasoning (ThoughtContent)\n");
+
+ // Test Case 1: Simple Math Reasoning
+ testSimpleMathReasoning(client);
+
+ // Test Case 2: Complex Logic Puzzle
+ testComplexLogicPuzzle(client);
+
+ // Test Case 3: Extended Thinking Mode
+ testExtendedThinking(client);
+
+ System.out.println("\n=== All tests completed ===");
+ }
+
+ /**
+ * Test Case 1: Simple Math Reasoning
+ *
+ *
Tests if ThoughtContent appears for basic arithmetic reasoning.
+ */
+ private static void testSimpleMathReasoning(Client client) {
+ System.out.println("\n--- Test Case 1: Simple Math Reasoning ---\n");
+
+ String prompt = "Think step by step: What is 15 * 24?";
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder().model("gemini-2.5-flash").input(prompt).build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ try {
+ Interaction response = client.interactions.create(config);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ printResults(response);
+ analyzeContent(response);
+
+ } catch (Exception e) {
+ System.err.println("ERROR in Test Case 1:");
+ System.err.println(" Exception: " + e.getClass().getName());
+ System.err.println(" Message: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Test Case 2: Complex Logic Puzzle
+ *
+ *
Tests ThoughtContent with a more complex reasoning task that requires multiple steps.
+ */
+ private static void testComplexLogicPuzzle(Client client) {
+ System.out.println("\n--- Test Case 2: Complex Logic Puzzle ---\n");
+
+ String prompt =
+ "Solve this logic puzzle step by step:\n"
+ + "Three friends - Alice, Bob, and Carol - each have a different favorite color (red,"
+ + " blue, or green).\n"
+ + "- Alice doesn't like blue\n"
+ + "- Bob's favorite color is not red\n"
+ + "- Carol likes green\n"
+ + "What is each person's favorite color? Show your reasoning.";
+
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder().model("gemini-2.5-flash").input(prompt).build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ try {
+ Interaction response = client.interactions.create(config);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ printResults(response);
+ analyzeContent(response);
+
+ } catch (Exception e) {
+ System.err.println("ERROR in Test Case 2:");
+ System.err.println(" Exception: " + e.getClass().getName());
+ System.err.println(" Message: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Test Case 3: Extended Thinking Mode
+ *
+ *
Tests ThoughtContent with a reasoning-heavy task.
+ */
+ private static void testExtendedThinking(Client client) {
+ System.out.println("\n--- Test Case 3: Extended Thinking Test ---\n");
+
+ String prompt =
+ "Calculate the following and explain your reasoning:\n"
+ + "If a train travels at 60 mph for 2.5 hours, then speeds up to 80 mph for another 1.5"
+ + " hours, how far does it travel in total?";
+
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input(prompt)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ try {
+ Interaction response = client.interactions.create(config);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ printResults(response);
+ analyzeContent(response);
+
+ } catch (Exception e) {
+ System.err.println("ERROR in Test Case 3:");
+ System.err.println(" Exception: " + e.getClass().getName());
+ System.err.println(" Message: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+ }
+
+ /**
+ * Analyzes interaction content to identify and display ThoughtContent.
+ *
+ *
This method: - Iterates through all outputs in the interaction - Identifies ThoughtContent
+ * instances - Displays thought signatures and summaries - Compares actual structure with expected
+ * structure
+ */
+ private static void analyzeContent(Interaction interaction) {
+ System.out.println("CONTENT ANALYSIS:");
+
+ if (!interaction.outputs().isPresent() || interaction.outputs().get().isEmpty()) {
+ System.out.println(" No outputs found in response");
+ return;
+ }
+
+ int thoughtCount = 0;
+ int textCount = 0;
+ int otherCount = 0;
+
+ System.out.println("\n Analyzing " + interaction.outputs().get().size() + " output(s):");
+
+ for (Content content : interaction.outputs().get()) {
+ System.out.println("\n Content Type: " + content.getClass().getSimpleName());
+
+ if (content instanceof ThoughtContent) {
+ thoughtCount++;
+ ThoughtContent thought = (ThoughtContent) content;
+
+ System.out.println(" >>> THOUGHT CONTENT FOUND <<<");
+ System.out.println(" Signature: " + thought.signature().orElse("(none)"));
+
+ if (thought.summary().isPresent()) {
+ List summaryContents = thought.summary().get();
+ System.out.println(" Summary: " + summaryContents.size() + " item(s)");
+
+ for (int i = 0; i < summaryContents.size(); i++) {
+ ThoughtSummaryContent summaryItem = summaryContents.get(i);
+ System.out.println(" Item " + (i + 1) + ": " + summaryItem.getClass().getSimpleName());
+
+ if (summaryItem instanceof TextContent) {
+ String text = ((TextContent) summaryItem).text().orElse("(empty)");
+ String preview = text.length() > 100 ? text.substring(0, 100) + "..." : text;
+ System.out.println(" Text: " + preview);
+ } else if (summaryItem instanceof ImageContent) {
+ System.out.println(" Image: " + ((ImageContent) summaryItem).uri().orElse("(no uri)"));
+ }
+ }
+ } else {
+ System.out.println(" Summary: (none)");
+ }
+
+ System.out.println(" Full ThoughtContent JSON:");
+ System.out.println(" " + thought.toJson());
+
+ } else if (content instanceof TextContent) {
+ textCount++;
+ TextContent text = (TextContent) content;
+ String textValue = text.text().orElse("(empty)");
+ String preview = textValue.length() > 100 ? textValue.substring(0, 100) + "..." : textValue;
+ System.out.println(" Text Preview: " + preview);
+ } else {
+ otherCount++;
+ System.out.println(" Content Class: " + content.getClass().getName());
+ }
+ }
+
+ System.out.println("\n SUMMARY:");
+ System.out.println(" ThoughtContent instances: " + thoughtCount);
+ System.out.println(" TextContent instances: " + textCount);
+ System.out.println(" Other content instances: " + otherCount);
+
+ if (thoughtCount == 0) {
+ System.out.println(
+ "\n NOTE: No ThoughtContent found. This may be expected if the model didn't use"
+ + " internal reasoning for this query.");
+ }
+
+ // Display final text output
+ if (interaction.outputs().isPresent() && !interaction.outputs().get().isEmpty()) {
+ System.out.println("\n FINAL TEXT OUTPUT:");
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ System.out.println(" " + ((TextContent) output).text().orElse("(empty)"));
+ }
+ }
+ }
+ }
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsUrlContext.java b/examples/src/main/java/com/google/genai/examples/InteractionsUrlContext.java
new file mode 100644
index 00000000000..a9f397d5361
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsUrlContext.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2025 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:
+ *
+ * Note: The Interactions API is currently only available via the Gemini Developer API (not
+ * Vertex AI).
+ *
+ *
1. 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
+ *
+ *
mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsUrlContext"
+ */
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.UrlContextResult;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.TextContent;
+import com.google.genai.types.interactions.content.UrlContextCallContent;
+import com.google.genai.types.interactions.content.UrlContextResultContent;
+import com.google.genai.types.interactions.tools.UrlContext;
+import java.util.List;
+
+/**
+ * Example: URL Context Tool with the Interactions API
+ *
+ *
Demonstrates how to use the UrlContext to enable the model to retrieve and use context
+ * from URLs. The model can fetch web pages and use their content to answer questions.
+ *
+ *
Note: The Interactions API is in beta and subject to change.
+ */
+public final class InteractionsUrlContext {
+
+ public static void main(String[] args) {
+ // Instantiate the client. The client gets the API key from the environment variable
+ // `GOOGLE_API_KEY`.
+ //
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: URL Context Tool Example ===\n");
+
+ // ===== STEP 1: Create UrlContext =====
+ System.out.println("STEP 1: Create UrlContext\n");
+
+ UrlContext urlTool = UrlContext.builder().build();
+
+ System.out.println("UrlContext created successfully\n");
+
+ // ===== STEP 2: Create interaction with URL Context enabled =====
+ System.out.println("---\n");
+ System.out.println("STEP 2: Create interaction with URL Context enabled\n");
+
+ String userQuestion =
+ "Please fetch and summarize the content from https://www.wikipedia.org/wiki/Artificial_intelligence";
+ System.out.println("User: " + userQuestion + "\n");
+
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .input(userQuestion)
+ .tools(urlTool)
+ .build();
+
+ // Print the request JSON
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ Interaction response = client.interactions.create(config);
+
+ // Print the response JSON
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ // ===== STEP 3: Extract and display the results =====
+ System.out.println("---\n");
+ System.out.println("STEP 3: Extract and display the results\n");
+
+ System.out.println("Response received. Interaction ID: " + response.id());
+ System.out.println();
+
+ if (response.outputs().isPresent()) {
+ for (Content content : response.outputs().get()) {
+ if (content instanceof TextContent) {
+ System.out.println("Text: " + ((TextContent) content).text().orElse("(empty)"));
+ System.out.println();
+ } else if (content instanceof UrlContextCallContent) {
+ UrlContextCallContent urlCall = (UrlContextCallContent) content;
+ System.out.println("URL Context Call:");
+ System.out.println(" ID: " + urlCall.id());
+ if (urlCall.arguments().isPresent()) {
+ System.out.println(" URLs: " + urlCall.arguments().get().urls().orElse(java.util.List.of()));
+ }
+ System.out.println();
+ } else if (content instanceof UrlContextResultContent) {
+ UrlContextResultContent urlResult = (UrlContextResultContent) content;
+ System.out.println("URL Context Result:");
+ System.out.println(" Call ID: " + urlResult.callId().orElse("N/A"));
+ System.out.println(" Is Error: " + urlResult.isError().orElse(false));
+
+ if (urlResult.result().isPresent()) {
+ List results = urlResult.result().get();
+ System.out.println(" Results: " + results.size() + " found");
+ for (int i = 0; i < results.size(); i++) {
+ UrlContextResult result = results.get(i);
+ System.out.println(" [" + (i + 1) + "] URL: " + result.url().orElse("N/A"));
+ System.out.println(" Status: " + result.status().map(Object::toString).orElse("N/A"));
+ }
+ }
+ System.out.println();
+ }
+ }
+ }
+
+ System.out.println("\n=== Example completed ===");
+ }
+
+ private InteractionsUrlContext() {}
+}
diff --git a/examples/src/main/java/com/google/genai/examples/InteractionsVideoContent.java b/examples/src/main/java/com/google/genai/examples/InteractionsVideoContent.java
new file mode 100644
index 00000000000..e4a5239f353
--- /dev/null
+++ b/examples/src/main/java/com/google/genai/examples/InteractionsVideoContent.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.examples;
+
+import com.google.genai.Client;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.content.TextContent;
+import com.google.genai.types.interactions.content.VideoContent;
+
+/**
+ * Example demonstrating video analysis using VideoContent with the Interactions API.
+ *
+ * This example shows:
+ *
+ * Using VideoContent.fromUri() to analyze a video from a URL
+ *
+ *
+ * Note: Inline base64-encoded video is not shown because video files are typically
+ * large and not suitable for inline embedding.
+ *
+ *
To run this example:
+ *
+ * Set the GOOGLE_API_KEY environment variable: {@code export GOOGLE_API_KEY=YOUR_API_KEY}
+ * Compile the examples: {@code mvn clean compile}
+ * Run: {@code mvn exec:java -Dexec.mainClass="com.google.genai.examples.InteractionsVideoContent"}
+ *
+ *
+ * Note: The Interactions API is currently in beta.
+ */
+public final class InteractionsVideoContent {
+
+ public static void main(String[] args) {
+ Client client = new Client();
+
+ System.out.println("=== Interactions API: Video Content Example ===\n");
+
+ try {
+ // ===== Video from URI =====
+ System.out.println("--- Video from URI ---\n");
+
+ String videoUri = "https://storage.googleapis.com/cloud-samples-data/generative-ai/video/pixel8.mp4";
+ VideoContent videoContent = VideoContent.fromUri(videoUri, "video/mp4");
+ TextContent textPrompt = TextContent.builder()
+ .text("Describe what happens in this video.")
+ .build();
+
+ CreateInteractionConfig config =
+ CreateInteractionConfig.builder()
+ .model("gemini-2.5-flash")
+ .inputFromContents(textPrompt, videoContent)
+ .build();
+
+ System.out.println("=== REQUEST ===");
+ System.out.println(config.toJson());
+ System.out.println();
+
+ Interaction response = client.interactions.create(config);
+
+ System.out.println("=== RESPONSE ===");
+ System.out.println(response.toJson());
+ System.out.println();
+
+ printResults(response);
+
+ System.out.println("\n=== Example completed ===");
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void printResults(Interaction interaction) {
+ System.out.println("Results:");
+ System.out.println(" Interaction ID: " + interaction.id());
+ System.out.println(" Status: " + interaction.status());
+
+ if (interaction.outputs().isPresent() && !interaction.outputs().get().isEmpty()) {
+ for (Content output : interaction.outputs().get()) {
+ if (output instanceof TextContent) {
+ System.out.println(" Text: " + ((TextContent) output).text().orElse("(empty)"));
+ } else {
+ System.out.println(" " + output.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+
+ private InteractionsVideoContent() {}
+}
diff --git a/pom.xml b/pom.xml
index 90a90201ab4..082489f5a2d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -323,6 +323,7 @@
com/google/genai/types/AutoValue_*.class
+ com/google/genai/types/interactions/AutoValue_*.class
diff --git a/src/main/java/com/google/genai/AsyncInteractions.java b/src/main/java/com/google/genai/AsyncInteractions.java
new file mode 100644
index 00000000000..d8af33bb5ac
--- /dev/null
+++ b/src/main/java/com/google/genai/AsyncInteractions.java
@@ -0,0 +1,191 @@
+/*
+ * Copyright 2025 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.
+ */
+
+// Auto-generated code. Do not edit.
+
+package com.google.genai;
+
+import com.google.genai.Common.BuiltRequest;
+import com.google.genai.types.interactions.CancelInteractionConfig;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.DeleteInteractionConfig;
+import com.google.genai.types.interactions.DeleteInteractionResponse;
+import com.google.genai.types.interactions.GetInteractionConfig;
+import com.google.genai.types.interactions.Interaction;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * Provides asynchronous methods for managing interactions. Instantiating this class is not
+ * required. After instantiating a {@link Client}, access methods through
+ * `client.async.interactions.methodName(...)` directly.
+ *
+ * The Interactions API is available in both Vertex AI and Gemini API.
+ *
+ *
Note: The Interactions API is in beta and subject to change.
+ */
+public final class AsyncInteractions {
+ Interactions interactions;
+ ApiClient apiClient;
+
+ public AsyncInteractions(ApiClient apiClient) {
+ this.apiClient = apiClient;
+ this.interactions = new Interactions(apiClient);
+ }
+
+ /**
+ * Asynchronously creates a new interaction with the specified configuration.
+ *
+ *
Either {@code model} or {@code agent} must be specified in the config, but not both.
+ *
+ *
Example usage for model-based interaction:
+ *
+ *
{@code
+ * CreateInteractionConfig config = CreateInteractionConfig.builder()
+ * .model("gemini-2.5-flash")
+ * .input("What is the capital of France?")
+ * .build();
+ * CompletableFuture future = client.async.interactions.create(config);
+ * future.thenAccept(interaction -> {
+ * System.out.println("Response: " + interaction.outputs());
+ * });
+ * }
+ *
+ * Example usage for agent-based interaction:
+ *
+ *
{@code
+ * CreateInteractionConfig config = CreateInteractionConfig.builder()
+ * .agent("deep-research-pro-preview-12-2025")
+ * .input("Research the history of quantum computing")
+ * .build();
+ * CompletableFuture future = client.async.interactions.create(config);
+ * }
+ *
+ * Note: The Interactions API is in beta and subject to change.
+ *
+ * @param config The configuration for creating the interaction
+ * @return A CompletableFuture containing the created Interaction with outputs
+ * @throws IllegalArgumentException if both model and agent are specified, or neither is specified
+ * @throws UnsupportedOperationException if using Vertex AI (not yet supported)
+ */
+ public CompletableFuture create(CreateInteractionConfig config) {
+ BuiltRequest builtRequest = interactions.buildRequestForCreate(config);
+
+ return this.apiClient
+ .asyncRequest("post", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
+ .thenApplyAsync(
+ response -> {
+ try (ApiResponse res = response) {
+ return interactions.processResponseForCreate(res, config);
+ }
+ });
+ }
+
+ /**
+ * Asynchronously retrieves an interaction by its ID.
+ *
+ * Example usage:
+ *
+ *
{@code
+ * GetInteractionConfig config = GetInteractionConfig.builder().build();
+ * CompletableFuture future = client.async.interactions.get("interaction-id-123", config);
+ * future.thenAccept(interaction -> {
+ * System.out.println("Status: " + interaction.status());
+ * });
+ * }
+ *
+ * Note: The Interactions API is in beta and subject to change.
+ *
+ * @param id The ID of the interaction to retrieve
+ * @param config The configuration for the get request (can be null)
+ * @return A CompletableFuture containing the retrieved Interaction
+ */
+ public CompletableFuture get(String id, GetInteractionConfig config) {
+ BuiltRequest builtRequest = interactions.buildRequestForGet(id, config);
+
+ return this.apiClient
+ .asyncRequest("get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
+ .thenApplyAsync(
+ response -> {
+ try (ApiResponse res = response) {
+ return interactions.processResponseForGet(res, config);
+ }
+ });
+ }
+
+ /**
+ * Asynchronously cancels a background interaction that is still in progress.
+ *
+ * Example usage:
+ *
+ *
{@code
+ * CancelInteractionConfig config = CancelInteractionConfig.builder().build();
+ * CompletableFuture future = client.async.interactions.cancel("interaction-id-123", config);
+ * future.thenAccept(cancelled -> {
+ * System.out.println("New status: " + cancelled.status());
+ * });
+ * }
+ *
+ * Note: The Interactions API is in beta and subject to change.
+ *
+ * @param id The ID of the interaction to cancel
+ * @param config The configuration for the cancel request (can be null)
+ * @return A CompletableFuture containing the updated Interaction
+ */
+ public CompletableFuture cancel(String id, CancelInteractionConfig config) {
+ BuiltRequest builtRequest = interactions.buildRequestForCancel(id, config);
+
+ return this.apiClient
+ .asyncRequest("post", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
+ .thenApplyAsync(
+ response -> {
+ try (ApiResponse res = response) {
+ return interactions.processResponseForCancel(res, config);
+ }
+ });
+ }
+
+ /**
+ * Asynchronously deletes an interaction by its ID.
+ *
+ * Example usage:
+ *
+ *
{@code
+ * DeleteInteractionConfig config = DeleteInteractionConfig.builder().build();
+ * CompletableFuture future =
+ * client.async.interactions.delete("interaction-id-123", config);
+ * }
+ *
+ * Note: The Interactions API is in beta and subject to change.
+ *
+ * @param id The ID of the interaction to delete
+ * @param config The configuration for the delete request (can be null)
+ * @return A CompletableFuture containing the delete response
+ */
+ public CompletableFuture delete(
+ String id, DeleteInteractionConfig config) {
+ BuiltRequest builtRequest = interactions.buildRequestForDelete(id, config);
+
+ return this.apiClient
+ .asyncRequest(
+ "delete", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())
+ .thenApplyAsync(
+ response -> {
+ try (ApiResponse res = response) {
+ return interactions.processResponseForDelete(res, config);
+ }
+ });
+ }
+}
diff --git a/src/main/java/com/google/genai/Client.java b/src/main/java/com/google/genai/Client.java
index 0bc250b550b..22772ec2087 100644
--- a/src/main/java/com/google/genai/Client.java
+++ b/src/main/java/com/google/genai/Client.java
@@ -41,6 +41,7 @@ public final class Async {
public final AsyncTokens authTokens;
public final AsyncTunings tunings;
public final AsyncFileSearchStores fileSearchStores;
+ public final AsyncInteractions interactions;
public Async(ApiClient apiClient) {
this.models = new AsyncModels(apiClient);
@@ -53,6 +54,7 @@ public Async(ApiClient apiClient) {
this.authTokens = new AsyncTokens(apiClient);
this.tunings = new AsyncTunings(apiClient);
this.fileSearchStores = new AsyncFileSearchStores(apiClient);
+ this.interactions = new AsyncInteractions(apiClient);
}
}
@@ -68,6 +70,7 @@ public Async(ApiClient apiClient) {
public final Tokens authTokens;
public final Tunings tunings;
public final FileSearchStores fileSearchStores;
+ public final Interactions interactions;
/** Builder for {@link Client}. */
public static class Builder {
@@ -280,6 +283,7 @@ private Client(
authTokens = new Tokens(this.apiClient);
tunings = new Tunings(this.apiClient);
fileSearchStores = new FileSearchStores(this.apiClient);
+ interactions = new Interactions(this.apiClient);
}
/** Returns whether the client is using Vertex AI APIs. */
diff --git a/src/main/java/com/google/genai/DebugConfig.java b/src/main/java/com/google/genai/DebugConfig.java
index fcefa933332..292c2b839dc 100644
--- a/src/main/java/com/google/genai/DebugConfig.java
+++ b/src/main/java/com/google/genai/DebugConfig.java
@@ -16,6 +16,7 @@
package com.google.genai;
+
/** Data class configuration for debugging or testing the Client. */
@ExcludeFromGeneratedCoverageReport
final class DebugConfig {
diff --git a/src/main/java/com/google/genai/Interactions.java b/src/main/java/com/google/genai/Interactions.java
new file mode 100644
index 00000000000..0a1145dd419
--- /dev/null
+++ b/src/main/java/com/google/genai/Interactions.java
@@ -0,0 +1,632 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.genai.Common.BuiltRequest;
+import com.google.genai.errors.GenAiIOException;
+import com.google.genai.types.HttpOptions;
+import com.google.genai.types.HttpResponse;
+import com.google.genai.types.interactions.CancelInteractionConfig;
+import com.google.genai.types.interactions.CancelInteractionParameters;
+import com.google.genai.types.interactions.CreateInteractionConfig;
+import com.google.genai.types.interactions.CreateInteractionParameters;
+import com.google.genai.types.interactions.DeleteInteractionConfig;
+import com.google.genai.types.interactions.DeleteInteractionParameters;
+import com.google.genai.types.interactions.DeleteInteractionResponse;
+import com.google.genai.types.interactions.GetInteractionConfig;
+import com.google.genai.types.interactions.GetInteractionParameters;
+import com.google.genai.types.interactions.Interaction;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import okhttp3.Headers;
+import okhttp3.ResponseBody;
+
+/**
+ * Provides methods for managing interactions. Instantiating this class is not required. After
+ * instantiating a {@link Client}, access methods through `client.interactions.methodName(...)`
+ * directly.
+ *
+ * Note: The Interactions API is in beta and subject to change.
+ */
+public final class Interactions {
+
+ final ApiClient apiClient;
+
+ public Interactions(ApiClient apiClient) {
+ this.apiClient = apiClient;
+ }
+
+ /**
+ * Copies a field from source to target if it exists, without transformation.
+ *
+ * @param fromObject Source JSON node
+ * @param parentObject Target ObjectNode to populate
+ * @param fieldName Name of the field to copy
+ */
+ private void copyFieldIfPresent(JsonNode fromObject, ObjectNode parentObject, String fieldName) {
+ Object value = Common.getValueByPath(fromObject, new String[] {fieldName});
+ if (value != null) {
+ Common.setValueByPath(parentObject, new String[] {fieldName}, value);
+ }
+ }
+
+ /**
+ * Copies a field from source to target with a transformation function.
+ *
+ * @param fromObject Source JSON node
+ * @param parentObject Target ObjectNode to populate
+ * @param fieldName Name of the field to copy
+ * @param transformer Function to transform the value
+ */
+ private void copyFieldWithTransform(
+ JsonNode fromObject,
+ ObjectNode parentObject,
+ String fieldName,
+ java.util.function.Function transformer) {
+ Object value = Common.getValueByPath(fromObject, new String[] {fieldName});
+ if (value != null) {
+ Common.setValueByPath(parentObject, new String[] {fieldName}, transformer.apply(value));
+ }
+ }
+
+ /**
+ * Transforms CreateInteractionConfig to the request body format. This transformation is identical
+ * for both Vertex AI and MLDev platforms. Only the endpoint path differs (handled by
+ * ApiClient.buildMaybeVertexPath).
+ *
+ * @param fromObject Source JSON node containing the config
+ * @param parentObject Target ObjectNode to populate (modified in place)
+ */
+ @ExcludeFromGeneratedCoverageReport
+ void createInteractionConfig(JsonNode fromObject, ObjectNode parentObject) {
+ // Simple fields - no transformation
+ // Note: Field names must match @JsonProperty annotations (snake_case)
+ copyFieldIfPresent(fromObject, parentObject, "input");
+ copyFieldIfPresent(fromObject, parentObject, "agent");
+ copyFieldIfPresent(fromObject, parentObject, "background");
+ copyFieldIfPresent(fromObject, parentObject, "generation_config");
+ copyFieldIfPresent(fromObject, parentObject, "agent_config");
+ copyFieldIfPresent(fromObject, parentObject, "previous_interaction_id");
+ copyFieldIfPresent(fromObject, parentObject, "response_format");
+ copyFieldIfPresent(fromObject, parentObject, "response_mime_type");
+ copyFieldIfPresent(fromObject, parentObject, "response_modalities");
+ copyFieldIfPresent(fromObject, parentObject, "store");
+ // Tool types serialize directly with their type discriminator
+ copyFieldIfPresent(fromObject, parentObject, "tools");
+
+ // Fields with transformation
+ // Note: Interactions API expects raw model string, not transformed
+ copyFieldIfPresent(fromObject, parentObject, "model");
+ copyFieldWithTransform(
+ fromObject,
+ parentObject,
+ "system_instruction",
+ value -> JsonSerializable.toJsonNode(Transformers.tContent(value)));
+ }
+
+ /**
+ * Transforms CreateInteractionParameters to the request body. Platform-agnostic - works for both
+ * Vertex AI and MLDev.
+ *
+ * @param fromObject Source JSON node containing the parameters
+ * @return Transformed ObjectNode ready for the request body
+ */
+ @ExcludeFromGeneratedCoverageReport
+ ObjectNode createInteractionParameters(JsonNode fromObject) {
+ ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
+
+ if (Common.getValueByPath(fromObject, new String[] {"config"}) != null) {
+ createInteractionConfig(
+ JsonSerializable.toJsonNode(Common.getValueByPath(fromObject, new String[] {"config"})),
+ toObject);
+ }
+
+ return toObject;
+ }
+
+ /** A shared buildRequest method for both sync and async methods. */
+ BuiltRequest buildRequestForCreate(CreateInteractionConfig config) {
+ // Validation: exactly one of model or agent must be specified
+ boolean hasModel = config.model().isPresent() && !config.model().get().isEmpty();
+ boolean hasAgent = config.agent().isPresent() && !config.agent().get().isEmpty();
+
+ if (hasModel && hasAgent) {
+ throw new IllegalArgumentException(
+ "Cannot specify both 'model' and 'agent'. Please provide only one.");
+ }
+
+ if (!hasModel && !hasAgent) {
+ throw new IllegalArgumentException(
+ "Must specify either 'model' or 'agent' in CreateInteractionConfig.");
+ }
+
+ // Validation: agentConfig only with agent, generationConfig only with model
+ if (hasAgent && config.generationConfig().isPresent()) {
+ throw new IllegalArgumentException(
+ "Cannot use 'generationConfig' with agent-based interactions. "
+ + "Use 'agentConfig' instead.");
+ }
+
+ if (hasModel && config.agentConfig().isPresent()) {
+ throw new IllegalArgumentException(
+ "Cannot use 'agentConfig' with model-based interactions. "
+ + "Use 'generationConfig' instead.");
+ }
+
+ CreateInteractionParameters.Builder parameterBuilder = CreateInteractionParameters.builder();
+
+ if (!Common.isZero(config)) {
+ parameterBuilder.config(config);
+ }
+ JsonNode parameterNode = JsonSerializable.toJsonNode(parameterBuilder.build());
+
+ ObjectNode body = createInteractionParameters(parameterNode);
+ String path = "interactions";
+
+ // The "_query" key is used internally to store query parameters
+ // that will be appended to the URL
+ JsonNode queryParams = body.get("_query");
+ if (queryParams != null) {
+ body.remove("_query");
+ path = String.format("%s?%s", path, Common.urlEncode((ObjectNode) queryParams));
+ }
+
+ Optional requestHttpOptions = Optional.empty();
+ if (config != null) {
+ requestHttpOptions = config.httpOptions();
+ }
+
+ String requestBody = JsonSerializable.toJsonString(body);
+ return new BuiltRequest(path, requestBody, requestHttpOptions);
+ }
+
+ /** A shared processResponse function for both sync and async methods. */
+ Interaction processResponseForCreate(ApiResponse response, CreateInteractionConfig config) {
+ ResponseBody responseBody = response.getBody();
+ String responseString;
+ try {
+ responseString = responseBody.string();
+ } catch (IOException e) {
+ throw new GenAiIOException("Failed to read HTTP response.", e);
+ }
+
+ JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString);
+
+ Interaction sdkResponse = JsonSerializable.fromJsonNode(responseNode, Interaction.class);
+ Headers responseHeaders = response.getHeaders();
+ if (responseHeaders == null) {
+ return sdkResponse;
+ }
+ Map headers = new HashMap<>();
+ for (String headerName : responseHeaders.names()) {
+ headers.put(headerName, responseHeaders.get(headerName));
+ }
+ return sdkResponse.toBuilder().sdkHttpResponse(HttpResponse.builder().headers(headers)).build();
+ }
+
+ /** A shared buildRequest method for both sync and async methods. */
+ BuiltRequest buildRequestForGet(String id, GetInteractionConfig config) {
+
+ // Validation: id must be non-empty
+ if (id == null || id.isEmpty()) {
+ throw new IllegalArgumentException("Interaction ID must not be empty");
+ }
+
+ GetInteractionParameters.Builder parameterBuilder = GetInteractionParameters.builder();
+
+ if (!Common.isZero(id)) {
+ parameterBuilder.id(id);
+ }
+ if (!Common.isZero(config)) {
+ parameterBuilder.config(config);
+ }
+ JsonNode parameterNode = JsonSerializable.toJsonNode(parameterBuilder.build());
+
+ // Transform ID parameter into URL placeholder using special "_url" key
+ // The "_url" key is used internally to store URL path parameters
+ ObjectNode body = transformIdParameter(parameterNode);
+
+ String path = body.get("_url") != null ? Common.formatMap("{id}", body.get("_url")) : "{id}";
+ body.remove("_url");
+
+ // The "_query" key is used internally to store query parameters
+ // that will be appended to the URL
+ JsonNode queryParams = body.get("_query");
+ if (queryParams != null) {
+ body.remove("_query");
+ path = String.format("%s?%s", path, Common.urlEncode((ObjectNode) queryParams));
+ }
+
+ Optional requestHttpOptions = Optional.empty();
+ if (config != null) {
+ requestHttpOptions = config.httpOptions();
+ }
+
+ return new BuiltRequest(path, JsonSerializable.toJsonString(body), requestHttpOptions);
+ }
+
+ /** A shared processResponse function for both sync and async methods. */
+ Interaction processResponseForGet(ApiResponse response, GetInteractionConfig config) {
+ ResponseBody responseBody = response.getBody();
+ String responseString;
+ try {
+ responseString = responseBody.string();
+ } catch (IOException e) {
+ throw new GenAiIOException("Failed to read HTTP response.", e);
+ }
+
+ JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString);
+
+ Interaction sdkResponse = JsonSerializable.fromJsonNode(responseNode, Interaction.class);
+ Headers responseHeaders = response.getHeaders();
+ if (responseHeaders == null) {
+ return sdkResponse;
+ }
+ Map headers = new HashMap<>();
+ for (String headerName : responseHeaders.names()) {
+ headers.put(headerName, responseHeaders.get(headerName));
+ }
+ return sdkResponse.toBuilder().sdkHttpResponse(HttpResponse.builder().headers(headers)).build();
+ }
+
+ /** A shared buildRequest method for both sync and async methods. */
+ BuiltRequest buildRequestForCancel(String id, CancelInteractionConfig config) {
+
+ // Validation: id must be non-empty
+ if (id == null || id.isEmpty()) {
+ throw new IllegalArgumentException("Interaction ID must not be empty");
+ }
+
+ CancelInteractionParameters.Builder parameterBuilder = CancelInteractionParameters.builder();
+
+ if (!Common.isZero(id)) {
+ parameterBuilder.id(id);
+ }
+ if (!Common.isZero(config)) {
+ parameterBuilder.config(config);
+ }
+ JsonNode parameterNode = JsonSerializable.toJsonNode(parameterBuilder.build());
+
+ // Transform ID parameter into URL placeholder using special "_url" key
+ // The "_url" key is used internally to store URL path parameters
+ ObjectNode body = transformIdParameter(parameterNode);
+
+ // Cancel uses POST to /interactions/{id}/cancel
+ String path =
+ body.get("_url") != null
+ ? Common.formatMap("{id}/cancel", body.get("_url"))
+ : "{id}/cancel";
+ body.remove("_url");
+
+ // The "_query" key is used internally to store query parameters
+ // that will be appended to the URL
+ JsonNode queryParams = body.get("_query");
+ if (queryParams != null) {
+ body.remove("_query");
+ path = String.format("%s?%s", path, Common.urlEncode((ObjectNode) queryParams));
+ }
+
+ Optional requestHttpOptions = Optional.empty();
+ if (config != null) {
+ requestHttpOptions = config.httpOptions();
+ }
+
+ return new BuiltRequest(path, JsonSerializable.toJsonString(body), requestHttpOptions);
+ }
+
+ /** A shared processResponse function for both sync and async methods. */
+ Interaction processResponseForCancel(ApiResponse response, CancelInteractionConfig config) {
+ ResponseBody responseBody = response.getBody();
+ String responseString;
+ try {
+ responseString = responseBody.string();
+ } catch (IOException e) {
+ throw new GenAiIOException("Failed to read HTTP response.", e);
+ }
+
+ JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString);
+
+ Interaction sdkResponse = JsonSerializable.fromJsonNode(responseNode, Interaction.class);
+ Headers responseHeaders = response.getHeaders();
+ if (responseHeaders == null) {
+ return sdkResponse;
+ }
+ Map headers = new HashMap<>();
+ for (String headerName : responseHeaders.names()) {
+ headers.put(headerName, responseHeaders.get(headerName));
+ }
+ return sdkResponse.toBuilder().sdkHttpResponse(HttpResponse.builder().headers(headers)).build();
+ }
+
+ /**
+ * Shared transformer for interaction ID parameters (used by GET, CANCEL, DELETE operations).
+ * Transforms the "id" field from the input into a URL parameter.
+ *
+ * @param fromObject Source JSON node containing the ID
+ * @return Transformed ObjectNode with ID in _url.id path
+ */
+ @ExcludeFromGeneratedCoverageReport
+ private ObjectNode transformIdParameter(JsonNode fromObject) {
+ ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
+
+ if (Common.getValueByPath(fromObject, new String[] {"id"}) != null) {
+ Common.setValueByPath(
+ toObject,
+ new String[] {"_url", "id"},
+ Transformers.tInteractionId(
+ this.apiClient, Common.getValueByPath(fromObject, new String[] {"id"})));
+ }
+
+ return toObject;
+ }
+
+ /**
+ * Shared transformer for delete interaction responses. Extracts sdkHttpResponse from the API
+ * response.
+ *
+ * @param fromObject Source JSON node from the API response
+ * @return Transformed ObjectNode with sdkHttpResponse field
+ */
+ @ExcludeFromGeneratedCoverageReport
+ private ObjectNode transformDeleteInteractionResponse(JsonNode fromObject) {
+ ObjectNode toObject = JsonSerializable.objectMapper().createObjectNode();
+
+ if (Common.getValueByPath(fromObject, new String[] {"sdkHttpResponse"}) != null) {
+ Common.setValueByPath(
+ toObject,
+ new String[] {"sdkHttpResponse"},
+ Common.getValueByPath(fromObject, new String[] {"sdkHttpResponse"}));
+ }
+
+ return toObject;
+ }
+
+ /** A shared buildRequest method for both sync and async methods. */
+ BuiltRequest buildRequestForDelete(String id, DeleteInteractionConfig config) {
+
+ // Validation: id must be non-empty
+ if (id == null || id.isEmpty()) {
+ throw new IllegalArgumentException("Interaction ID must not be empty");
+ }
+
+ DeleteInteractionParameters.Builder parameterBuilder = DeleteInteractionParameters.builder();
+
+ if (!Common.isZero(id)) {
+ parameterBuilder.id(id);
+ }
+ if (!Common.isZero(config)) {
+ parameterBuilder.config(config);
+ }
+ JsonNode parameterNode = JsonSerializable.toJsonNode(parameterBuilder.build());
+
+ // Transform ID parameter into URL placeholder using special "_url" key
+ // The "_url" key is used internally to store URL path parameters
+ ObjectNode body = transformIdParameter(parameterNode);
+
+ String path = body.get("_url") != null ? Common.formatMap("{id}", body.get("_url")) : "{id}";
+ body.remove("_url");
+
+ // The "_query" key is used internally to store query parameters
+ // that will be appended to the URL
+ JsonNode queryParams = body.get("_query");
+ if (queryParams != null) {
+ body.remove("_query");
+ path = String.format("%s?%s", path, Common.urlEncode((ObjectNode) queryParams));
+ }
+
+ Optional requestHttpOptions = Optional.empty();
+ if (config != null) {
+ requestHttpOptions = config.httpOptions();
+ }
+
+ return new BuiltRequest(path, JsonSerializable.toJsonString(body), requestHttpOptions);
+ }
+
+ /** A shared processResponse function for both sync and async methods. */
+ DeleteInteractionResponse processResponseForDelete(
+ ApiResponse response, DeleteInteractionConfig config) {
+ ResponseBody responseBody = response.getBody();
+ String responseString;
+ try {
+ responseString = responseBody.string();
+ } catch (IOException e) {
+ throw new GenAiIOException("Failed to read HTTP response.", e);
+ }
+
+ JsonNode responseNode = JsonSerializable.stringToJsonNode(responseString);
+
+ // Transform response - identical for both platforms
+ responseNode = transformDeleteInteractionResponse(responseNode);
+
+ DeleteInteractionResponse sdkResponse =
+ JsonSerializable.fromJsonNode(responseNode, DeleteInteractionResponse.class);
+ Headers responseHeaders = response.getHeaders();
+ if (responseHeaders == null) {
+ return sdkResponse;
+ }
+ Map headers = new HashMap<>();
+ for (String headerName : responseHeaders.names()) {
+ headers.put(headerName, responseHeaders.get(headerName));
+ }
+ return sdkResponse.toBuilder().sdkHttpResponse(HttpResponse.builder().headers(headers)).build();
+ }
+
+ /**
+ * Creates a new interaction with the specified configuration.
+ *
+ * Either {@code model} or {@code agent} must be specified in the config, but not both.
+ *
+ *
When using function calling tools, the application must handle the function execution loop
+ * manually. If the interaction returns {@code status: "requires_action"}, extract the function
+ * calls from the outputs, execute them, and create a new interaction with the results using
+ * {@code previousInteractionId}.
+ *
+ *
Example usage for model-based interaction:
+ *
+ *
{@code
+ * CreateInteractionConfig config = CreateInteractionConfig.builder()
+ * .model("gemini-2.5-flash")
+ * .input("What is the capital of France?")
+ * .build();
+ * Interaction response = client.interactions.create(config);
+ * }
+ *
+ * Example usage for agent-based interaction:
+ *
+ *
{@code
+ * CreateInteractionConfig config = CreateInteractionConfig.builder()
+ * .agent("deep-research-pro-preview-12-2025")
+ * .input("Research the history of quantum computing")
+ * .build();
+ * Interaction response = client.interactions.create(config);
+ * }
+ *
+ * Example usage with manual function calling:
+ *
+ *
{@code
+ * CreateInteractionConfig config = CreateInteractionConfig.builder()
+ * .model("gemini-2.5-flash")
+ * .input("What's the weather in Paris?")
+ * .tools(Function.of("getWeather", "Gets weather for a city", schema))
+ * .build();
+ *
+ * Interaction interaction = client.interactions.create(config);
+ *
+ * // Manual loop for function calling
+ * while ("requires_action".equals(interaction.status().toString())) {
+ * // Extract and execute functions manually
+ * List results = executeFunctions(interaction);
+ *
+ * // Continue conversation with results
+ * interaction = client.interactions.create(
+ * config.toBuilder()
+ * .previousInteractionId(interaction.id())
+ * .inputFromContents(results)
+ * .build()
+ * );
+ * }
+ * }
+ *
+ * Note: The Interactions API is in beta and subject to change.
+ *
+ * @param config The configuration for creating the interaction
+ * @return The created Interaction with outputs
+ * @throws IllegalArgumentException if both model and agent are specified, or neither is specified
+ * @throws GenAiIOException if the API request fails
+ */
+ public Interaction create(CreateInteractionConfig config) {
+ BuiltRequest builtRequest = buildRequestForCreate(config);
+
+ try (ApiResponse response =
+ this.apiClient.request(
+ "post", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())) {
+ return processResponseForCreate(response, config);
+ }
+ }
+
+ /**
+ * Retrieves an interaction by its ID.
+ *
+ *
Example usage:
+ *
+ *
{@code
+ * GetInteractionConfig config = GetInteractionConfig.builder().build();
+ * Interaction interaction = client.interactions.get("interaction-id-123", config);
+ * System.out.println("Status: " + interaction.status());
+ * }
+ *
+ * Note: The Interactions API is in beta and subject to change.
+ *
+ * @param id The ID of the interaction to retrieve
+ * @param config The configuration for the get request (can be null)
+ * @return The retrieved Interaction
+ * @throws IllegalArgumentException if the ID is empty
+ * @throws GenAiIOException if the API request fails
+ */
+ public Interaction get(String id, GetInteractionConfig config) {
+ BuiltRequest builtRequest = buildRequestForGet(id, config);
+
+ try (ApiResponse response =
+ this.apiClient.request(
+ "get", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())) {
+ return processResponseForGet(response, config);
+ }
+ }
+
+ /**
+ * Cancels a background interaction that is still in progress.
+ *
+ *
Only applies to interactions created with background=true that are in IN_PROGRESS status.
+ *
+ *
Example usage:
+ *
+ *
{@code
+ * CancelInteractionConfig config = CancelInteractionConfig.builder().build();
+ * Interaction cancelled = client.interactions.cancel("interaction-id-123", config);
+ * System.out.println("New status: " + cancelled.status()); // Should be CANCELLED
+ * }
+ *
+ * Note: The Interactions API is in beta and subject to change.
+ *
+ * @param id The ID of the interaction to cancel
+ * @param config The configuration for the cancel request (can be null)
+ * @return The updated Interaction with CANCELLED status
+ * @throws IllegalArgumentException if the ID is empty
+ * @throws GenAiIOException if the API request fails
+ */
+ public Interaction cancel(String id, CancelInteractionConfig config) {
+ BuiltRequest builtRequest = buildRequestForCancel(id, config);
+
+ try (ApiResponse response =
+ this.apiClient.request(
+ "post", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())) {
+ return processResponseForCancel(response, config);
+ }
+ }
+
+ /**
+ * Deletes an interaction by its ID.
+ *
+ *
Example usage:
+ *
+ *
{@code
+ * DeleteInteractionConfig config = DeleteInteractionConfig.builder().build();
+ * DeleteInteractionResponse response = client.interactions.delete("interaction-id-123", config);
+ * }
+ *
+ * Note: The Interactions API is in beta and subject to change.
+ *
+ * @param id The ID of the interaction to delete
+ * @param config The configuration for the delete request (can be null)
+ * @return The delete response with HTTP headers
+ * @throws IllegalArgumentException if the ID is empty
+ * @throws GenAiIOException if the API request fails
+ */
+ public DeleteInteractionResponse delete(String id, DeleteInteractionConfig config) {
+ BuiltRequest builtRequest = buildRequestForDelete(id, config);
+
+ try (ApiResponse response =
+ this.apiClient.request(
+ "delete", builtRequest.path(), builtRequest.body(), builtRequest.httpOptions())) {
+ return processResponseForDelete(response, config);
+ }
+ }
+}
diff --git a/src/main/java/com/google/genai/Transformers.java b/src/main/java/com/google/genai/Transformers.java
index 65eab1ed837..8d1f10f03c7 100644
--- a/src/main/java/com/google/genai/Transformers.java
+++ b/src/main/java/com/google/genai/Transformers.java
@@ -409,6 +409,21 @@ public static String tCachedContentName(ApiClient apiClient, Object origin) {
"Unsupported cached content name type: " + origin.getClass());
}
+ /** Transforms an object to an interaction ID for the API. */
+ public static String tInteractionId(ApiClient apiClient, Object origin) {
+ if (origin == null) {
+ return null;
+ } else if (origin instanceof String) {
+ return getResourceName(apiClient, (String) origin, "interactions");
+ } else if (origin instanceof JsonNode) {
+ String interactionId = JsonSerializable.toJsonString((JsonNode) origin);
+ interactionId = interactionId.replace("\"", "");
+ return getResourceName(apiClient, interactionId, "interactions");
+ }
+ throw new IllegalArgumentException(
+ "Unsupported interaction ID type: " + origin.getClass());
+ }
+
/** Transforms an object to a list of Content for the embedding API. */
@SuppressWarnings("unchecked")
public static @Nullable List tContentsForEmbed(ApiClient apiClient, Object origin) {
diff --git a/src/main/java/com/google/genai/errors/ExcludeFromGeneratedCoverageReport.java b/src/main/java/com/google/genai/errors/ExcludeFromGeneratedCoverageReport.java
index c7e60717c3d..ab99c3092f6 100644
--- a/src/main/java/com/google/genai/errors/ExcludeFromGeneratedCoverageReport.java
+++ b/src/main/java/com/google/genai/errors/ExcludeFromGeneratedCoverageReport.java
@@ -28,4 +28,4 @@
*/
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
-@interface ExcludeFromGeneratedCoverageReport {}
\ No newline at end of file
+@interface ExcludeFromGeneratedCoverageReport {}
diff --git a/src/main/java/com/google/genai/types/ExcludeFromGeneratedCoverageReport.java b/src/main/java/com/google/genai/types/ExcludeFromGeneratedCoverageReport.java
index 73d98f6f869..43981930475 100644
--- a/src/main/java/com/google/genai/types/ExcludeFromGeneratedCoverageReport.java
+++ b/src/main/java/com/google/genai/types/ExcludeFromGeneratedCoverageReport.java
@@ -28,4 +28,4 @@
*/
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
-@interface ExcludeFromGeneratedCoverageReport {}
+public @interface ExcludeFromGeneratedCoverageReport {}
diff --git a/src/main/java/com/google/genai/types/ThinkingLevel.java b/src/main/java/com/google/genai/types/ThinkingLevel.java
index 5985dc0d52c..865a796eb01 100644
--- a/src/main/java/com/google/genai/types/ThinkingLevel.java
+++ b/src/main/java/com/google/genai/types/ThinkingLevel.java
@@ -23,30 +23,102 @@
import com.google.common.base.Ascii;
import java.util.Objects;
-/** The number of thoughts tokens that the model should generate. */
+/**
+ * Controls the depth and extent of the model's reasoning process.
+ *
+ * The thinking level determines how many internal reasoning tokens the model should generate
+ * before producing its final response. Higher thinking levels allow the model to engage in more
+ * thorough analysis, exploration of alternative approaches, and step-by-step reasoning, which can
+ * lead to more accurate and well-reasoned responses for complex tasks.
+ *
+ *
This class is shared across multiple APIs (Interactions API, etc.) and follows the standard
+ * enum wrapper pattern used throughout the codebase. The {@code Known} enum contains all
+ * recognized values from the OpenAPI specification, and {@code THINKING_LEVEL_UNSPECIFIED} serves
+ * as a fallback for forward compatibility.
+ *
+ *
Example usage:
+ *
+ *
{@code
+ * // For simple tasks, use minimal thinking
+ * ThinkingLevel level = new ThinkingLevel(ThinkingLevel.Known.MINIMAL);
+ *
+ * // For complex reasoning tasks, use high thinking
+ * ThinkingLevel level = new ThinkingLevel(ThinkingLevel.Known.HIGH);
+ *
+ * // Include in generation config
+ * GenerationConfig config = GenerationConfig.builder()
+ * .thinkingLevel(new ThinkingLevel(ThinkingLevel.Known.MEDIUM))
+ * .build();
+ * }
+ */
public class ThinkingLevel {
- /** Enum representing the known values for ThinkingLevel. */
+ /**
+ * Enum representing the known values for ThinkingLevel.
+ *
+ * These values control the amount of internal reasoning the model performs before generating
+ * its response.
+ */
public enum Known {
- /** Unspecified thinking level. */
+ /**
+ * Unspecified thinking level.
+ *
+ *
This is the fallback value used when the API returns an unknown thinking level not
+ * recognized by this version of the SDK. This ensures forward compatibility when new thinking
+ * levels are added to the API.
+ */
THINKING_LEVEL_UNSPECIFIED,
- /** Low thinking level. */
+ /**
+ * Low thinking level.
+ *
+ *
The model performs a limited amount of internal reasoning. Use this for tasks that
+ * benefit from some deliberation but don't require extensive analysis. Generates fewer
+ * thinking tokens than MEDIUM or HIGH.
+ */
LOW,
- /** Medium thinking level. */
+ /**
+ * Medium thinking level.
+ *
+ *
The model performs a moderate amount of internal reasoning. This is a balanced option
+ * suitable for tasks of average complexity that benefit from careful consideration. Generates
+ * more thinking tokens than LOW but fewer than HIGH.
+ */
MEDIUM,
- /** High thinking level. */
+ /**
+ * High thinking level.
+ *
+ *
The model performs extensive internal reasoning. Use this for complex tasks that require
+ * deep analysis, multi-step reasoning, or exploration of multiple approaches. Generates the
+ * most thinking tokens, which may increase latency but can significantly improve response
+ * quality for challenging problems.
+ */
HIGH,
- /** MINIMAL thinking level. */
+ /**
+ * Minimal thinking level.
+ *
+ *
The model performs the least amount of internal reasoning. Use this for simple,
+ * straightforward tasks where immediate responses are preferred and extensive deliberation
+ * would not improve the output quality. Generates the fewest thinking tokens.
+ */
MINIMAL
}
private Known thinkingLevelEnum;
private final String value;
+ /**
+ * Creates a ThinkingLevel from a string value.
+ *
+ *
This constructor is used by Jackson during JSON deserialization. It attempts to match the
+ * provided string value to a known enum value (case-insensitive). If no match is found, it falls
+ * back to {@code THINKING_LEVEL_UNSPECIFIED}.
+ *
+ * @param value the string representation of the thinking level
+ */
@JsonCreator
public ThinkingLevel(String value) {
this.value = value;
@@ -61,6 +133,14 @@ public ThinkingLevel(String value) {
}
}
+ /**
+ * Creates a ThinkingLevel from a known enum value.
+ *
+ *
This is the recommended constructor for creating ThinkingLevel instances in application
+ * code.
+ *
+ * @param knownValue the known thinking level enum value
+ */
public ThinkingLevel(Known knownValue) {
this.thinkingLevelEnum = knownValue;
this.value = knownValue.toString();
@@ -110,6 +190,14 @@ public int hashCode() {
}
}
+ /**
+ * Returns the known enum value for this thinking level.
+ *
+ *
If the value was not recognized during deserialization, this will return {@code
+ * THINKING_LEVEL_UNSPECIFIED}.
+ *
+ * @return the known enum value
+ */
@ExcludeFromGeneratedCoverageReport
public Known knownEnum() {
return this.thinkingLevelEnum;
diff --git a/src/main/java/com/google/genai/types/Turn.java b/src/main/java/com/google/genai/types/Turn.java
new file mode 100644
index 00000000000..287422365d0
--- /dev/null
+++ b/src/main/java/com/google/genai/types/Turn.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2025 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.
+ */
+
+// Auto-generated code. Do not edit.
+
+package com.google.genai.types;
+
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+
+/** Represents a conversation turn with role and content. */
+@AutoValue
+@JsonDeserialize(builder = Turn.Builder.class)
+public abstract class Turn extends JsonSerializable {
+ /** The content of the turn. Can be a string or list of Content objects. */
+ @JsonProperty("content")
+ public abstract Optional> content();
+
+ /** Optional. The role in the conversation ('user' or 'model'). */
+ @JsonProperty("role")
+ public abstract Optional role();
+
+ /** Instantiates a builder for Turn. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_Turn.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for Turn. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /** For internal usage. Please use `Turn.builder()` for instantiation. */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_Turn.Builder();
+ }
+
+ /**
+ * Setter for content.
+ *
+ * content: The content of the turn as a list of Content objects.
+ */
+ @JsonProperty("content")
+ public abstract Builder content(List content);
+
+ /**
+ * Setter for content (varargs convenience method).
+ *
+ * content: The content of the turn.
+ */
+ @CanIgnoreReturnValue
+ public Builder content(Content... content) {
+ return content(Arrays.asList(content));
+ }
+
+ /**
+ * Setter for content builder (varargs convenience method).
+ *
+ *
content: The content of the turn.
+ */
+ @CanIgnoreReturnValue
+ public Builder content(Content.Builder... contentBuilders) {
+ return content(
+ Arrays.asList(contentBuilders).stream()
+ .map(Content.Builder::build)
+ .collect(toImmutableList()));
+ }
+
+ /** Internal setter for content with Optional. */
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder content(Optional> content);
+
+ /**
+ * Clear method for content.
+ *
+ * Removes the content field.
+ */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearContent() {
+ return content(Optional.empty());
+ }
+
+ /**
+ * Setter for role.
+ *
+ *
role: The role in the conversation ('user' or 'model').
+ */
+ @JsonProperty("role")
+ public abstract Builder role(String role);
+
+ /** Internal setter for role with Optional. */
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder role(Optional role);
+
+ /**
+ * Clear method for role.
+ *
+ * Removes the role field.
+ */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearRole() {
+ return role(Optional.empty());
+ }
+
+ /** Builds the Turn instance. */
+ public abstract Turn build();
+ }
+
+ /** Deserializes a Turn from a JSON string. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Turn fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, Turn.class);
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/AgentConfig.java b/src/main/java/com/google/genai/types/interactions/AgentConfig.java
new file mode 100644
index 00000000000..878d8b8be98
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/AgentConfig.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonSubTypes;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+
+/**
+ * Base interface for agent configuration types using a type discriminator.
+ *
+ *
AgentConfig is a polymorphic type that configures agent behavior. Alternative to {@code
+ * generation_config}. Only applicable when {@code agent} is set.
+ *
+ *
Concrete subtypes:
+ *
+ *
+ * {@link DynamicAgentConfig} - Configuration for dynamic agents
+ * {@link DeepResearchAgentConfig} - Configuration for Deep Research agent
+ *
+ *
+ * Example usage:
+ *
+ *
{@code
+ * // Dynamic agent configuration
+ * AgentConfig config = DynamicAgentConfig.create();
+ *
+ * // Deep Research agent with thinking summaries
+ * AgentConfig config = DeepResearchAgentConfig.builder()
+ * .thinkingSummaries(new ThinkingSummaries(ThinkingSummaries.Known.AUTO))
+ * .build();
+ *
+ * // Use in CreateInteractionConfig
+ * CreateInteractionConfig interactionConfig = CreateInteractionConfig.builder()
+ * .agent("agent-name")
+ * .input("Your input")
+ * .agentConfig(config)
+ * .build();
+ * }
+ */
+@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
+@JsonSubTypes({
+ @JsonSubTypes.Type(value = DynamicAgentConfig.class, name = "dynamic"),
+ @JsonSubTypes.Type(value = DeepResearchAgentConfig.class, name = "deep-research")
+})
+public interface AgentConfig {
+ // Marker interface - Jackson handles type discrimination via annotations
+}
diff --git a/src/main/java/com/google/genai/types/interactions/AllowedTools.java b/src/main/java/com/google/genai/types/interactions/AllowedTools.java
new file mode 100644
index 00000000000..cc88aa86901
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/AllowedTools.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Configuration for allowed tools in an MCP server.
+ *
+ * This type matches the Python SDK's AllowedTools:
+ *
+ *
+ * class AllowedTools(BaseModel):
+ * mode: Optional[ToolChoiceType] = None # Literal["auto", "any", "none", "validated"]
+ * tools: Optional[List[str]] = None
+ *
+ *
+ * Example usage:
+ *
+ *
{@code
+ * AllowedTools allowedTools = AllowedTools.builder()
+ * .mode("auto")
+ * .tools("get_weather", "get_forecast")
+ * .build();
+ * }
+ */
+@AutoValue
+@JsonDeserialize(builder = AllowedTools.Builder.class)
+public abstract class AllowedTools extends JsonSerializable {
+
+ /**
+ * The mode of the tool choice.
+ *
+ * Valid values: "auto", "any", "none", "validated"
+ */
+ @JsonProperty("mode")
+ public abstract Optional mode();
+
+ /** The names of the allowed tools. */
+ @JsonProperty("tools")
+ public abstract Optional> tools();
+
+ /** Instantiates a builder for AllowedTools. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_AllowedTools.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for AllowedTools. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /** For internal usage. Please use {@code AllowedTools.builder()} for instantiation. */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_AllowedTools.Builder();
+ }
+
+ /**
+ * Setter for mode.
+ *
+ * mode: The mode of the tool choice. Valid values: "auto", "any", "none", "validated"
+ */
+ @JsonProperty("mode")
+ public abstract Builder mode(String mode);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder mode(Optional mode);
+
+ /** Clears the value of mode field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearMode() {
+ return mode(Optional.empty());
+ }
+
+ /**
+ * Setter for tools.
+ *
+ * tools: The names of the allowed tools.
+ */
+ @JsonProperty("tools")
+ public abstract Builder tools(List tools);
+
+ /**
+ * Setter for tools (varargs convenience method).
+ *
+ * tools: The names of the allowed tools.
+ */
+ @CanIgnoreReturnValue
+ public Builder tools(String... tools) {
+ return tools(Arrays.asList(tools));
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder tools(Optional> tools);
+
+ /** Clears the value of tools field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearTools() {
+ return tools(Optional.empty());
+ }
+
+ public abstract AllowedTools build();
+ }
+
+ /** Deserializes a JSON string to an AllowedTools object. */
+ @ExcludeFromGeneratedCoverageReport
+ public static AllowedTools fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, AllowedTools.class);
+ }
+
+ /** Convenience factory method. */
+ @ExcludeFromGeneratedCoverageReport
+ public static AllowedTools of(String mode, List tools) {
+ return builder().mode(mode).tools(tools).build();
+ }
+
+ /** Convenience factory method (varargs). */
+ @ExcludeFromGeneratedCoverageReport
+ public static AllowedTools of(String mode, String... tools) {
+ return builder().mode(mode).tools(Arrays.asList(tools)).build();
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/Annotation.java b/src/main/java/com/google/genai/types/interactions/Annotation.java
new file mode 100644
index 00000000000..04ac0cf7b86
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/Annotation.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.Optional;
+
+/**
+ * Citation information for model-generated content in the Interactions API.
+ *
+ * Annotations provide attribution for specific segments of text by mapping byte indices to their
+ * source references (such as URLs or titles). This enables proper citation and source tracking for
+ * content generated by the model.
+ *
+ *
Example usage:
+ *
+ *
{@code
+ * Annotation citation = Annotation.builder()
+ * .startIndex(0)
+ * .endIndex(50)
+ * .source("https://example.com/research-paper")
+ * .build();
+ *
+ * // Or using the convenience factory method
+ * Annotation citation2 = Annotation.of(51, 100, "Wikipedia: Machine Learning");
+ * }
+ *
+ * The Interactions API is available in both Vertex AI and Gemini API.
+ *
+ *
Note: The Interactions API is in beta and subject to change.
+ */
+@AutoValue
+@JsonDeserialize(builder = Annotation.Builder.class)
+public abstract class Annotation extends JsonSerializable {
+
+ /**
+ * Start of segment of the response that is attributed to this source. Index indicates the start
+ * of the segment, measured in bytes.
+ */
+ @JsonProperty("start_index")
+ public abstract Optional startIndex();
+
+ /**
+ * End of the attributed segment, exclusive. Index indicates the end of the segment, measured in
+ * bytes.
+ */
+ @JsonProperty("end_index")
+ public abstract Optional endIndex();
+
+ /** Source attributed for a portion of the text. Could be a URL, title, or other identifier. */
+ @JsonProperty("source")
+ public abstract Optional source();
+
+ /** Instantiates a builder for Annotation. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_Annotation.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for Annotation. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /** For internal usage. Please use {@code Annotation.builder()} for instantiation. */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_Annotation.Builder();
+ }
+
+ /**
+ * Setter for startIndex.
+ *
+ * startIndex: Start of segment of the response that is attributed to this source.
+ */
+ @JsonProperty("start_index")
+ public abstract Builder startIndex(Integer startIndex);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder startIndex(Optional startIndex);
+
+ /** Clears the value of startIndex field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearStartIndex() {
+ return startIndex(Optional.empty());
+ }
+
+ /**
+ * Setter for endIndex.
+ *
+ * endIndex: End of the attributed segment, exclusive.
+ */
+ @JsonProperty("end_index")
+ public abstract Builder endIndex(Integer endIndex);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder endIndex(Optional endIndex);
+
+ /** Clears the value of endIndex field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearEndIndex() {
+ return endIndex(Optional.empty());
+ }
+
+ /**
+ * Setter for source.
+ *
+ * source: Source attributed for a portion of the text.
+ */
+ @JsonProperty("source")
+ public abstract Builder source(String source);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder source(Optional source);
+
+ /** Clears the value of source field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearSource() {
+ return source(Optional.empty());
+ }
+
+ public abstract Annotation build();
+ }
+
+ /** Deserializes a JSON string to an Annotation object. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Annotation fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, Annotation.class);
+ }
+
+ /** Convenience factory method. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Annotation of(Integer startIndex, Integer endIndex, String source) {
+ return builder().startIndex(startIndex).endIndex(endIndex).source(source).build();
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/AudioMimeType.java b/src/main/java/com/google/genai/types/interactions/AudioMimeType.java
new file mode 100644
index 00000000000..36830727902
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/AudioMimeType.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.google.common.base.Ascii;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.Objects;
+
+/**
+ * MIME type for audio content.
+ *
+ * Supports known audio MIME types with extensibility for future formats.
+ */
+public class AudioMimeType {
+
+ /** Enum representing the known audio MIME types. */
+ public enum Known {
+ /** Unspecified or unknown audio MIME type. */
+ AUDIO_MIME_TYPE_UNSPECIFIED("unspecified"),
+
+ /** WAV audio format. */
+ AUDIO_WAV("audio/wav"),
+
+ /** MP3 audio format. */
+ AUDIO_MP3("audio/mp3"),
+
+ /** AIFF audio format. */
+ AUDIO_AIFF("audio/aiff"),
+
+ /** AAC audio format. */
+ AUDIO_AAC("audio/aac"),
+
+ /** OGG audio format. */
+ AUDIO_OGG("audio/ogg"),
+
+ /** FLAC audio format. */
+ AUDIO_FLAC("audio/flac");
+
+ private final String value;
+
+ Known(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return this.value;
+ }
+ }
+
+ private Known mimeTypeEnum;
+ private final String value;
+
+ /**
+ * Constructs an AudioMimeType from a string value.
+ *
+ * @param value The MIME type string (e.g., "audio/mp3")
+ */
+ @JsonCreator
+ public AudioMimeType(String value) {
+ this.value = value;
+ for (Known mimeTypeEnum : Known.values()) {
+ if (Ascii.equalsIgnoreCase(mimeTypeEnum.toString(), value)) {
+ this.mimeTypeEnum = mimeTypeEnum;
+ break;
+ }
+ }
+ if (this.mimeTypeEnum == null) {
+ this.mimeTypeEnum = Known.AUDIO_MIME_TYPE_UNSPECIFIED;
+ }
+ }
+
+ /**
+ * Constructs an AudioMimeType from a known enum value.
+ *
+ * @param knownValue The known MIME type
+ */
+ public AudioMimeType(Known knownValue) {
+ this.mimeTypeEnum = knownValue;
+ this.value = knownValue.toString();
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ @Override
+ @JsonValue
+ public String toString() {
+ return this.value;
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ @SuppressWarnings("PatternMatchingInstanceof")
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null) {
+ return false;
+ }
+
+ if (!(o instanceof AudioMimeType)) {
+ return false;
+ }
+
+ AudioMimeType other = (AudioMimeType) o;
+
+ if (this.mimeTypeEnum != Known.AUDIO_MIME_TYPE_UNSPECIFIED
+ && other.mimeTypeEnum != Known.AUDIO_MIME_TYPE_UNSPECIFIED) {
+ return this.mimeTypeEnum == other.mimeTypeEnum;
+ } else if (this.mimeTypeEnum == Known.AUDIO_MIME_TYPE_UNSPECIFIED
+ && other.mimeTypeEnum == Known.AUDIO_MIME_TYPE_UNSPECIFIED) {
+ return this.value.equals(other.value);
+ }
+ return false;
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ @Override
+ public int hashCode() {
+ if (this.mimeTypeEnum != Known.AUDIO_MIME_TYPE_UNSPECIFIED) {
+ return this.mimeTypeEnum.hashCode();
+ } else {
+ return Objects.hashCode(this.value);
+ }
+ }
+
+ /**
+ * Returns the known enum value if this is a recognized MIME type.
+ *
+ * @return The known enum value
+ */
+ @ExcludeFromGeneratedCoverageReport
+ public Known knownEnum() {
+ return this.mimeTypeEnum;
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/CancelInteractionConfig.java b/src/main/java/com/google/genai/types/interactions/CancelInteractionConfig.java
new file mode 100644
index 00000000000..1fa649f97f5
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/CancelInteractionConfig.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import com.google.genai.types.HttpOptions;
+import java.util.Optional;
+
+/**
+ * Configuration for canceling an interaction in the Interactions API.
+ *
+ *
Optional parameters for the interactions.cancel method. Currently supports HTTP request
+ * options for customizing the cancel operation.
+ *
+ *
Example usage:
+ *
+ *
{@code
+ * CancelInteractionConfig config = CancelInteractionConfig.builder()
+ * .httpOptions(HttpOptions.builder().timeout(5000).build())
+ * .build();
+ * client.interactions.cancel("interaction-id", config);
+ * }
+ *
+ * The Interactions API is available in both Vertex AI and Gemini API.
+ *
+ *
Note: The Interactions API is in beta and subject to change.
+ */
+@AutoValue
+@JsonDeserialize(builder = CancelInteractionConfig.Builder.class)
+public abstract class CancelInteractionConfig extends JsonSerializable {
+ /** Used to override HTTP request options. */
+ @JsonProperty("httpOptions")
+ public abstract Optional httpOptions();
+
+ /** Instantiates a builder for CancelInteractionConfig. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_CancelInteractionConfig.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for CancelInteractionConfig. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /** For internal usage. Please use `CancelInteractionConfig.builder()` for instantiation. */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_CancelInteractionConfig.Builder();
+ }
+
+ /**
+ * Setter for httpOptions.
+ *
+ * httpOptions: Used to override HTTP request options.
+ */
+ @JsonProperty("httpOptions")
+ public abstract Builder httpOptions(HttpOptions httpOptions);
+
+ /**
+ * Setter for httpOptions builder.
+ *
+ *
httpOptions: Used to override HTTP request options.
+ */
+ @CanIgnoreReturnValue
+ public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) {
+ return httpOptions(httpOptionsBuilder.build());
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder httpOptions(Optional httpOptions);
+
+ /** Clears the value of httpOptions field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearHttpOptions() {
+ return httpOptions(Optional.empty());
+ }
+
+ public abstract CancelInteractionConfig build();
+ }
+
+ /** Deserializes a JSON string to a CancelInteractionConfig object. */
+ @ExcludeFromGeneratedCoverageReport
+ public static CancelInteractionConfig fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, CancelInteractionConfig.class);
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/CancelInteractionParameters.java b/src/main/java/com/google/genai/types/interactions/CancelInteractionParameters.java
new file mode 100644
index 00000000000..a1caa2c5c2e
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/CancelInteractionParameters.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.api.core.InternalApi;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.Optional;
+
+/** Parameters for interactions.cancel method. */
+@AutoValue
+@InternalApi
+@JsonDeserialize(builder = CancelInteractionParameters.Builder.class)
+public abstract class CancelInteractionParameters extends JsonSerializable {
+ /** The ID of the interaction to cancel. */
+ @JsonProperty("id")
+ public abstract Optional id();
+
+ /** Optional parameters for the request. */
+ @JsonProperty("config")
+ public abstract Optional config();
+
+ /** Instantiates a builder for CancelInteractionParameters. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_CancelInteractionParameters.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for CancelInteractionParameters. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /**
+ * For internal usage. Please use `CancelInteractionParameters.builder()` for instantiation.
+ */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_CancelInteractionParameters.Builder();
+ }
+
+ /**
+ * Setter for id.
+ *
+ * id: The ID of the interaction to cancel.
+ */
+ @JsonProperty("id")
+ public abstract Builder id(String id);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder id(Optional id);
+
+ /** Clears the value of id field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearId() {
+ return id(Optional.empty());
+ }
+
+ /**
+ * Setter for config.
+ *
+ * config: Optional parameters for the request.
+ */
+ @JsonProperty("config")
+ public abstract Builder config(CancelInteractionConfig config);
+
+ /**
+ * Setter for config builder.
+ *
+ *
config: Optional parameters for the request.
+ */
+ @CanIgnoreReturnValue
+ public Builder config(CancelInteractionConfig.Builder configBuilder) {
+ return config(configBuilder.build());
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder config(Optional config);
+
+ /** Clears the value of config field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearConfig() {
+ return config(Optional.empty());
+ }
+
+ public abstract CancelInteractionParameters build();
+ }
+
+ /** Deserializes a JSON string to a CancelInteractionParameters object. */
+ @ExcludeFromGeneratedCoverageReport
+ public static CancelInteractionParameters fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, CancelInteractionParameters.class);
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/CodeExecutionCallArguments.java b/src/main/java/com/google/genai/types/interactions/CodeExecutionCallArguments.java
new file mode 100644
index 00000000000..8d46ae6cf6d
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/CodeExecutionCallArguments.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.Optional;
+
+@AutoValue
+@JsonDeserialize(builder = CodeExecutionCallArguments.Builder.class)
+public abstract class CodeExecutionCallArguments extends JsonSerializable {
+
+ @JsonProperty("language")
+ public abstract Optional language();
+
+ @JsonProperty("code")
+ public abstract Optional code();
+
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_CodeExecutionCallArguments.Builder();
+ }
+
+ public abstract Builder toBuilder();
+
+ @AutoValue.Builder
+ public abstract static class Builder {
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_CodeExecutionCallArguments.Builder();
+ }
+
+ @JsonProperty("language")
+ public abstract Builder language(String language);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder language(Optional language);
+
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearLanguage() {
+ return language(Optional.empty());
+ }
+
+ @JsonProperty("code")
+ public abstract Builder code(String code);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder code(Optional code);
+
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearCode() {
+ return code(Optional.empty());
+ }
+
+ public abstract CodeExecutionCallArguments build();
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ public static CodeExecutionCallArguments fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, CodeExecutionCallArguments.class);
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ public static CodeExecutionCallArguments of(String language, String code) {
+ return builder().language(language).code(code).build();
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/CreateInteractionConfig.java b/src/main/java/com/google/genai/types/interactions/CreateInteractionConfig.java
new file mode 100644
index 00000000000..3adfbe48adb
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/CreateInteractionConfig.java
@@ -0,0 +1,549 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.common.collect.ImmutableList;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.interactions.AgentConfig;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import com.google.genai.types.HttpOptions;
+import com.google.genai.types.interactions.content.Content;
+import com.google.genai.types.interactions.tools.Tool;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Configuration for creating an interaction.
+ *
+ * The Interactions API is available in both Vertex AI and Gemini API.
+ *
+ *
Note: The Interactions API is in beta and subject to change.
+ */
+@AutoValue
+@JsonDeserialize(builder = CreateInteractionConfig.Builder.class)
+public abstract class CreateInteractionConfig extends JsonSerializable {
+ /** Used to override HTTP request options. */
+ @JsonProperty("httpOptions")
+ public abstract Optional httpOptions();
+
+ /** Required: The input for the interaction. */
+ @JsonProperty("input")
+ public abstract Input input();
+
+ /** The model to use for the interaction. Either model or agent must be specified. */
+ @JsonProperty("model")
+ public abstract Optional model();
+
+ /** The agent to use for the interaction. Either model or agent must be specified. */
+ @JsonProperty("agent")
+ public abstract Optional agent();
+
+ /** Whether to run the interaction in the background. */
+ @JsonProperty("background")
+ public abstract Optional background();
+
+ /** Whether to stream the interaction response. */
+ @JsonProperty("stream")
+ public abstract Optional stream();
+
+ /** Configuration for generation (only used with model-based interactions). */
+ @JsonProperty("generation_config")
+ public abstract Optional generationConfig();
+
+ /** Configuration for the agent (only used with agent-based interactions). */
+ @JsonProperty("agent_config")
+ public abstract Optional agentConfig();
+
+ /** The ID of the previous interaction for conversation continuity. */
+ @JsonProperty("previous_interaction_id")
+ public abstract Optional previousInteractionId();
+
+ /** The expected response format. */
+ @JsonProperty("response_format")
+ public abstract Optional responseFormat();
+
+ /** The MIME type for the response. */
+ @JsonProperty("response_mime_type")
+ public abstract Optional responseMimeType();
+
+ /**
+ * The requested modalities of the response.
+ *
+ * Represents the set of modalities that the model can return.
+ *
+ *
Supported values:
+ *
+ *
+ * {@link ResponseModality.Known#TEXT} - Text content
+ * {@link ResponseModality.Known#IMAGE} - Image content
+ * {@link ResponseModality.Known#AUDIO} - Audio content
+ *
+ */
+ @JsonProperty("response_modalities")
+ public abstract Optional> responseModalities();
+
+ /** Whether to store the interaction history. */
+ @JsonProperty("store")
+ public abstract Optional store();
+
+ /** Developer set system instruction. */
+ @JsonProperty("system_instruction")
+ public abstract Optional systemInstruction();
+
+ /**
+ * A list of tools the model may use to generate the next response.
+ *
+ * Use the dedicated Interactions tool types such as {@code Function}, {@code GoogleSearch},
+ * {@code CodeExecution}, etc.
+ */
+ @JsonProperty("tools")
+ public abstract Optional> tools();
+
+ /** Instantiates a builder for CreateInteractionConfig. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_CreateInteractionConfig.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for CreateInteractionConfig. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /** For internal usage. Please use `CreateInteractionConfig.builder()` for instantiation. */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_CreateInteractionConfig.Builder();
+ }
+
+ /**
+ * Setter for httpOptions.
+ *
+ * httpOptions: Used to override HTTP request options.
+ */
+ @JsonProperty("httpOptions")
+ public abstract Builder httpOptions(HttpOptions httpOptions);
+
+ /**
+ * Setter for httpOptions builder.
+ *
+ *
httpOptions: Used to override HTTP request options.
+ */
+ @CanIgnoreReturnValue
+ public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) {
+ return httpOptions(httpOptionsBuilder.build());
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder httpOptions(Optional httpOptions);
+
+ /** Clears the value of httpOptions field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearHttpOptions() {
+ return httpOptions(Optional.empty());
+ }
+
+ /**
+ * Setter for input.
+ *
+ * input: The input for the interaction.
+ */
+ @JsonProperty("input")
+ public abstract Builder input(Input input);
+
+ /**
+ * Convenience setter for input from a string.
+ *
+ *
input: The input text for the interaction.
+ */
+ @CanIgnoreReturnValue
+ public Builder input(String text) {
+ return input(Input.fromString(text));
+ }
+
+ /**
+ * Convenience setter for input from a list of Content.
+ *
+ *
input: The input content for the interaction.
+ */
+ @CanIgnoreReturnValue
+ public Builder inputFromContents(List contents) {
+ return input(Input.fromContents(contents));
+ }
+
+ /**
+ * Convenience setter for input from Content objects (varargs).
+ *
+ * input: The input content for the interaction.
+ */
+ @CanIgnoreReturnValue
+ public Builder inputFromContents(Content... contents) {
+ return input(Input.fromContents(contents));
+ }
+
+ /**
+ * Convenience setter for input from a list of Turn.
+ *
+ *
input: The input turns for the interaction.
+ */
+ @CanIgnoreReturnValue
+ public Builder inputFromTurns(List turns) {
+ return input(Input.fromTurns(turns));
+ }
+
+ /**
+ * Convenience setter for input from Turn objects (varargs).
+ *
+ * input: The input turns for the interaction.
+ */
+ @CanIgnoreReturnValue
+ public Builder inputFromTurns(Turn... turns) {
+ return input(Input.fromTurns(turns));
+ }
+
+ /**
+ * Setter for model.
+ *
+ *
model: The model to use for the interaction.
+ */
+ @JsonProperty("model")
+ public abstract Builder model(String model);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder model(Optional model);
+
+ /** Clears the value of model field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearModel() {
+ return model(Optional.empty());
+ }
+
+ /**
+ * Setter for agent.
+ *
+ * agent: The agent to use for the interaction.
+ */
+ @JsonProperty("agent")
+ public abstract Builder agent(String agent);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder agent(Optional agent);
+
+ /** Clears the value of agent field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearAgent() {
+ return agent(Optional.empty());
+ }
+
+ /**
+ * Setter for background.
+ *
+ * background: Whether to run the interaction in the background.
+ */
+ @JsonProperty("background")
+ public abstract Builder background(Boolean background);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder background(Optional background);
+
+ /** Clears the value of background field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearBackground() {
+ return background(Optional.empty());
+ }
+
+ /**
+ * Setter for stream.
+ *
+ * stream: Whether to stream the interaction response.
+ */
+ @JsonProperty("stream")
+ public abstract Builder stream(Boolean stream);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder stream(Optional stream);
+
+ /** Clears the value of stream field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearStream() {
+ return stream(Optional.empty());
+ }
+
+ /**
+ * Setter for generationConfig.
+ *
+ * generationConfig: Configuration for generation.
+ */
+ @JsonProperty("generation_config")
+ public abstract Builder generationConfig(GenerationConfig generationConfig);
+
+ /**
+ * Setter for generationConfig builder.
+ *
+ *
generationConfig: Configuration for generation.
+ */
+ @CanIgnoreReturnValue
+ public Builder generationConfig(GenerationConfig.Builder generationConfigBuilder) {
+ return generationConfig(generationConfigBuilder.build());
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder generationConfig(Optional generationConfig);
+
+ /** Clears the value of generationConfig field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearGenerationConfig() {
+ return generationConfig(Optional.empty());
+ }
+
+ /**
+ * Setter for agentConfig.
+ *
+ * agentConfig: Configuration for the agent.
+ */
+ @JsonProperty("agent_config")
+ public abstract Builder agentConfig(AgentConfig agentConfig);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder agentConfig(Optional agentConfig);
+
+ /** Clears the value of agentConfig field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearAgentConfig() {
+ return agentConfig(Optional.empty());
+ }
+
+ /**
+ * Setter for previousInteractionId.
+ *
+ * previousInteractionId: The ID of the previous interaction.
+ */
+ @JsonProperty("previous_interaction_id")
+ public abstract Builder previousInteractionId(String previousInteractionId);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder previousInteractionId(Optional previousInteractionId);
+
+ /** Clears the value of previousInteractionId field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearPreviousInteractionId() {
+ return previousInteractionId(Optional.empty());
+ }
+
+ /**
+ * Setter for responseFormat.
+ *
+ * responseFormat: The expected response format.
+ */
+ @JsonProperty("response_format")
+ public abstract Builder responseFormat(Object responseFormat);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder responseFormat(Optional responseFormat);
+
+ /** Clears the value of responseFormat field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearResponseFormat() {
+ return responseFormat(Optional.empty());
+ }
+
+ /**
+ * Setter for responseMimeType.
+ *
+ * responseMimeType: The MIME type for the response.
+ */
+ @JsonProperty("response_mime_type")
+ public abstract Builder responseMimeType(String responseMimeType);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder responseMimeType(Optional responseMimeType);
+
+ /** Clears the value of responseMimeType field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearResponseMimeType() {
+ return responseMimeType(Optional.empty());
+ }
+
+ /**
+ * Setter for responseModalities.
+ *
+ * responseModalities: The modalities for the response.
+ */
+ @JsonProperty("response_modalities")
+ public abstract Builder responseModalities(List responseModalities);
+
+ /**
+ * Setter for responseModalities.
+ *
+ * responseModalities: The modalities for the response.
+ */
+ public Builder responseModalities(ResponseModality... responseModalities) {
+ return responseModalities(Arrays.asList(responseModalities));
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder responseModalities(Optional> responseModalities);
+
+ /** Clears the value of responseModalities field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearResponseModalities() {
+ return responseModalities(Optional.empty());
+ }
+
+ /**
+ * Setter for responseModalities given a varargs of strings.
+ *
+ * responseModalities: The modalities for the response.
+ */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder responseModalities(String... responseModalities) {
+ return responseModalitiesFromString(Arrays.asList(responseModalities));
+ }
+
+ /**
+ * Setter for responseModalities given a varargs of known enums.
+ *
+ *
responseModalities: The modalities for the response.
+ */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder responseModalities(ResponseModality.Known... knownTypes) {
+ return responseModalitiesFromKnown(Arrays.asList(knownTypes));
+ }
+
+ /**
+ * Setter for responseModalities given a list of known enums.
+ *
+ *
responseModalities: The modalities for the response.
+ */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder responseModalitiesFromKnown(List knownTypes) {
+ ImmutableList listItems =
+ knownTypes.stream().map(ResponseModality::new).collect(toImmutableList());
+ return responseModalities(listItems);
+ }
+
+ /**
+ * Setter for responseModalities given a list of strings.
+ *
+ * responseModalities: The modalities for the response.
+ */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder responseModalitiesFromString(List responseModalities) {
+ ImmutableList listItems =
+ responseModalities.stream().map(ResponseModality::new).collect(toImmutableList());
+ return responseModalities(listItems);
+ }
+
+ /**
+ * Setter for store.
+ *
+ * store: Whether to store the interaction history.
+ */
+ @JsonProperty("store")
+ public abstract Builder store(Boolean store);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder store(Optional store);
+
+ /** Clears the value of store field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearStore() {
+ return store(Optional.empty());
+ }
+
+ /**
+ * Setter for systemInstruction.
+ *
+ * systemInstruction: Developer set system instruction.
+ */
+ @JsonProperty("system_instruction")
+ public abstract Builder systemInstruction(String systemInstruction);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder systemInstruction(Optional systemInstruction);
+
+ /** Clears the value of systemInstruction field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearSystemInstruction() {
+ return systemInstruction(Optional.empty());
+ }
+
+ /**
+ * Setter for tools.
+ *
+ * tools: A list of tools the model may use to generate the next response. Use the dedicated
+ * Interactions tool types such as {@code FunctionTool}, {@code GoogleSearchTool}, etc.
+ */
+ @JsonProperty("tools")
+ public abstract Builder tools(List tools);
+
+ /**
+ * Setter for tools (varargs convenience method).
+ *
+ * tools: A list of tools the model may use to generate the next response.
+ */
+ @CanIgnoreReturnValue
+ public Builder tools(Tool... tools) {
+ return tools(Arrays.asList(tools));
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder tools(Optional> tools);
+
+ /** Clears the value of tools field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearTools() {
+ return tools(Optional.empty());
+ }
+
+ /** Builds the CreateInteractionConfig instance. */
+ public abstract CreateInteractionConfig build();
+ }
+
+ /** Deserializes a CreateInteractionConfig from a JSON string. */
+ @ExcludeFromGeneratedCoverageReport
+ public static CreateInteractionConfig fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, CreateInteractionConfig.class);
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/CreateInteractionParameters.java b/src/main/java/com/google/genai/types/interactions/CreateInteractionParameters.java
new file mode 100644
index 00000000000..891faa1b87e
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/CreateInteractionParameters.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.api.core.InternalApi;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.Optional;
+
+/** Parameters for interactions.create method. */
+@AutoValue
+@InternalApi
+@JsonDeserialize(builder = CreateInteractionParameters.Builder.class)
+public abstract class CreateInteractionParameters extends JsonSerializable {
+ /** Configuration that contains parameters for the interaction. */
+ @JsonProperty("config")
+ public abstract Optional config();
+
+ /** Instantiates a builder for CreateInteractionParameters. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_CreateInteractionParameters.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for CreateInteractionParameters. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /**
+ * For internal usage. Please use `CreateInteractionParameters.builder()` for instantiation.
+ */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_CreateInteractionParameters.Builder();
+ }
+
+ /**
+ * Setter for config.
+ *
+ * config: Configuration that contains parameters for the interaction.
+ */
+ @JsonProperty("config")
+ public abstract Builder config(CreateInteractionConfig config);
+
+ /**
+ * Setter for config builder.
+ *
+ *
config: Configuration that contains parameters for the interaction.
+ */
+ @CanIgnoreReturnValue
+ public Builder config(CreateInteractionConfig.Builder configBuilder) {
+ return config(configBuilder.build());
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder config(Optional config);
+
+ /** Clears the value of config field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearConfig() {
+ return config(Optional.empty());
+ }
+
+ /** Builds the CreateInteractionParameters instance. */
+ public abstract CreateInteractionParameters build();
+ }
+
+ /** Deserializes a CreateInteractionParameters from a JSON string. */
+ @ExcludeFromGeneratedCoverageReport
+ public static CreateInteractionParameters fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, CreateInteractionParameters.class);
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/DeepResearchAgentConfig.java b/src/main/java/com/google/genai/types/interactions/DeepResearchAgentConfig.java
new file mode 100644
index 00000000000..38b08e59a85
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/DeepResearchAgentConfig.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.Optional;
+
+/**
+ * Configuration for the Deep Research agent.
+ *
+ * DeepResearchAgentConfig allows configuration of the Deep Research agent, including control
+ * over thinking summaries in the response.
+ *
+ *
Example usage:
+ *
+ *
{@code
+ * // Create with thinking summaries
+ * AgentConfig config = DeepResearchAgentConfig.builder()
+ * .thinkingSummaries(new ThinkingSummaries(ThinkingSummaries.Known.AUTO))
+ * .build();
+ *
+ * // Create without thinking summaries
+ * AgentConfig config = DeepResearchAgentConfig.builder()
+ * .thinkingSummaries(new ThinkingSummaries(ThinkingSummaries.Known.NONE))
+ * .build();
+ *
+ * CreateInteractionConfig interactionConfig = CreateInteractionConfig.builder()
+ * .agent("deep-research-pro-preview-12-2025")
+ * .input("Your research question")
+ * .agentConfig(config)
+ * .build();
+ * }
+ */
+@AutoValue
+@JsonDeserialize(builder = DeepResearchAgentConfig.Builder.class)
+@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
+@JsonTypeName("deep-research")
+public abstract class DeepResearchAgentConfig extends JsonSerializable implements AgentConfig {
+
+ /** Instantiates a builder for DeepResearchAgentConfig. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_DeepResearchAgentConfig.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /**
+ * Whether to include thought summaries in response.
+ *
+ * Controls whether the Deep Research agent includes summaries of its thinking process. Use
+ * AUTO to let the agent decide, or NONE to exclude summaries.
+ */
+ @JsonProperty("thinking_summaries")
+ public abstract Optional thinkingSummaries();
+
+ /** Builder for DeepResearchAgentConfig. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /**
+ * For internal usage. Please use {@code DeepResearchAgentConfig.builder()} for instantiation.
+ */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_DeepResearchAgentConfig.Builder();
+ }
+
+ /**
+ * Setter for thinking_summaries.
+ *
+ * @param thinkingSummaries Whether to include thought summaries in response
+ */
+ @JsonProperty("thinking_summaries")
+ public abstract Builder thinkingSummaries(ThinkingSummaries thinkingSummaries);
+
+ /** Internal setter for thinking_summaries with Optional. */
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder thinkingSummaries(Optional thinkingSummaries);
+
+ /** Clears the value of thinking_summaries field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearThinkingSummaries() {
+ return thinkingSummaries(Optional.empty());
+ }
+
+ /** Builds the DeepResearchAgentConfig instance. */
+ public abstract DeepResearchAgentConfig build();
+ }
+
+ /** Deserializes a DeepResearchAgentConfig from a JSON string. */
+ @ExcludeFromGeneratedCoverageReport
+ public static DeepResearchAgentConfig fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, DeepResearchAgentConfig.class);
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/DeleteInteractionConfig.java b/src/main/java/com/google/genai/types/interactions/DeleteInteractionConfig.java
new file mode 100644
index 00000000000..fc5109cdeb4
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/DeleteInteractionConfig.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import com.google.genai.types.HttpOptions;
+import java.util.Optional;
+
+/**
+ * Configuration for deleting an interaction in the Interactions API.
+ *
+ * Optional parameters for the interactions.delete method. Currently supports HTTP request
+ * options for customizing the delete operation.
+ *
+ *
Example usage:
+ *
+ *
{@code
+ * DeleteInteractionConfig config = DeleteInteractionConfig.builder()
+ * .httpOptions(HttpOptions.builder().timeout(5000).build())
+ * .build();
+ * client.interactions.delete("interaction-id", config);
+ * }
+ *
+ * The Interactions API is available in both Vertex AI and Gemini API.
+ *
+ *
Note: The Interactions API is in beta and subject to change.
+ */
+@AutoValue
+@JsonDeserialize(builder = DeleteInteractionConfig.Builder.class)
+public abstract class DeleteInteractionConfig extends JsonSerializable {
+ /** Used to override HTTP request options. */
+ @JsonProperty("httpOptions")
+ public abstract Optional httpOptions();
+
+ /** Instantiates a builder for DeleteInteractionConfig. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_DeleteInteractionConfig.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for DeleteInteractionConfig. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /** For internal usage. Please use `DeleteInteractionConfig.builder()` for instantiation. */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_DeleteInteractionConfig.Builder();
+ }
+
+ /**
+ * Setter for httpOptions.
+ *
+ * httpOptions: Used to override HTTP request options.
+ */
+ @JsonProperty("httpOptions")
+ public abstract Builder httpOptions(HttpOptions httpOptions);
+
+ /**
+ * Setter for httpOptions builder.
+ *
+ *
httpOptions: Used to override HTTP request options.
+ */
+ @CanIgnoreReturnValue
+ public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) {
+ return httpOptions(httpOptionsBuilder.build());
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder httpOptions(Optional httpOptions);
+
+ /** Clears the value of httpOptions field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearHttpOptions() {
+ return httpOptions(Optional.empty());
+ }
+
+ public abstract DeleteInteractionConfig build();
+ }
+
+ /** Deserializes a JSON string to a DeleteInteractionConfig object. */
+ @ExcludeFromGeneratedCoverageReport
+ public static DeleteInteractionConfig fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, DeleteInteractionConfig.class);
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/DeleteInteractionParameters.java b/src/main/java/com/google/genai/types/interactions/DeleteInteractionParameters.java
new file mode 100644
index 00000000000..76008c2e39e
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/DeleteInteractionParameters.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.api.core.InternalApi;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.Optional;
+
+/** Parameters for interactions.delete method. */
+@AutoValue
+@InternalApi
+@JsonDeserialize(builder = DeleteInteractionParameters.Builder.class)
+public abstract class DeleteInteractionParameters extends JsonSerializable {
+ /** The ID of the interaction to delete. */
+ @JsonProperty("id")
+ public abstract Optional id();
+
+ /** Optional parameters for the request. */
+ @JsonProperty("config")
+ public abstract Optional config();
+
+ /** Instantiates a builder for DeleteInteractionParameters. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_DeleteInteractionParameters.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for DeleteInteractionParameters. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /**
+ * For internal usage. Please use `DeleteInteractionParameters.builder()` for instantiation.
+ */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_DeleteInteractionParameters.Builder();
+ }
+
+ /**
+ * Setter for id.
+ *
+ * id: The ID of the interaction to delete.
+ */
+ @JsonProperty("id")
+ public abstract Builder id(String id);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder id(Optional id);
+
+ /** Clears the value of id field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearId() {
+ return id(Optional.empty());
+ }
+
+ /**
+ * Setter for config.
+ *
+ * config: Optional parameters for the request.
+ */
+ @JsonProperty("config")
+ public abstract Builder config(DeleteInteractionConfig config);
+
+ /**
+ * Setter for config builder.
+ *
+ *
config: Optional parameters for the request.
+ */
+ @CanIgnoreReturnValue
+ public Builder config(DeleteInteractionConfig.Builder configBuilder) {
+ return config(configBuilder.build());
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder config(Optional config);
+
+ /** Clears the value of config field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearConfig() {
+ return config(Optional.empty());
+ }
+
+ public abstract DeleteInteractionParameters build();
+ }
+
+ /** Deserializes a JSON string to a DeleteInteractionParameters object. */
+ @ExcludeFromGeneratedCoverageReport
+ public static DeleteInteractionParameters fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, DeleteInteractionParameters.class);
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/DeleteInteractionResponse.java b/src/main/java/com/google/genai/types/interactions/DeleteInteractionResponse.java
new file mode 100644
index 00000000000..4fe4df5176a
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/DeleteInteractionResponse.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import com.google.genai.types.HttpResponse;
+import java.util.Optional;
+
+/** Empty response for interactions.delete method. */
+@AutoValue
+@JsonDeserialize(builder = DeleteInteractionResponse.Builder.class)
+public abstract class DeleteInteractionResponse extends JsonSerializable {
+ /** Used to retain the full HTTP response. */
+ @JsonProperty("sdkHttpResponse")
+ public abstract Optional sdkHttpResponse();
+
+ /** Instantiates a builder for DeleteInteractionResponse. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_DeleteInteractionResponse.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for DeleteInteractionResponse. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /** For internal usage. Please use `DeleteInteractionResponse.builder()` for instantiation. */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_DeleteInteractionResponse.Builder();
+ }
+
+ /**
+ * Setter for sdkHttpResponse.
+ *
+ * sdkHttpResponse: Used to retain the full HTTP response.
+ */
+ @JsonProperty("sdkHttpResponse")
+ public abstract Builder sdkHttpResponse(HttpResponse sdkHttpResponse);
+
+ /**
+ * Setter for sdkHttpResponse builder.
+ *
+ *
sdkHttpResponse: Used to retain the full HTTP response.
+ */
+ @CanIgnoreReturnValue
+ public Builder sdkHttpResponse(HttpResponse.Builder sdkHttpResponseBuilder) {
+ return sdkHttpResponse(sdkHttpResponseBuilder.build());
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder sdkHttpResponse(Optional sdkHttpResponse);
+
+ /** Clears the value of sdkHttpResponse field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearSdkHttpResponse() {
+ return sdkHttpResponse(Optional.empty());
+ }
+
+ public abstract DeleteInteractionResponse build();
+ }
+
+ /** Deserializes a JSON string to a DeleteInteractionResponse object. */
+ @ExcludeFromGeneratedCoverageReport
+ public static DeleteInteractionResponse fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, DeleteInteractionResponse.class);
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/DocumentMimeType.java b/src/main/java/com/google/genai/types/interactions/DocumentMimeType.java
new file mode 100644
index 00000000000..8923db43ed8
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/DocumentMimeType.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.google.common.base.Ascii;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.Objects;
+
+/**
+ * MIME type for document content.
+ *
+ * Supports known document MIME types with extensibility for future formats.
+ */
+public class DocumentMimeType {
+
+ /** Enum representing the known document MIME types. */
+ public enum Known {
+ /** Unspecified or unknown document MIME type. */
+ DOCUMENT_MIME_TYPE_UNSPECIFIED("unspecified"),
+
+ /** PDF document format. */
+ APPLICATION_PDF("application/pdf");
+
+ private final String value;
+
+ Known(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return this.value;
+ }
+ }
+
+ private Known mimeTypeEnum;
+ private final String value;
+
+ /**
+ * Constructs a DocumentMimeType from a string value.
+ *
+ * @param value The MIME type string (e.g., "application/pdf")
+ */
+ @JsonCreator
+ public DocumentMimeType(String value) {
+ this.value = value;
+ for (Known mimeTypeEnum : Known.values()) {
+ if (Ascii.equalsIgnoreCase(mimeTypeEnum.toString(), value)) {
+ this.mimeTypeEnum = mimeTypeEnum;
+ break;
+ }
+ }
+ if (this.mimeTypeEnum == null) {
+ this.mimeTypeEnum = Known.DOCUMENT_MIME_TYPE_UNSPECIFIED;
+ }
+ }
+
+ /**
+ * Constructs a DocumentMimeType from a known enum value.
+ *
+ * @param knownValue The known MIME type
+ */
+ public DocumentMimeType(Known knownValue) {
+ this.mimeTypeEnum = knownValue;
+ this.value = knownValue.toString();
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ @Override
+ @JsonValue
+ public String toString() {
+ return this.value;
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ @SuppressWarnings("PatternMatchingInstanceof")
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null) {
+ return false;
+ }
+
+ if (!(o instanceof DocumentMimeType)) {
+ return false;
+ }
+
+ DocumentMimeType other = (DocumentMimeType) o;
+
+ if (this.mimeTypeEnum != Known.DOCUMENT_MIME_TYPE_UNSPECIFIED
+ && other.mimeTypeEnum != Known.DOCUMENT_MIME_TYPE_UNSPECIFIED) {
+ return this.mimeTypeEnum == other.mimeTypeEnum;
+ } else if (this.mimeTypeEnum == Known.DOCUMENT_MIME_TYPE_UNSPECIFIED
+ && other.mimeTypeEnum == Known.DOCUMENT_MIME_TYPE_UNSPECIFIED) {
+ return this.value.equals(other.value);
+ }
+ return false;
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ @Override
+ public int hashCode() {
+ if (this.mimeTypeEnum != Known.DOCUMENT_MIME_TYPE_UNSPECIFIED) {
+ return this.mimeTypeEnum.hashCode();
+ } else {
+ return Objects.hashCode(this.value);
+ }
+ }
+
+ /**
+ * Returns the known enum value if this is a recognized MIME type.
+ *
+ * @return The known enum value
+ */
+ @ExcludeFromGeneratedCoverageReport
+ public Known knownEnum() {
+ return this.mimeTypeEnum;
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/DynamicAgentConfig.java b/src/main/java/com/google/genai/types/interactions/DynamicAgentConfig.java
new file mode 100644
index 00000000000..7bdd554291e
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/DynamicAgentConfig.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+
+/**
+ * Configuration for dynamic agents.
+ *
+ *
DynamicAgentConfig allows configuration of agents with dynamic behavior. This is a minimal
+ * configuration type with extensibility support.
+ *
+ *
Example usage:
+ *
+ *
{@code
+ * AgentConfig config = DynamicAgentConfig.create();
+ *
+ * CreateInteractionConfig interactionConfig = CreateInteractionConfig.builder()
+ * .agent("agent-name")
+ * .input("Your input")
+ * .agentConfig(config)
+ * .build();
+ * }
+ */
+@AutoValue
+@JsonDeserialize(builder = DynamicAgentConfig.Builder.class)
+@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
+@JsonTypeName("dynamic")
+public abstract class DynamicAgentConfig extends JsonSerializable implements AgentConfig {
+
+ /** Creates a new DynamicAgentConfig instance. */
+ @ExcludeFromGeneratedCoverageReport
+ public static DynamicAgentConfig create() {
+ return new AutoValue_DynamicAgentConfig.Builder().build();
+ }
+
+ /** Instantiates a builder for DynamicAgentConfig. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_DynamicAgentConfig.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for DynamicAgentConfig. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /** For internal usage. Please use {@code DynamicAgentConfig.builder()} for instantiation. */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_DynamicAgentConfig.Builder();
+ }
+
+ /** Builds the DynamicAgentConfig instance. */
+ public abstract DynamicAgentConfig build();
+ }
+
+ /** Deserializes a DynamicAgentConfig from a JSON string. */
+ @ExcludeFromGeneratedCoverageReport
+ public static DynamicAgentConfig fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, DynamicAgentConfig.class);
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/FileSearchResult.java b/src/main/java/com/google/genai/types/interactions/FileSearchResult.java
new file mode 100644
index 00000000000..8943accb07b
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/FileSearchResult.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.Optional;
+
+@AutoValue
+@JsonDeserialize(builder = FileSearchResult.Builder.class)
+public abstract class FileSearchResult extends JsonSerializable {
+
+ @JsonProperty("title")
+ public abstract Optional title();
+
+ @JsonProperty("text")
+ public abstract Optional text();
+
+ @JsonProperty("file_search_store")
+ public abstract Optional fileSearchStore();
+
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_FileSearchResult.Builder();
+ }
+
+ public abstract Builder toBuilder();
+
+ @AutoValue.Builder
+ public abstract static class Builder {
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_FileSearchResult.Builder();
+ }
+
+ @JsonProperty("title")
+ public abstract Builder title(String title);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder title(Optional title);
+
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearTitle() {
+ return title(Optional.empty());
+ }
+
+ @JsonProperty("text")
+ public abstract Builder text(String text);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder text(Optional text);
+
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearText() {
+ return text(Optional.empty());
+ }
+
+ @JsonProperty("file_search_store")
+ public abstract Builder fileSearchStore(String fileSearchStore);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder fileSearchStore(Optional fileSearchStore);
+
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearFileSearchStore() {
+ return fileSearchStore(Optional.empty());
+ }
+
+ public abstract FileSearchResult build();
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ public static FileSearchResult fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, FileSearchResult.class);
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ public static FileSearchResult of(String title, String text, String fileSearchStore) {
+ return builder().title(title).text(text).fileSearchStore(fileSearchStore).build();
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/GenerationConfig.java b/src/main/java/com/google/genai/types/interactions/GenerationConfig.java
new file mode 100644
index 00000000000..e2cd368e698
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/GenerationConfig.java
@@ -0,0 +1,353 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Generation configuration specific to the Interactions API.
+ *
+ * This configuration contains exactly the 10 fields defined in the Interactions API
+ * specification for the generationConfig parameter. It differs from the general {@code
+ * GenerationConfig} class which is shared across multiple APIs and has 25+ fields.
+ *
+ *
The Interactions API is available in both Vertex AI and Gemini API.
+ *
+ *
The 10 fields are:
+ *
+ *
+ * temperature - Controls randomness of predictions
+ * topP - Nucleus sampling parameter
+ * seed - Random seed for reproducibility
+ * stopSequences - List of sequences that stop generation
+ * toolChoice - Controls tool usage behavior
+ * thinkingLevel - Controls model thinking depth
+ * thinkingSummaries - Controls inclusion of thinking summaries
+ * maxOutputTokens - Maximum tokens to generate
+ * speechConfig - Configuration for speech generation
+ * imageConfig - Configuration for image generation
+ *
+ */
+@AutoValue
+@JsonDeserialize(builder = GenerationConfig.Builder.class)
+public abstract class GenerationConfig extends JsonSerializable {
+
+ /** Controls the randomness of predictions. Higher values increase randomness. */
+ @JsonProperty("temperature")
+ public abstract Optional temperature();
+
+ /**
+ * Nucleus sampling parameter. Only tokens with cumulative probability up to topP are considered.
+ */
+ @JsonProperty("top_p")
+ public abstract Optional topP();
+
+ /** Random seed for reproducible generation. */
+ @JsonProperty("seed")
+ public abstract Optional seed();
+
+ /** List of sequences that will stop generation when encountered. */
+ @JsonProperty("stop_sequences")
+ public abstract Optional> stopSequences();
+
+ /**
+ * Controls tool usage behavior.
+ *
+ * Can be a simple type (auto, any, none, validated) or a configuration object specifying
+ * allowed tools.
+ */
+ @JsonProperty("tool_choice")
+ public abstract Optional toolChoice();
+
+ /**
+ * Controls the amount of thinking the model performs.
+ *
+ * Supported values: MINIMAL, LOW, MEDIUM, HIGH.
+ */
+ @JsonProperty("thinking_level")
+ public abstract Optional thinkingLevel();
+
+ /**
+ * Controls whether thinking summaries are included in the response.
+ *
+ * Supported values: AUTO, NONE.
+ */
+ @JsonProperty("thinking_summaries")
+ public abstract Optional thinkingSummaries();
+
+ /** The maximum number of output tokens to generate. */
+ @JsonProperty("max_output_tokens")
+ public abstract Optional maxOutputTokens();
+
+ /** Configuration for speech generation (voice, language, speaker). */
+ @JsonProperty("speech_config")
+ public abstract Optional speechConfig();
+
+ /** Configuration for image generation (aspect ratio, image size). */
+ @JsonProperty("image_config")
+ public abstract Optional imageConfig();
+
+ /** Instantiates a builder for GenerationConfig. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_GenerationConfig.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for GenerationConfig. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /** For internal usage. Please use {@code GenerationConfig.builder()} for instantiation. */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_GenerationConfig.Builder();
+ }
+
+ /**
+ * Setter for temperature.
+ *
+ * temperature: Controls the randomness of predictions. Higher values increase randomness.
+ */
+ @JsonProperty("temperature")
+ public abstract Builder temperature(Float temperature);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder temperature(Optional temperature);
+
+ /** Clears the value of temperature field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearTemperature() {
+ return temperature(Optional.empty());
+ }
+
+ /**
+ * Setter for topP.
+ *
+ * topP: Nucleus sampling parameter. Only tokens with cumulative probability up to topP are
+ * considered.
+ */
+ @JsonProperty("top_p")
+ public abstract Builder topP(Float topP);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder topP(Optional topP);
+
+ /** Clears the value of topP field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearTopP() {
+ return topP(Optional.empty());
+ }
+
+ /**
+ * Setter for seed.
+ *
+ * seed: Random seed for reproducible generation.
+ */
+ @JsonProperty("seed")
+ public abstract Builder seed(Integer seed);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder seed(Optional seed);
+
+ /** Clears the value of seed field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearSeed() {
+ return seed(Optional.empty());
+ }
+
+ /**
+ * Setter for stopSequences.
+ *
+ * stopSequences: List of sequences that will stop generation when encountered.
+ */
+ @JsonProperty("stop_sequences")
+ public abstract Builder stopSequences(List stopSequences);
+
+ /**
+ * Setter for stopSequences (varargs convenience method).
+ *
+ * stopSequences: List of sequences that will stop generation when encountered.
+ */
+ @CanIgnoreReturnValue
+ public Builder stopSequences(String... stopSequences) {
+ return stopSequences(Arrays.asList(stopSequences));
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder stopSequences(Optional> stopSequences);
+
+ /** Clears the value of stopSequences field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearStopSequences() {
+ return stopSequences(Optional.empty());
+ }
+
+ /**
+ * Setter for toolChoice.
+ *
+ * toolChoice: Controls tool usage behavior. Can be a simple type (auto, any, none,
+ * validated) or a configuration object specifying allowed tools.
+ */
+ @JsonProperty("tool_choice")
+ public abstract Builder toolChoice(ToolChoice toolChoice);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder toolChoice(Optional toolChoice);
+
+ /** Clears the value of toolChoice field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearToolChoice() {
+ return toolChoice(Optional.empty());
+ }
+
+ /**
+ * Setter for thinkingLevel.
+ *
+ * thinkingLevel: Controls the amount of thinking the model performs. Supported values:
+ * MINIMAL, LOW, MEDIUM, HIGH.
+ */
+ @JsonProperty("thinking_level")
+ public abstract Builder thinkingLevel(ThinkingLevel thinkingLevel);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder thinkingLevel(Optional thinkingLevel);
+
+ /** Clears the value of thinkingLevel field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearThinkingLevel() {
+ return thinkingLevel(Optional.empty());
+ }
+
+ /**
+ * Setter for thinkingSummaries.
+ *
+ * thinkingSummaries: Controls whether thinking summaries are included in the response.
+ * Supported values: AUTO, NONE.
+ */
+ @JsonProperty("thinking_summaries")
+ public abstract Builder thinkingSummaries(ThinkingSummaries thinkingSummaries);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder thinkingSummaries(Optional thinkingSummaries);
+
+ /** Clears the value of thinkingSummaries field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearThinkingSummaries() {
+ return thinkingSummaries(Optional.empty());
+ }
+
+ /**
+ * Setter for maxOutputTokens.
+ *
+ * maxOutputTokens: The maximum number of output tokens to generate.
+ */
+ @JsonProperty("max_output_tokens")
+ public abstract Builder maxOutputTokens(Integer maxOutputTokens);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder maxOutputTokens(Optional maxOutputTokens);
+
+ /** Clears the value of maxOutputTokens field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearMaxOutputTokens() {
+ return maxOutputTokens(Optional.empty());
+ }
+
+ /**
+ * Setter for speechConfig.
+ *
+ * speechConfig: Configuration for speech generation (voice, language, speaker).
+ */
+ @JsonProperty("speech_config")
+ public abstract Builder speechConfig(SpeechConfig speechConfig);
+
+ /**
+ * Convenience setter for speechConfig using a builder.
+ *
+ *
speechConfig: Configuration for speech generation (voice, language, speaker).
+ */
+ @CanIgnoreReturnValue
+ public Builder speechConfig(SpeechConfig.Builder speechConfigBuilder) {
+ return speechConfig(speechConfigBuilder.build());
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder speechConfig(Optional speechConfig);
+
+ /** Clears the value of speechConfig field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearSpeechConfig() {
+ return speechConfig(Optional.empty());
+ }
+
+ /**
+ * Setter for imageConfig.
+ *
+ * imageConfig: Configuration for image generation (aspect ratio, image size).
+ */
+ @JsonProperty("image_config")
+ public abstract Builder imageConfig(ImageConfig imageConfig);
+
+ /**
+ * Convenience setter for imageConfig using a builder.
+ *
+ *
imageConfig: Configuration for image generation (aspect ratio, image size).
+ */
+ @CanIgnoreReturnValue
+ public Builder imageConfig(ImageConfig.Builder imageConfigBuilder) {
+ return imageConfig(imageConfigBuilder.build());
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder imageConfig(Optional imageConfig);
+
+ /** Clears the value of imageConfig field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearImageConfig() {
+ return imageConfig(Optional.empty());
+ }
+
+ public abstract GenerationConfig build();
+ }
+
+ /** Deserializes a JSON string to an GenerationConfig object. */
+ @ExcludeFromGeneratedCoverageReport
+ public static GenerationConfig fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, GenerationConfig.class);
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/GetInteractionConfig.java b/src/main/java/com/google/genai/types/interactions/GetInteractionConfig.java
new file mode 100644
index 00000000000..c0e6890e88c
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/GetInteractionConfig.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import com.google.genai.types.HttpOptions;
+import java.util.Optional;
+
+/** Optional parameters for interactions.get method. */
+@AutoValue
+@JsonDeserialize(builder = GetInteractionConfig.Builder.class)
+public abstract class GetInteractionConfig extends JsonSerializable {
+ /** Used to override HTTP request options. */
+ @JsonProperty("httpOptions")
+ public abstract Optional httpOptions();
+
+ /** Instantiates a builder for GetInteractionConfig. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_GetInteractionConfig.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for GetInteractionConfig. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /** For internal usage. Please use `GetInteractionConfig.builder()` for instantiation. */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_GetInteractionConfig.Builder();
+ }
+
+ /**
+ * Setter for httpOptions.
+ *
+ * httpOptions: Used to override HTTP request options.
+ */
+ @JsonProperty("httpOptions")
+ public abstract Builder httpOptions(HttpOptions httpOptions);
+
+ /**
+ * Setter for httpOptions builder.
+ *
+ *
httpOptions: Used to override HTTP request options.
+ */
+ @CanIgnoreReturnValue
+ public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) {
+ return httpOptions(httpOptionsBuilder.build());
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder httpOptions(Optional httpOptions);
+
+ /** Clears the value of httpOptions field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearHttpOptions() {
+ return httpOptions(Optional.empty());
+ }
+
+ public abstract GetInteractionConfig build();
+ }
+
+ /** Deserializes a JSON string to a GetInteractionConfig object. */
+ @ExcludeFromGeneratedCoverageReport
+ public static GetInteractionConfig fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, GetInteractionConfig.class);
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/GetInteractionParameters.java b/src/main/java/com/google/genai/types/interactions/GetInteractionParameters.java
new file mode 100644
index 00000000000..c85b2cd3668
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/GetInteractionParameters.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.api.core.InternalApi;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.Optional;
+
+/** Parameters for interactions.get method. */
+@AutoValue
+@InternalApi
+@JsonDeserialize(builder = GetInteractionParameters.Builder.class)
+public abstract class GetInteractionParameters extends JsonSerializable {
+ /** The ID of the interaction to retrieve. */
+ @JsonProperty("id")
+ public abstract Optional id();
+
+ /** Optional parameters for the request. */
+ @JsonProperty("config")
+ public abstract Optional config();
+
+ /** Instantiates a builder for GetInteractionParameters. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_GetInteractionParameters.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for GetInteractionParameters. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /** For internal usage. Please use `GetInteractionParameters.builder()` for instantiation. */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_GetInteractionParameters.Builder();
+ }
+
+ /**
+ * Setter for id.
+ *
+ * id: The ID of the interaction to retrieve.
+ */
+ @JsonProperty("id")
+ public abstract Builder id(String id);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder id(Optional id);
+
+ /** Clears the value of id field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearId() {
+ return id(Optional.empty());
+ }
+
+ /**
+ * Setter for config.
+ *
+ * config: Optional parameters for the request.
+ */
+ @JsonProperty("config")
+ public abstract Builder config(GetInteractionConfig config);
+
+ /**
+ * Setter for config builder.
+ *
+ *
config: Optional parameters for the request.
+ */
+ @CanIgnoreReturnValue
+ public Builder config(GetInteractionConfig.Builder configBuilder) {
+ return config(configBuilder.build());
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder config(Optional config);
+
+ /** Clears the value of config field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearConfig() {
+ return config(Optional.empty());
+ }
+
+ public abstract GetInteractionParameters build();
+ }
+
+ /** Deserializes a JSON string to a GetInteractionParameters object. */
+ @ExcludeFromGeneratedCoverageReport
+ public static GetInteractionParameters fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, GetInteractionParameters.class);
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/GoogleSearchCallArguments.java b/src/main/java/com/google/genai/types/interactions/GoogleSearchCallArguments.java
new file mode 100644
index 00000000000..2db25c19ec4
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/GoogleSearchCallArguments.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Arguments for Google Search tool calls in the Interactions API.
+ *
+ * Specifies the search queries to be executed when the model invokes the Google Search tool.
+ *
+ *
Example usage:
+ *
+ *
{@code
+ * GoogleSearchCallArguments args = GoogleSearchCallArguments.builder()
+ * .queries(List.of("latest AI research", "machine learning trends"))
+ * .build();
+ * }
+ *
+ * The Interactions API is available in both Vertex AI and Gemini API.
+ *
+ *
Note: The Interactions API is in beta and subject to change.
+ */
+@AutoValue
+@JsonDeserialize(builder = GoogleSearchCallArguments.Builder.class)
+public abstract class GoogleSearchCallArguments extends JsonSerializable {
+
+ @JsonProperty("queries")
+ public abstract Optional> queries();
+
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_GoogleSearchCallArguments.Builder();
+ }
+
+ public abstract Builder toBuilder();
+
+ @AutoValue.Builder
+ public abstract static class Builder {
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_GoogleSearchCallArguments.Builder();
+ }
+
+ @JsonProperty("queries")
+ public abstract Builder queries(List queries);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder queries(Optional> queries);
+
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearQueries() {
+ return queries(Optional.empty());
+ }
+
+ public abstract GoogleSearchCallArguments build();
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ public static GoogleSearchCallArguments fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, GoogleSearchCallArguments.class);
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ public static GoogleSearchCallArguments of(List queries) {
+ return builder().queries(queries).build();
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/GoogleSearchResult.java b/src/main/java/com/google/genai/types/interactions/GoogleSearchResult.java
new file mode 100644
index 00000000000..8702f1720cf
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/GoogleSearchResult.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.Optional;
+
+@AutoValue
+@JsonDeserialize(builder = GoogleSearchResult.Builder.class)
+public abstract class GoogleSearchResult extends JsonSerializable {
+
+ @JsonProperty("url")
+ public abstract Optional url();
+
+ @JsonProperty("title")
+ public abstract Optional title();
+
+ @JsonProperty("rendered_content")
+ public abstract Optional renderedContent();
+
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_GoogleSearchResult.Builder();
+ }
+
+ public abstract Builder toBuilder();
+
+ @AutoValue.Builder
+ public abstract static class Builder {
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_GoogleSearchResult.Builder();
+ }
+
+ @JsonProperty("url")
+ public abstract Builder url(String url);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder url(Optional url);
+
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearUrl() {
+ return url(Optional.empty());
+ }
+
+ @JsonProperty("title")
+ public abstract Builder title(String title);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder title(Optional title);
+
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearTitle() {
+ return title(Optional.empty());
+ }
+
+ @JsonProperty("rendered_content")
+ public abstract Builder renderedContent(String renderedContent);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder renderedContent(Optional renderedContent);
+
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearRenderedContent() {
+ return renderedContent(Optional.empty());
+ }
+
+ public abstract GoogleSearchResult build();
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ public static GoogleSearchResult fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, GoogleSearchResult.class);
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ public static GoogleSearchResult of(String url, String title, String renderedContent) {
+ return builder().url(url).title(title).renderedContent(renderedContent).build();
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/ImageConfig.java b/src/main/java/com/google/genai/types/interactions/ImageConfig.java
new file mode 100644
index 00000000000..53c65cdbf9f
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/ImageConfig.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.Optional;
+
+/**
+ * Configuration for image generation in the Interactions API.
+ *
+ * This class controls the visual properties of generated images, including aspect ratio and
+ * resolution. It is specific to the Interactions API and provides a simplified interface compared
+ * to image configuration in other APIs.
+ *
+ *
The Interactions API is available in both Vertex AI and Gemini API.
+ *
+ *
Supported aspect ratios include:
+ *
+ *
+ * "1:1" - Square format
+ * "2:3", "3:2" - Standard photo formats
+ * "3:4", "4:3" - Traditional screen formats
+ * "9:16", "16:9" - Mobile and widescreen formats
+ * "21:9" - Ultra-widescreen format
+ *
+ *
+ * Supported image sizes: "1K", "2K", "4K"
+ *
+ *
Example usage:
+ *
+ *
{@code
+ * // Configure square images at 2K resolution
+ * ImageConfig imageConfig = ImageConfig.builder()
+ * .aspectRatio("1:1")
+ * .imageSize("2K")
+ * .build();
+ *
+ * // Configure widescreen 4K images
+ * ImageConfig widescreenConfig = ImageConfig.builder()
+ * .aspectRatio("16:9")
+ * .imageSize("4K")
+ * .build();
+ *
+ * // Use in generation config
+ * GenerationConfig config = GenerationConfig.builder()
+ * .imageConfig(imageConfig)
+ * .build();
+ * }
+ */
+@AutoValue
+@JsonDeserialize(builder = ImageConfig.Builder.class)
+public abstract class ImageConfig extends JsonSerializable {
+
+ /**
+ * Aspect ratio of the generated images.
+ *
+ * Supported values:
+ *
+ *
+ * {@code "1:1"} - Square (1:1)
+ * {@code "2:3"} - Portrait (2:3)
+ * {@code "3:2"} - Landscape (3:2)
+ * {@code "3:4"} - Portrait (3:4)
+ * {@code "4:3"} - Landscape (4:3)
+ * {@code "4:5"} - Portrait (4:5)
+ * {@code "5:4"} - Landscape (5:4)
+ * {@code "9:16"} - Vertical video (9:16)
+ * {@code "16:9"} - Horizontal video (16:9)
+ * {@code "21:9"} - Ultra-wide (21:9)
+ *
+ *
+ * This field accepts any string value to support future aspect ratios.
+ */
+ @JsonProperty("aspect_ratio")
+ public abstract Optional aspectRatio();
+
+ /**
+ * Specifies the size of generated images.
+ *
+ * Supported values:
+ *
+ *
+ * {@code "1K"} - 1024x1024 pixels (default)
+ * {@code "2K"} - 2048x2048 pixels
+ * {@code "4K"} - 4096x4096 pixels
+ *
+ *
+ * If not specified, the model will use default value {@code "1K"}.
+ *
+ *
This field accepts any string value to support future image sizes.
+ */
+ @JsonProperty("image_size")
+ public abstract Optional imageSize();
+
+ /** Instantiates a builder for ImageConfig. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_ImageConfig.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for ImageConfig. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /** For internal usage. Please use {@code ImageConfig.builder()} for instantiation. */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_ImageConfig.Builder();
+ }
+
+ /**
+ * Setter for aspectRatio.
+ *
+ * aspectRatio: Aspect ratio of the generated images.
+ *
+ *
Supported values: "1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9".
+ */
+ @JsonProperty("aspect_ratio")
+ public abstract Builder aspectRatio(String aspectRatio);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder aspectRatio(Optional aspectRatio);
+
+ /** Clears the value of aspectRatio field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearAspectRatio() {
+ return aspectRatio(Optional.empty());
+ }
+
+ /**
+ * Setter for imageSize.
+ *
+ * imageSize: Size of the generated images. Supported values are "1K", "2K", and "4K".
+ */
+ @JsonProperty("image_size")
+ public abstract Builder imageSize(String imageSize);
+
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder imageSize(Optional imageSize);
+
+ /** Clears the value of imageSize field. */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearImageSize() {
+ return imageSize(Optional.empty());
+ }
+
+ public abstract ImageConfig build();
+ }
+
+ /** Deserializes a JSON string to an ImageConfig object. */
+ @ExcludeFromGeneratedCoverageReport
+ public static ImageConfig fromJson(String jsonString) {
+ return JsonSerializable.fromJsonString(jsonString, ImageConfig.class);
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/ImageMimeType.java b/src/main/java/com/google/genai/types/interactions/ImageMimeType.java
new file mode 100644
index 00000000000..c0ea936dbc2
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/ImageMimeType.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.google.common.base.Ascii;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import java.util.Objects;
+
+/**
+ * MIME type for image content.
+ *
+ * Supports known image MIME types with extensibility for future formats.
+ */
+public class ImageMimeType {
+
+ /** Enum representing the known image MIME types. */
+ public enum Known {
+ /** Unspecified or unknown image MIME type. */
+ IMAGE_MIME_TYPE_UNSPECIFIED("unspecified"),
+
+ /** PNG image format. */
+ IMAGE_PNG("image/png"),
+
+ /** JPEG image format. */
+ IMAGE_JPEG("image/jpeg"),
+
+ /** WebP image format. */
+ IMAGE_WEBP("image/webp"),
+
+ /** HEIC image format. */
+ IMAGE_HEIC("image/heic"),
+
+ /** HEIF image format. */
+ IMAGE_HEIF("image/heif");
+
+ private final String value;
+
+ Known(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return this.value;
+ }
+ }
+
+ private Known mimeTypeEnum;
+ private final String value;
+
+ /**
+ * Constructs an ImageMimeType from a string value.
+ *
+ * @param value The MIME type string (e.g., "image/png")
+ */
+ @JsonCreator
+ public ImageMimeType(String value) {
+ this.value = value;
+ for (Known mimeTypeEnum : Known.values()) {
+ if (Ascii.equalsIgnoreCase(mimeTypeEnum.toString(), value)) {
+ this.mimeTypeEnum = mimeTypeEnum;
+ break;
+ }
+ }
+ if (this.mimeTypeEnum == null) {
+ this.mimeTypeEnum = Known.IMAGE_MIME_TYPE_UNSPECIFIED;
+ }
+ }
+
+ /**
+ * Constructs an ImageMimeType from a known enum value.
+ *
+ * @param knownValue The known MIME type
+ */
+ public ImageMimeType(Known knownValue) {
+ this.mimeTypeEnum = knownValue;
+ this.value = knownValue.toString();
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ @Override
+ @JsonValue
+ public String toString() {
+ return this.value;
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ @SuppressWarnings("PatternMatchingInstanceof")
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null) {
+ return false;
+ }
+
+ if (!(o instanceof ImageMimeType)) {
+ return false;
+ }
+
+ ImageMimeType other = (ImageMimeType) o;
+
+ if (this.mimeTypeEnum != Known.IMAGE_MIME_TYPE_UNSPECIFIED
+ && other.mimeTypeEnum != Known.IMAGE_MIME_TYPE_UNSPECIFIED) {
+ return this.mimeTypeEnum == other.mimeTypeEnum;
+ } else if (this.mimeTypeEnum == Known.IMAGE_MIME_TYPE_UNSPECIFIED
+ && other.mimeTypeEnum == Known.IMAGE_MIME_TYPE_UNSPECIFIED) {
+ return this.value.equals(other.value);
+ }
+ return false;
+ }
+
+ @ExcludeFromGeneratedCoverageReport
+ @Override
+ public int hashCode() {
+ if (this.mimeTypeEnum != Known.IMAGE_MIME_TYPE_UNSPECIFIED) {
+ return this.mimeTypeEnum.hashCode();
+ } else {
+ return Objects.hashCode(this.value);
+ }
+ }
+
+ /**
+ * Returns the known enum value if this is a recognized MIME type.
+ *
+ * @return The known enum value
+ */
+ @ExcludeFromGeneratedCoverageReport
+ public Known knownEnum() {
+ return this.mimeTypeEnum;
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/Input.java b/src/main/java/com/google/genai/types/interactions/Input.java
new file mode 100644
index 00000000000..51ae38ea3cc
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/Input.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.interactions.content.Content;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Union type for interaction input. Can be a string, list of Content objects, or list of Turn
+ * objects.
+ */
+@JsonSerialize(using = InputSerializer.class)
+public final class Input extends JsonSerializable {
+ private final Object value;
+
+ private Input(Object value) {
+ this.value = value;
+ }
+
+ /**
+ * Creates an Input from a string.
+ *
+ * @param text The input text
+ * @return An Input instance wrapping the string
+ */
+ public static Input fromString(String text) {
+ return new Input(text);
+ }
+
+ /**
+ * Creates an Input from a single Content object.
+ *
+ * @param content The interaction content object
+ * @return An Input instance wrapping the content
+ */
+ public static Input fromContent(Content content) {
+ return new Input(content);
+ }
+
+ /**
+ * Creates an Input from a list of Content objects.
+ *
+ * @param contents The list of interaction content objects
+ * @return An Input instance wrapping the contents
+ */
+ public static Input fromContents(List contents) {
+ return new Input(contents);
+ }
+
+ /**
+ * Creates an Input from Content objects (varargs).
+ *
+ * @param contents The interaction content objects
+ * @return An Input instance wrapping the contents
+ */
+ public static Input fromContents(Content... contents) {
+ return new Input(Arrays.asList(contents));
+ }
+
+ /**
+ * Creates an Input from a list of Turn objects.
+ *
+ * @param turns The list of conversation turns
+ * @return An Input instance wrapping the turns
+ */
+ public static Input fromTurns(List turns) {
+ return new Input(turns);
+ }
+
+ /**
+ * Creates an Input from Turn objects (varargs).
+ *
+ * @param turns The conversation turns
+ * @return An Input instance wrapping the turns
+ */
+ public static Input fromTurns(Turn... turns) {
+ return new Input(Arrays.asList(turns));
+ }
+
+ /**
+ * Gets the underlying value.
+ *
+ * @return The wrapped value (String, List<Content>, or List<Turn>)
+ */
+ public Object getValue() {
+ return value;
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/InputSerializer.java b/src/main/java/com/google/genai/types/interactions/InputSerializer.java
new file mode 100644
index 00000000000..5ffa4409865
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/InputSerializer.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.google.genai.types.interactions.content.Content;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Custom serializer for Input that ensures proper polymorphic type information is included when
+ * serializing lists of Content or Turn objects.
+ *
+ * This is necessary because the @JsonValue annotation on a field typed as Object loses type
+ * information for contained elements. This serializer explicitly handles the different cases
+ * (String, List of Content, List of Turn) and ensures that polymorphic content types include their
+ * "type" property.
+ */
+public class InputSerializer extends JsonSerializer {
+
+ @Override
+ public void serialize(Input value, JsonGenerator gen, SerializerProvider serializers)
+ throws IOException {
+ Object innerValue = value.getValue();
+
+ if (innerValue == null) {
+ gen.writeNull();
+ } else if (innerValue instanceof String) {
+ // String input - write directly
+ gen.writeString((String) innerValue);
+ } else if (innerValue instanceof Content) {
+ // Single Content - serialize with type info
+ serializers.defaultSerializeValue(innerValue, gen);
+ } else if (innerValue instanceof List) {
+ // List input - serialize with proper type handling
+ List> list = (List>) innerValue;
+ gen.writeStartArray();
+ for (Object item : list) {
+ // Use the default serializer which respects @JsonTypeInfo on the item's class
+ serializers.defaultSerializeValue(item, gen);
+ }
+ gen.writeEndArray();
+ } else {
+ // Fallback for unknown types
+ serializers.defaultSerializeValue(innerValue, gen);
+ }
+ }
+}
diff --git a/src/main/java/com/google/genai/types/interactions/Interaction.java b/src/main/java/com/google/genai/types/interactions/Interaction.java
new file mode 100644
index 00000000000..de37f991351
--- /dev/null
+++ b/src/main/java/com/google/genai/types/interactions/Interaction.java
@@ -0,0 +1,380 @@
+/*
+ * Copyright 2025 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.
+ */
+
+package com.google.genai.types.interactions;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
+import com.google.genai.JsonSerializable;
+import com.google.genai.types.ExcludeFromGeneratedCoverageReport;
+import com.google.genai.types.HttpResponse;
+import com.google.genai.types.interactions.content.Content;
+import java.time.Instant;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Represents an interaction with a model or agent.
+ *
+ *
The Interactions API is available in both Vertex AI and Gemini API.
+ *
+ *
Note: The Interactions API is in beta and subject to change.
+ */
+@AutoValue
+@JsonDeserialize(builder = Interaction.Builder.class)
+public abstract class Interaction extends JsonSerializable {
+ /**
+ * Unique identifier for the interaction.
+ *
+ *
This field is always present in API responses and is required.
+ */
+ @JsonProperty("id")
+ public abstract String id();
+
+ /**
+ * The status of the interaction.
+ *
+ *
This field is always present in API responses and is required.
+ */
+ @JsonProperty("status")
+ public abstract InteractionStatus status();
+
+ /** The agent identifier (e.g., "deep-research-pro-preview-12-2025"). */
+ @JsonProperty("agent")
+ public abstract Optional agent();
+
+ /** The model used for the interaction. */
+ @JsonProperty("model")
+ public abstract Optional model();
+
+ /**
+ * The output content from the interaction.
+ *
+ * Note: Outputs use Content (discriminated union with type field), not the standard Content
+ * type with parts.
+ */
+ @JsonProperty("outputs")
+ public abstract Optional> outputs();
+
+ /** The ID of the previous interaction for conversation continuity. */
+ @JsonProperty("previous_interaction_id")
+ public abstract Optional previousInteractionId();
+
+ /** The role in the conversation. */
+ @JsonProperty("role")
+ public abstract Optional role();
+
+ /** The creation timestamp. */
+ @JsonProperty("created")
+ public abstract Optional created();
+
+ /** The last update timestamp. */
+ @JsonProperty("updated")
+ public abstract Optional updated();
+
+ /** Token usage statistics for the interaction. */
+ @JsonProperty("usage")
+ public abstract Optional usage();
+
+ /** Used to retain the full HTTP response. */
+ @JsonProperty("sdkHttpResponse")
+ public abstract Optional sdkHttpResponse();
+
+ /** Instantiates a builder for Interaction. */
+ @ExcludeFromGeneratedCoverageReport
+ public static Builder builder() {
+ return new AutoValue_Interaction.Builder();
+ }
+
+ /** Creates a builder with the same values as this instance. */
+ public abstract Builder toBuilder();
+
+ /** Builder for Interaction. */
+ @AutoValue.Builder
+ public abstract static class Builder {
+ /** For internal usage. Please use `Interaction.builder()` for instantiation. */
+ @JsonCreator
+ private static Builder create() {
+ return new AutoValue_Interaction.Builder();
+ }
+
+ /**
+ * Setter for id.
+ *
+ * id: Unique identifier for the interaction. This field is required.
+ */
+ @JsonProperty("id")
+ public abstract Builder id(String id);
+
+ /**
+ * Setter for status.
+ *
+ *
status: The status of the interaction. This field is required.
+ */
+ @JsonProperty("status")
+ public abstract Builder status(InteractionStatus status);
+
+ /**
+ * Setter for agent.
+ *
+ *
agent: The agent identifier.
+ */
+ @JsonProperty("agent")
+ public abstract Builder agent(String agent);
+
+ /** Internal setter for agent with Optional. */
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder agent(Optional agent);
+
+ /**
+ * Clear method for agent.
+ *
+ * Removes the agent field.
+ */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearAgent() {
+ return agent(Optional.empty());
+ }
+
+ /**
+ * Setter for model.
+ *
+ *
model: The model used for the interaction.
+ */
+ @JsonProperty("model")
+ public abstract Builder model(String model);
+
+ /** Internal setter for model with Optional. */
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder model(Optional model);
+
+ /**
+ * Clear method for model.
+ *
+ * Removes the model field.
+ */
+ @ExcludeFromGeneratedCoverageReport
+ @CanIgnoreReturnValue
+ public Builder clearModel() {
+ return model(Optional.empty());
+ }
+
+ /**
+ * Setter for outputs.
+ *
+ *
outputs: The output content from the interaction.
+ */
+ @JsonProperty("outputs")
+ public abstract Builder outputs(List outputs);
+
+ /**
+ * Setter for outputs (varargs convenience method).
+ *
+ * outputs: The output content from the interaction.
+ */
+ @CanIgnoreReturnValue
+ public Builder outputs(Content... outputs) {
+ return outputs(Arrays.asList(outputs));
+ }
+
+ /** Internal setter for outputs with Optional. */
+ @ExcludeFromGeneratedCoverageReport
+ abstract Builder outputs(Optional> outputs);
+
+ /**
+ * Clear method for outputs.
+ *
+ *