{"slug": "imagen-4-api-is-dead-heres-the-complete-migration-fix", "title": "Imagen 4 API Is Dead. Here’s the Complete Migration Fix.", "summary": "Google killed three Imagen 4 API endpoints on August 17, 2026, breaking production apps that call generate_images() with model IDs imagen-4.0-generate-001, imagen-4.0-fast-generate-001, or imagen-4.0-ultra-generate-001. The migration is not a drop-in swap: developers must switch to client.models.generate_content(), handle a new response structure, and loop for multiple images. Google's earlier guidance pointed to gemini-2.5-flash-image, which retires on October 2, 2026, so developers should migrate directly to gemini-3.1-flash-image (Nano Banana 2) or gemini-3.1-flash-lite-image (Nano Banana 2 Lite), both GA with no announced retirement date.", "body_md": "Google killed three Imagen 4 API endpoints on August 17. If your production app calls `generate_images()`\n\nwith any of those model IDs, it is throwing a hard error right now — not a deprecation warning, not a graceful fallback. A hard stop. And if you migrated to `gemini-2.5-flash-image`\n\nbased on Google’s earlier guidance, you have six weeks before that one dies too. Here is the complete fix.\n\n## What Google Shut Down\n\nThree endpoints died on August 17, 2026:\n\n`imagen-4.0-generate-001`\n\n(Standard, $0.040/image)`imagen-4.0-fast-generate-001`\n\n(Fast, $0.020/image)`imagen-4.0-ultra-generate-001`\n\n(Ultra, $0.060/image)\n\nVertex AI users saw these deprecated in March. Gemini API users hit the wall yesterday. Run a codebase audit now — search for `generate_images`\n\n, `imagen-4.0`\n\n, and `GenerateImagesConfig`\n\n.\n\n## The Migration Is Not a Drop-In Swap\n\nThree things changed at the API level. Miss any of them and you ship broken code.\n\n**1. The method is gone.** `client.models.generate_images()`\n\ndoes not exist on Gemini image models. Switch to `client.models.generate_content()`\n\n.\n\n**2. The response structure changed.** `response.generated_images`\n\nis gone. Iterate over `response.candidates[0].content.parts`\n\nand check each part for `inline_data`\n\n.\n\n**3. Multiple images require a loop.** There is no direct equivalent to `number_of_images=4`\n\nin the same request shape. Call in a loop or check whether your target model supports the `n`\n\nconfig parameter.\n\nHere is a minimal before-and-after:\n\n### Old Code (Broken as of August 17)\n\n``` python\nfrom google import genai\nfrom google.genai import types\n\nclient = genai.Client()\nresponse = client.models.generate_images(\n    model='imagen-4.0-generate-001',\n    prompt='A photo of a golden retriever on a beach',\n    config=types.GenerateImagesConfig(number_of_images=1),\n)\nresponse.generated_images[0].image.save('output.png')\n```\n\n### New Code (Working with Gemini 3.1 Flash Image)\n\n``` python\nfrom google import genai\nfrom google.genai.types import GenerateContentConfig, Modality\nfrom PIL import Image\nfrom io import BytesIO\n\nclient = genai.Client()\nresponse = client.models.generate_content(\n    model=\"gemini-3.1-flash-image\",\n    contents=\"A photo of a golden retriever on a beach\",\n    config=GenerateContentConfig(response_modalities=[Modality.IMAGE]),\n)\nfor part in response.candidates[0].content.parts:\n    if part.inline_data is not None:\n        image = Image.open(BytesIO(part.inline_data.data))\n        image.save(\"output.png\")\n```\n\nFirebase AI Logic users have a separate migration path — check [Google’s Firebase migration guide](https://firebase.google.com/docs/ai-logic/imagen-models-migration) for the SDK-specific calls.\n\n## Do Not Stop at Gemini 2.5 Flash Image\n\nGoogle’s initial migration guidance pointed at `gemini-2.5-flash-image`\n\n. That model retires on **October 2, 2026** — 44 days from now. If you migrate to it today, you are doing this again in six weeks.\n\nGo directly to `gemini-3.1-flash-image`\n\n(Nano Banana 2) or `gemini-3.1-flash-lite-image`\n\n(Nano Banana 2 Lite). Both are GA with no announced retirement date. [Google’s model retirement tracker](https://vorplabs.com/models/google-model-retirements) is worth bookmarking if you run multiple Google AI integrations.\n\n## Which Model Is Right for Your Workload\n\nTwo real options:\n\n| Model | Price (1K img) | Speed | Max Res | Status |\n|---|---|---|---|---|\n`gemini-3.1-flash-image` | $0.067 | ~10s | 4K | GA — safe |\n`gemini-3.1-flash-lite-image` | $0.034 | ~4s | 1K | GA — safe |\n`gemini-3.1-flash-image` (Batch) | $0.034 | async | 4K | GA — safe |\n`gemini-2.5-flash-image` | ~$0.050 | ~7s | 2K | Retires Oct 2 |\n\n**Gemini 3.1 Flash Image** is the full-quality target. Four-K output, 14 aspect ratios, multi-subject consistency across up to five characters, native world knowledge. List price is approximately $0.067 per 1K-resolution image. Run it through the [Batch API](https://ai.google.dev/gemini-api/docs/pricing) and the price drops to $0.034 with async delivery.\n\n**Gemini 3.1 Flash Lite Image** is the budget option. At $0.034 per image, it is cheaper than old Imagen 4 Standard ($0.040) and roughly matches what Imagen 4 Fast cost in bulk. Outputs cap at 1K resolution, text rendering is weaker on small fonts, and there is no Search grounding. For draft generation, thumbnail pipelines, or high-volume preview workflows, it earns its place.\n\nAt standard resolution, real-time, Nano Banana 2 costs 67% more than Imagen 4 Standard used to. That is the honest number. There is no GA equivalent to Imagen 4 Fast’s $0.020 price point. Nano Banana 2 Lite closes the gap and brings you a stable model in return.\n\n## The Quick Decision\n\nFinal-quality images, full resolution, or conversational image editing: use `gemini-3.1-flash-image`\n\n. High-volume previews, drafts, or anything where 1K is sufficient: use `gemini-3.1-flash-lite-image`\n\n. Need full quality at Imagen 4 Standard pricing: use Nano Banana 2 through the Batch API.\n\nEither way, migrate once to a 3.1 model and you are on GA with no announced sunset. That stability is worth the extra cost over the alternative — staying on Gemini 2.5 Flash Image and scheduling the same migration for October.\n\nFor the full list of changes in the Gemini API across all model types, the [official Gemini API changelog](https://ai.google.dev/gemini-api/docs/changelog) is the authoritative source.", "url": "https://wpnews.pro/news/imagen-4-api-is-dead-heres-the-complete-migration-fix", "canonical_source": "https://byteiota.com/imagen-4-api-is-dead-heres-the-complete-migration-fix/", "published_at": "2026-08-18 10:21:41+00:00", "updated_at": "2026-08-18 10:42:46.265126+00:00", "lang": "en", "topics": ["artificial-intelligence", "generative-ai", "ai-products", "developer-tools"], "entities": ["Google", "Imagen 4", "Vertex AI", "Gemini API", "gemini-2.5-flash-image", "gemini-3.1-flash-image", "gemini-3.1-flash-lite-image", "Firebase AI Logic"], "alternates": {"html": "https://wpnews.pro/news/imagen-4-api-is-dead-heres-the-complete-migration-fix", "markdown": "https://wpnews.pro/news/imagen-4-api-is-dead-heres-the-complete-migration-fix.md", "text": "https://wpnews.pro/news/imagen-4-api-is-dead-heres-the-complete-migration-fix.txt", "jsonld": "https://wpnews.pro/news/imagen-4-api-is-dead-heres-the-complete-migration-fix.jsonld"}}