Skip to content

[Bug] Vertex provider + /v1/images/generations returns 404 for Gemini image models #170

Description

@kkliah

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-geminidalle. 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

  1. Configure a Vertex provider with gemini-3.1-flash-image-preview (or gemini-2.5-flash-image-preview)
  2. POST to /v1/images/generations:
{
  "model": "gemini-3.1-flash-image-preview",
  "prompt": "A cute cat wearing a tiny hat"
}
  1. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions