fix: use correct Gemini model for image generation (gemini-3-pro-image-preview)

This commit is contained in:
Jeff Emmett 2026-01-30 11:57:54 +00:00
parent cf347dfdf8
commit 0724566c05
1 changed files with 9 additions and 6 deletions

View File

@ -77,26 +77,27 @@ Square format, clean edges for die-cut sticker."""
# Call Gemini API for image generation
try:
async with httpx.AsyncClient(timeout=120.0) as client:
# Use gemini-3-pro-image-preview for image generation
response = await client.post(
f"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?key={gemini_api_key}",
f"https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent?key={gemini_api_key}",
json={
"contents": [{
"parts": [{
"text": f"Generate an image: {style_prompt}"
"text": style_prompt
}]
}],
"generationConfig": {
"responseModalities": ["image", "text"],
"responseMimeType": "image/png"
"responseModalities": ["image", "text"]
}
},
headers={"Content-Type": "application/json"}
)
if response.status_code != 200:
error_detail = response.text[:500] if response.text else "Unknown error"
raise HTTPException(
status_code=502,
detail=f"AI generation failed: {response.text}"
detail=f"AI generation failed ({response.status_code}): {error_detail}"
)
result = response.json()
@ -112,9 +113,11 @@ Square format, clean edges for die-cut sticker."""
break
if not image_data:
# Log what we got for debugging
import json
raise HTTPException(
status_code=502,
detail="AI did not return an image"
detail=f"AI did not return an image. Response: {json.dumps(result)[:500]}"
)
except httpx.TimeoutException: