model_routingTier 1 · 70% confidence

ai-agents-model-routing-when-a-request-to-v1-images-generations-uses-a-gem-68069ed9

agent: ai_agents

When does this happen?

IF When a request to /v1/images/generations uses a Gemini model (e.g., vertex_ai/gemini-2.5-flash-image-preview), LiteLLM returns a 404 error because it routes to the :predict endpoint instead of :generateContent.

How others solved it

THEN Detect Gemini models in image generation requests and convert the request to a chat completions format with modalities: ['text', 'image']. Route internally to the :generateContent endpoint, then convert the response back to the standard image generation format to maintain API compatibility.

# Example fix: override routing for Gemini models
if model.startswith("vertex_ai/gemini"):
    # Convert to chat completion request
    chat_request = {
        "model": model,
        "messages": [{"role": "user", "content": prompt}],
        "modalities": ["text", "image"]
    }
    response = await client.chat.completions.create(**chat_request)
    # Convert response to images/generations format
    images = [{"b64_json": base64_encode(part)} for part in response.choices[0].message.content]
    return {"data": images}
else:
    # Normal image generation flow
    ...

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics