Skip to content

Commit 5af717b

Browse files
committed
feat: add video modality support and document usage with Gemini Omni Flash
1 parent 5a277f9 commit 5af717b

3 files changed

Lines changed: 126 additions & 1 deletion

File tree

BLOG.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: "Generating Media with Nano Banana 2 Lite and Gemini Omni Flash in Java"
3+
date: 2026-06-30T20:00:00+02:00
4+
draft: false
5+
tags: ["Java", "Gemini", "AI", "Generative AI"]
6+
categories: ["Programming"]
7+
---
8+
9+
Google just announced the launch of some incredibly exciting new models: **Nano Banana 2 Lite** (the fastest, most cost-efficient Gemini Image model yet) and **Gemini Omni Flash** for high-quality video and conversational editing. You can read all about the announcement on the [Google Blog](https://blog.google/innovation-and-ai/models-and-research/gemini-models/gemini-omni-flash-nano-banana-2-lite/).
10+
11+
As soon as I saw the news, I couldn't wait to get my hands dirty. I wanted to see how easy it would be to generate images and videos using the [Gemini Interactions API Java SDK](https://github.com/glaforge/gemini-interactions-api-sdk).
12+
13+
Spoiler alert: it's incredibly simple! In this post, I'll walk you through how to invoke both of these models to generate an image and a video natively in Java.
14+
15+
## Setting Up
16+
17+
First, make sure you have the Gemini Interactions API SDK in your project. If you're using Maven, just add the dependency:
18+
19+
```xml
20+
<dependency>
21+
<groupId>io.github.glaforge</groupId>
22+
<artifactId>gemini-interactions-api-sdk</artifactId>
23+
<version>0.11.0</version>
24+
</dependency>
25+
```
26+
27+
Also, ensure that your `GEMINI_API_KEY` environment variable is set.
28+
29+
## Generating an Image with Nano Banana 2 Lite
30+
31+
The model identifier for the new image model is `gemini-3.1-flash-lite-image`. Generating an image is as simple as creating a `ModelInteractionParams` request, specifying the `IMAGE` response modality, and extracting the binary data from the interaction.
32+
33+
```java
34+
import io.github.glaforge.gemini.interactions.GeminiInteractionsClient;
35+
import io.github.glaforge.gemini.interactions.model.*;
36+
import io.github.glaforge.gemini.interactions.model.InteractionParams.ModelInteractionParams;
37+
import io.github.glaforge.gemini.interactions.model.Interaction.Modality;
38+
import java.nio.file.Files;
39+
import java.nio.file.Paths;
40+
41+
public class MediaGenerator {
42+
public static void main(String[] args) throws Exception {
43+
// Initialize the client
44+
GeminiInteractionsClient client = GeminiInteractionsClient.builder()
45+
.apiKey(System.getenv("GEMINI_API_KEY"))
46+
.build();
47+
48+
// Prepare the image request
49+
ModelInteractionParams imageRequest = ModelInteractionParams.builder()
50+
.model("gemini-3.1-flash-lite-image")
51+
.input("A highly detailed realistic banana wearing sunglasses on a beach")
52+
.responseModalities(Modality.IMAGE)
53+
.build();
54+
55+
// Execute the interaction and save the image
56+
Interaction imageInteraction = client.create(imageRequest);
57+
58+
if (imageInteraction.outputImage() != null) {
59+
byte[] imageData = imageInteraction.outputImage().data();
60+
Files.write(Paths.get("nano-banana.png"), imageData);
61+
System.out.println("Image saved successfully!");
62+
}
63+
}
64+
}
65+
```
66+
67+
## Generating a Video with Gemini Omni Flash
68+
69+
The video generation process is practically identical! The model identifier for Omni Flash is `gemini-omni-flash-preview`. We simply switch the model name and update the `responseModalities` to `Modality.VIDEO`.
70+
71+
*Note: You may need to ensure you're on the absolute latest version of the SDK to support the `VIDEO` modality!*
72+
73+
```java
74+
// Prepare the video request
75+
ModelInteractionParams videoRequest = ModelInteractionParams.builder()
76+
.model("gemini-omni-flash-preview")
77+
.input("A banana jumping into a pool of water")
78+
.responseModalities(Modality.VIDEO)
79+
.build();
80+
81+
// Execute the interaction and save the video
82+
Interaction videoInteraction = client.create(videoRequest);
83+
84+
if (videoInteraction.outputVideo() != null) {
85+
byte[] videoData = videoInteraction.outputVideo().data();
86+
Files.write(Paths.get("omni-banana.mp4"), videoData);
87+
System.out.println("Video saved successfully!");
88+
}
89+
```
90+
91+
## The Results!
92+
93+
With just a few lines of Java code, the SDK abstracts away all the HTTP calls and multipart response parsing, giving you the direct byte arrays for your generated media.
94+
95+
*(If you are following along, don't forget to embed the generated `nano-banana.png` and `omni-banana.mp4` files here to show off the results!)*
96+
97+
The Interactions API keeps getting more powerful, and the Java SDK is keeping right up with it. Let me know what you end up building with Nano Banana 2 Lite and Omni Flash!

skills/gemini-interactions-java-api/SKILL.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,32 @@ if (image != null) {
104104
}
105105
```
106106

107+
### Multimodal Video Generation (Gemini Omni Flash)
108+
109+
Generate videos and extract the video data.
110+
111+
```java
112+
import io.github.glaforge.gemini.interactions.GeminiInteractionsClient;
113+
import io.github.glaforge.gemini.interactions.model.*;
114+
import io.github.glaforge.gemini.interactions.model.Content.*;
115+
import io.github.glaforge.gemini.interactions.model.InteractionParams.ModelInteractionParams;
116+
import io.github.glaforge.gemini.interactions.model.Interaction.Modality;
117+
118+
GeminiInteractionsClient client = GeminiInteractionsClient.builder().apiKey(System.getenv("GEMINI_API_KEY")).build();
119+
120+
ModelInteractionParams request = ModelInteractionParams.builder()
121+
.model("gemini-omni-flash-preview")
122+
.input("A highly detailed cinematic shot of a futuristic banana.")
123+
.responseModalities(Modality.VIDEO)
124+
.build();
125+
126+
Interaction interaction = client.create(request);
127+
Content.VideoContent video = interaction.outputVideo();
128+
if (video != null) {
129+
System.out.println("Video generated with " + video.data().length + " bytes.");
130+
}
131+
```
132+
107133
### Stateful Conversation (Multi-Turn)
108134

109135
Use `store(true)` to persist the conversation in the cloud, and `previousInteractionId` to continue the thread.

src/main/java/io/github/glaforge/gemini/interactions/model/Interaction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ public enum Modality {
229229
/** Image modality. */
230230
@JsonProperty("image") IMAGE,
231231
/** Audio modality. */
232-
@JsonProperty("audio") AUDIO
232+
@JsonProperty("audio") AUDIO,
233+
/** Video modality. */
234+
@JsonProperty("video") VIDEO
233235
}
234236

235237
/**

0 commit comments

Comments
 (0)