Support direct GCS output (storageUri) for 'gemini-2.5-flash-image' to prevent OOM in high concurrency
I maintainer di solito rispondono entro 1 giorno
@hemasekhar-p ci sta già lavorando.
Dal 15/12/2025.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
SDK Version
1.21.0
Model Used
gemini-2.5-flash-image
Description
I am using the google-genai SDK to generate images using the gemini-2.5-flash-image model via the client.models.generateContent method.
Currently, the SDK returns the generated image directly as raw bytes (inline data) in the response memory. While this works for single requests, it causes significant memory pressure (OOM) in high-concurrency scenarios because the application server must hold multiple large image buffers in the heap before uploading them to storage (e.g., S3/GCS).
In the legacy Vertex AI Imagen API (e.g., imagen-3.0), we could provide a storageUri parameter to instruct the model to write the output directly to Google Cloud Storage (GCS), returning only the URI. This allowed for "zero-copy" handling on the client side.
My question is:
Is there a way to configure a GCS destination (similar to storageUri or outputConfig) in GenerateContentConfig for Gemini image generation models? If not, are there any plans to support this feature?
Current Code Implementation
Here is how I am currently calling the API. The imageByte array is the bottleneck.
public GoogleVertexAiResponse imageGenByNanoBanana(GoogleVertexAiRequest aiRequest){
// ... validation logic ...
GenerateContentConfig.Builder contentConfigBuilder =
GenerateContentConfig.builder()
.candidateCount(1)
.httpOptions(HttpOptions.builder()
.apiVersion("v1")
.timeout(60000)
.build());
if(!StringUtils.isEmpty(aiRequest.getAspectRatio())){
contentConfigBuilder.imageConfig(ImageConfig.builder()
.aspectRatio(aiRequest.getAspectRatio())
.build());
}
GenerateContentConfig contentConfig = contentConfigBuilder.build();
try {
// The response contains the full image bytes in memory
GenerateContentResponse response =
client.models.generateContent(
aiRequest.getModelVersion(), // gemini-2.5-flash-image
aiRequest.getPrompt(),
contentConfig);
List<Part> parts =
response
.candidates()
.flatMap(candidates -> candidates.stream().findFirst())
.flatMap(Candidate::content)
.flatMap(Content::parts)
.orElse(new ArrayList<>());
byte[] imageByte = null;
for(Part part: parts){
// Memory bottleneck here:
if(part.inlineData().flatMap(Blob::data).isPresent()){
imageByte = part.inlineData().flatMap(Blob::data).get();
break;
}
}
// ... upload logic ...
} catch (Exception e){
log.error("Google Vertex Ai Image Gen Occur An Error: {}", e.getMessage(), e);
return handleException(e);
}
}
Expected Behavior
I would like to be able to specify a GCS URI in the config so that the response returns a reference to the file instead of the raw bytes.
Example (Hypothetical):
GenerateContentConfig.builder()
.imageConfig(ImageConfig.builder()
.storageUri("gs://my-bucket/output/") // feature request
.build())
.build();
Thanks
- Lingua principale
- Java
- Stelle
- 398
- Fork
- 126
- Merge medio
- 1g 12h
- PR unite (30g)
- 71
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di googleapis/java-genai
-
ResponseStream.close() can block on the reader lock before closing the HTTP responseForse già presa @hirematha l’ha presa 1 giorno fa. Apertapriority: p2 type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
googleapis/java-genai#1372 ·
I maintainer di solito rispondono entro 1 giorno
-
Interactions API: GaosClientException.getMessage() only returns "400 . API error occurred" and omits the server error detailsForse già presa @hemasekhar-p l’ha presa 25 giorni fa. Apertapriority: p2 type: bug
googleapis/java-genai#1282 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Interactions API: store(false) omits "id", breaking Interaction and InteractionCompletedEvent deserializationForse già presa @hemasekhar-p l’ha presa 25 giorni fa. Apertapriority: p2 type: bug
googleapis/java-genai#1281 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Interaction.outputText() always returns Optional.empty() (SDK-computed field is never populated)Forse già presa @hemasekhar-p l’ha presa 25 giorni fa. Apertapriority: p2 type: bug
googleapis/java-genai#1280 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Gen AI with structured output - `propertyOrdering` in Python vs. Java implementationsForse già presa @hemasekhar-p l’ha presa 79 giorni fa. Apertapriority: p3 type: feature request
googleapis/java-genai#1169 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di googleapis/java-genai
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
I maintainer di solito rispondono entro 2 giorni
-
code-health feature/sync OS/Android QA/Test-Plan-Specified QA/Yes
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
brave/brave-browser#60327 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
aws/context-ontology-accelerator#325 ·
I maintainer di solito rispondono entro 1 giorno
-
The README tells to run `mvn jeo:disassemble`, which fails with `No plugin found for prefix 'jeo'`Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
objectionary/jeo-maven-plugin#1938 ·
I maintainer di solito rispondono entro 2 giorni
-
effort/l priority/p2 risk/high triage/deferred
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
iflytek/skillhub#1039 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno