--- a/scripts/generate_image.py +++ b/scripts/generate_image.py @@ -22,7 +22,7 @@ import httpx OPENROUTER_API_URL = "https://openrouter.ai/api/v1/chat/completions" -MODEL = "google/gemini-3-pro-image-preview" +MODEL = "google/gemini-2.5-flash-image" RESOLUTION_MAP = { "1K": "1024x1024", @@ -80,7 +80,6 @@ "model": MODEL, "messages": messages, "max_tokens": 4096, - "response_format": {"type": "image"}, } res_dims = RESOLUTION_MAP.get(resolution) @@ -100,6 +99,16 @@ for choice in data.get("choices", []): msg = choice.get("message", {}) + + # Handle images array in message (e.g., Gemini 2.5 flash image) + msg_images = msg.get("images", []) + for img_obj in msg_images: + if isinstance(img_obj, dict) and img_obj.get("type") == "image_url": + url = img_obj.get("image_url", {}).get("url", "") + if url.startswith("data:"): + b64_str = url.split(",", 1)[1] + images.append(base64.standard_b64decode(b64_str)) + content = msg.get("content") if isinstance(content, list): @@ -119,8 +128,10 @@ pass if not images: + import json print("Error: no images returned by the model.", file=sys.stderr) - print(f"Response: {data}", file=sys.stderr) + print(f"Full response structure:", file=sys.stderr) + print(json.dumps(data, indent=2, default=str)[:5000], file=sys.stderr) sys.exit(1) return images