Migrate from Imagen to a Gemini Image model ("Nano Banana")


All Imagen models are deprecated and will shut down as early as August 17, 2026. This deprecation and shutdown is applicable across Google and for both the Gemini Developer API and Agent Platform Gemini API (formerly Vertex AI).

Before this shutdown date, to avoid service disruption, you should migrate your apps from using Imagen models to using Gemini 3.x Image models (the "Nano Banana" models), as described in this guide.

If you have an urgent issue involving this deprecation and shutdown, reach out to Firebase Support.

Replacement Gemini Image models

Review the following table to choose a replacement Gemini 3.x Image model for your app.

Imagen model Gemini 3.x Image models ("Nano Banana")
imagen-4.0-fast-generate-001 gemini-3.1-flash-image (with thinking level MINIMAL)
imagen-4.0-generate-001 gemini-3.1-flash-image (with thinking level HIGH)
imagen-4.0-ultra-generate-001 gemini-3-pro-image
imagen-3.0-capability-001 gemini-3.1-flash-image

Migrate your app

This section shows before and after examples for migrating from an Imagen model to a Gemini Image model.

Generate an image from text

Click your Gemini API provider to view provider-specific content and code on this page.

To generate an image from text, migrate your app by making the following changes:

  • Use an appropriate replacement Gemini Image model (such as gemini-3.1-flash-image).

  • Create a GenerativeModel instance (instead of an ImagenModel instance).

  • Update the model configuration options to accommodate Gemini Image models.

    • As part of this configuration, set a response modality of IMAGE.
      Note that Gemini Image models can be configured to return both images and text.

Swift

Before


import FirebaseAILogic

// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())

// Create an `ImagenModel` instance with a model that supports your use case.
let model = ai.imagenModel(modelName: "IMAGEN_MODEL_NAME")

// Provide an image generation prompt.
let prompt = "An astronaut riding a horse"

// To generate an image, call `generateImages` with the text prompt.
let response = try await model.generateImages(prompt: prompt)

// Handle the generated image.
guard let image = response.images.first else {
  fatalError("No image in the response.")
}
let uiImage = UIImage(data: image.data)

After


import FirebaseAILogic

// Initialize the Gemini Developer API backend service.
let ai = FirebaseAI.firebaseAI(backend: .googleAI())

// Create a `GenerativeModel` instance with a Gemini model that supports image output.
let model = ai.generativeModel(
  modelName: "GEMINI_IMAGE_MODEL_NAME",
  generationConfig: GenerationConfig(
    responseModalities: [.image],
    imageConfig: ImageConfig(aspectRatio: .landscape4x3)
  )
)

// Provide an image generation prompt.
let prompt = "An astronaut riding a horse"

// To generate an image, call `generateContent` with the text prompt.
let response = try await model.generateContent(prompt)

// Handle the case where no images were generated.
guard let inlineDataPart = response.inlineDataParts.first else {
  fatalError("No image in the response.")
}

// Process the image.
guard let uiImage = UIImage(data: inlineDataPart.data) else {
  fatalError("Failed to convert data to UIImage.")
}

Kotlin

Before


// Initialize the Gemini Developer API backend service.
val ai = Firebase.ai(backend = GenerativeBackend.googleAI())

// Create an `ImagenModel` instance with an Imagen model that supports your use case.
val model = ai.imagenModel("IMAGEN_MODEL_NAME")

// Provide an image generation prompt.
val prompt = "An astronaut riding a horse"

// To generate an image, call `generateImages` with the text prompt.
val imageResponse = model.generateImages(prompt)

// Handle the generated image.
val image = imageResponse.images.first()

val bitmapImage = image.asBitmap()

After


// Initialize the Gemini Developer API backend service.
val ai = Firebase.ai(backend = GenerativeBackend.googleAI())

// Create a `GenerativeModel` instance with a Gemini model that supports image output.
val model = ai.generativeModel(
    modelName = "GEMINI_IMAGE_MODEL_NAME",
    generationConfig = generationConfig {
      responseModalities = listOf