diff --git a/backend/app/api/design_generator.py b/backend/app/api/design_generator.py index f7dd15e..ff19836 100644 --- a/backend/app/api/design_generator.py +++ b/backend/app/api/design_generator.py @@ -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: