The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Add better handling image generation for gemini models
Sameer Kankute02510a908f38
diff --git a/litellm/llms/gemini/image_generation/transformation.py b/litellm/llms/gemini/image_generation/transformation.pyindex e79414394fa..2d8d82e6ad8 100644--- a/litellm/llms/gemini/image_generation/transformation.py+++ b/litellm/llms/gemini/image_generation/transformation.py@@ -21,12 +21,6 @@ else:LiteLLMLoggingObj = Any-FLASH_IMAGE_PREVIEW_MODEL_IDENTIFIERS = (- "2.0-flash-preview-image",- "2.0-flash-preview-image-generation",- "2.5-flash-image-preview",- "3-pro-image-preview",-)class GoogleImageGenConfig(BaseImageGenerationConfig):DEFAULT_BASE_URL: str = "https://generativelanguage.googleapis.com/v1beta"@@ -104,7 +98,7 @@ class GoogleImageGenConfig(BaseImageGenerationConfig):complete_url = complete_url.rstrip("/")# Gemini Flash Image Preview models use generateContent endpoint- if any(identifier in model for identifier in FLASH_IMAGE_PREVIEW_MODEL_IDENTIFIERS):+ if "gemini" in model:complete_url = f"{complete_url}/models/{model}:generateContent"else:# All other Imagen models use predict endpoint@@ -159,7 +153,7 @@ class GoogleImageGenConfig(BaseImageGenerationConfig):}"""# For Gemini Flash Image Preview models, use standard Gemini format- if any(identifier in model for identifier in FLASH_IMAGE_PREVIEW_MODEL_IDENTIFIERS):+ if "gemini" in model:request_body: dict = {"contents": [{@@ -218,7 +212,7 @@ class GoogleImageGenConfig(BaseImageGenerationConfig):model_response.data = []# Handle different response formats based on model- if any(identifier in model for identifier in FLASH_IMAGE_PREVIEW_MODEL_IDENTIFIERS):+ if "gemini" in model:# Gemini Flash Image Preview models return in candidates formatcandidates = response_data.get("candidates", [])for candidate in candidates: