From ac045ee2d22d9e1b87d3d0843a2cccccd5a90056 Mon Sep 17 00:00:00 2001 From: Harsh Raj <42068222+Harshraj9812@users.noreply.github.com> Date: Sun, 14 Sep 2025 14:23:18 +0530 Subject: [PATCH] Fix for Gemini Image Generation using Nano Banana https://ai.google.dev/gemini-api/docs/image-generation?authuser=1#rest --- backend/open_webui/routers/images.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/backend/open_webui/routers/images.py b/backend/open_webui/routers/images.py index 802a3e9924..5be4137e38 100644 --- a/backend/open_webui/routers/images.py +++ b/backend/open_webui/routers/images.py @@ -586,17 +586,15 @@ async def image_generations( model = get_image_model(request) data = { - "instances": {"prompt": form_data.prompt}, - "parameters": { - "sampleCount": form_data.n, - "outputOptions": {"mimeType": "image/png"}, - }, + "prompt": {"text": form_data.prompt}, + "samples": form_data.n } + # Use asyncio.to_thread for the requests.post call r = await asyncio.to_thread( requests.post, - url=f"{request.app.state.config.IMAGES_GEMINI_API_BASE_URL}/models/{model}:predict", + url=f"{request.app.state.config.IMAGES_GEMINI_API_BASE_URL}/models/{model}:generateImage?key={request.app.state.config.IMAGES_GEMINI_API_KEY}", json=data, headers=headers, ) @@ -605,9 +603,9 @@ async def image_generations( res = r.json() images = [] - for image in res["predictions"]: + for image in res.get("images", []): image_data, content_type = load_b64_image_data( - image["bytesBase64Encoded"] + image["imageBytes"] ) url = upload_image(request, image_data, content_type, data, user) images.append({"url": url})