Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Support direct GCS output (storageUri) for 'gemini-2.5-flash-image' to prevent OOM in high concurrency

Aperta
#737 2 commenti 0 reazioni 1 assegnatario Vedi su GitHub

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

priority: p3 type: feature request
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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di googleapis/java-genai

Tutte le issue di googleapis/java-genai

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.