Support direct GCS output (storageUri) for 'gemini-2.5-flash-image' to prevent OOM in high concurrency
维护者通常 1 天内回复
@hemasekhar-p 已经在做这个了。
开始于 2025年12月15日。
评估
这个 Issue 还没有评估数据。
描述
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
- 主要语言
- Java
- 星标
- 398
- 派生
- 126
- 平均合并
- 1 天 12 小时
- 30 天内合并 PR
- 71
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
googleapis/java-genai 的其他 Issue
-
ResponseStream.close() can block on the reader lock before closing the HTTP response可能已有人在做 @hirematha 于 2 天前认领。 未关闭priority: p2 type: bug
难度 2/5 1-3 小时 新手友好度 68/100
googleapis/java-genai#1372 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Interactions API: GaosClientException.getMessage() only returns "400 . API error occurred" and omits the server error details可能已有人在做 @hemasekhar-p 于 26 天前认领。 未关闭priority: p2 type: bug
googleapis/java-genai#1282 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Interactions API: store(false) omits "id", breaking Interaction and InteractionCompletedEvent deserialization可能已有人在做 @hemasekhar-p 于 26 天前认领。 未关闭priority: p2 type: bug
googleapis/java-genai#1281 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Interaction.outputText() always returns Optional.empty() (SDK-computed field is never populated)可能已有人在做 @hemasekhar-p 于 26 天前认领。 未关闭priority: p2 type: bug
googleapis/java-genai#1280 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Gen AI with structured output - `propertyOrdering` in Python vs. Java implementations可能已有人在做 @hemasekhar-p 于 80 天前认领。 未关闭priority: p3 type: feature request
googleapis/java-genai#1169 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 googleapis/java-genai 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
quarkusio/quarkus-agent-mcp#302 ·
维护者通常 2 天内回复
-
build
难度 1/5 1 小时以内 新手友好度 85/100
MetricsHub/metricshub-community#1472 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
IdentityArrayObjectSet iterator remove may throw ArrayIndexOutOfBoundsException可能已有人在做 @jiteshkhatri11 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
javapathfinder/jpf-core#660 · 1 条评论 ·