Description
When calling /v1/images/generations with a Gemini image generation model (e.g. gemini-3.1-flash-image-preview) through a Vertex provider, the request returns HTTP 404.
This works correctly when using the gemini provider (direct API key), but fails with the vertex provider (service account).
Root Cause
Three issues in the engine routing and payload construction:
1. Engine override in get_engine() (core/utils.py ~line 201)
if engine != "gemini" and (endpoint == "/v1/images/generations" or "stable-diffusion" in original_model):
engine = "dalle"
This forces vertex-gemini → dalle. The dalle handler then constructs URL https://aiplatform.googleapis.com/images/generations — a path that doesn't exist on Vertex AI → 404.
Fix: engine not in ("gemini", "vertex-gemini")
2. Missing prompt→messages conversion in get_vertex_gemini_payload() (core/request.py)
ImageGenerationRequest has a prompt field, not messages. The get_gemini_payload() handler already has this fallback:
try:
request_messages = [Message(role="user", content=request.prompt)]
except Exception:
request_messages = copy.deepcopy(request.messages)
But get_vertex_gemini_payload() goes straight to request.messages, which crashes for image generation requests.
3. Missing responseModalities for image models
Gemini image generation models require "responseModalities": ["TEXT", "IMAGE"] in generationConfig to return images. This is not set for -image-preview models in either the gemini or vertex-gemini payload builders.
Steps to Reproduce
- Configure a Vertex provider with
gemini-3.1-flash-image-preview (or gemini-2.5-flash-image-preview)
- POST to
/v1/images/generations:
{
"model": "gemini-3.1-flash-image-preview",
"prompt": "A cute cat wearing a tiny hat"
}
- Observe 404 error
Logs
provider: vertex model: gemini-3.1-flash-image-preview engine: dalle role: xxx
Error 404 with provider vertex API key: None: <!DOCTYPE html>...Error 404 (Not Found)!!1...
After fix, engine correctly stays as vertex-gemini and returns 200:
provider: vertex model: gemini-3.1-flash-image-preview engine: vertex-gemini role: xxx
POST /v1/images/generations HTTP/1.1" 200 OK
Environment
- uni-api version: 1.7.53 (
yym68686/uni-api:latest)
- Provider: Vertex AI (service account with
project_id, client_email, private_key)
Description
When calling
/v1/images/generationswith a Gemini image generation model (e.g.gemini-3.1-flash-image-preview) through a Vertex provider, the request returns HTTP 404.This works correctly when using the
geminiprovider (direct API key), but fails with thevertexprovider (service account).Root Cause
Three issues in the engine routing and payload construction:
1. Engine override in
get_engine()(core/utils.py~line 201)This forces
vertex-gemini→dalle. Thedallehandler then constructs URLhttps://aiplatform.googleapis.com/images/generations— a path that doesn't exist on Vertex AI → 404.Fix:
engine not in ("gemini", "vertex-gemini")2. Missing prompt→messages conversion in
get_vertex_gemini_payload()(core/request.py)ImageGenerationRequesthas apromptfield, notmessages. Theget_gemini_payload()handler already has this fallback:But
get_vertex_gemini_payload()goes straight torequest.messages, which crashes for image generation requests.3. Missing
responseModalitiesfor image modelsGemini image generation models require
"responseModalities": ["TEXT", "IMAGE"]ingenerationConfigto return images. This is not set for-image-previewmodels in either the gemini or vertex-gemini payload builders.Steps to Reproduce
gemini-3.1-flash-image-preview(orgemini-2.5-flash-image-preview)/v1/images/generations:{ "model": "gemini-3.1-flash-image-preview", "prompt": "A cute cat wearing a tiny hat" }Logs
After fix, engine correctly stays as
vertex-geminiand returns 200:Environment
yym68686/uni-api:latest)project_id,client_email,private_key)