Imagen on Vertex AI | AI Image Generator

Imagen on Vertex AI brings Google's state of the art image generative AI capabilities to application developers. With Imagen on Vertex AI, application developers can build next-generation AI products that transform their user's imagination into high quality visual assets using AI generation, in seconds.

Try image generation (Vertex AI Studio)

Try Imagen in a Colab

With Imagen, you can do the following:

  • Generate novel images using only a text prompt (text-to-image AI generation).
  • Edit or expand an uploaded or generated image using a mask area you define.
  • Upscale existing, generated, or edited images.

Prompts for preceding images

These images are generated using the general Imagen 3 image generation model (imagen-3.0-generate-002) and the following prompts:

  1. Claymation scene. A medium wide shot of an elderly woman. She is wearing flowing clothing. She is standing in a lush garden watering the plants with an orange watering can
  2. Shot in the style of DSLR camera with the polarizing filter. A photo of two hot air balloons over the unique rock formations in Cappadocia, Turkey. The colors and patterns on these balloons contrast beautifully against the earthy tones of the landscape below. This shot captures the sense of adventure that comes with enjoying such an experience.
  3. A weathered, wooden mech robot covered in flowering vines stands peacefully in a field of tall wildflowers, with a a small blue bird resting on its outstrecteched hand. Digital Cartoon, with warm colors and soft lines. A large cliff with a waterfall looms behind.
  4. A view of a person's hand as they hold a little clay figurine of a bird in their hand and sculpt it with a modeling tool in their other hand. You can see the sculptor's scarf. Their hands are covered in clay dust. A macro DSLR image highlighting the texture and craftsmanship.
  5. A large, colorful bouquet of flowers in an old blue glass vase on the table. In front is one beautiful peony flower surrounded by various other blossoms like roses, lilies, daisies, orchids, fruits, berries, green leaves. The background is dark gray. Oil painting in the style of the Dutch Golden Age.
  6. A single comic book panel of a boy and his father on a grassy hill, staring at the sunset. A speech bubble points from the boy's mouth and says: The sun will rise again. Muted, late 1990s coloring style

Quickstart: Generate images from text prompts

You can generate novel images using only descriptive text as an input. The following samples show a simplified case for generating images, but you can use additional parameters to tailor the generated images to your needs.

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Vertex AI API.

    Enable the API

  8. Set up authentication for your environment.

    Select the tab for how you plan to use the samples on this page:

    Python

    To use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.

    1. Install the Google Cloud CLI.

    2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    3. To initialize the gcloud CLI, run the following command:

      gcloud init
    4. If you're using a local shell, then create local authentication credentials for your user account:

      gcloud auth application-default login

      You don't need to do this if you're using Cloud Shell.

      If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

    5. For more information, see Set up ADC for a local development environment in the Google Cloud authentication documentation.

    REST

    To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.

      After installing the Google Cloud CLI, initialize it by running the following command:

      gcloud init

      If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    For more information, see Authenticate for using REST in the Google Cloud authentication documentation.

  9. Use the following samples to generate an image:

    Python

    from google import genai
    
    client = genai.Client()
    
    # TODO(developer): Update and un-comment below line
    # output_file = "output-image.png"
    
    image = client.models.generate_images(
        model="imagen-4.0-generate-preview-05-20",
        prompt="A dog reading a newspaper",
    )
    
    image.generated_images[0].image.save(output_file)
    
    print(f"Created output image using {len(image.generated_images[0].image.image_bytes)} bytes")
    # Example response:
    # Created output image using 1234567 bytes
    

    REST

    Before using any of the request data, make the following replacements:

    • PROJECT_ID: Your Google Cloud project ID.
    • TEXT_PROMPT: The text prompt that guides what images the model generates. This field is required for both generation and editing.

    HTTP method and URL:

    POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/imagen-3.0-generate-002:predict

    Request JSON body:

    {
      "instances": [
        {
          "prompt": "TEXT_PROMPT"
        }
      ],
    }
    

    To send your request, choose one of these options:

    curl

    Save the request body in a file named request.json, and execute the following command:

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @request.json \
    "https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/imagen-3.0-generate-002:predict"

    PowerShell

    Save the request body in a file named request.json, and execute the following command:

    $cred = gcloud auth print-access-token
    $headers = @{ "Authorization" = "Bearer $cred" }

    Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/imagen-3.0-generate-002:predict" | Select-Object -Expand Content
    The following sample response returns a prediction object, with the image bytes base-64-encoded.
    {
      "predictions": [
        {
          "bytesBase64Encoded": "BASE64_IMG_BYTES",
          "prompt": "ENHANCED_PROMPT"
          "mimeType": "image/png"
        },
      ]
    }
    

Product usage

To view usage standards and content restrictions associated with Imagen on Vertex AI, see the usage guidelines.

Model versions

There are multiple image generation models that you can use. For more information, see Imagen models.

Try more examples

For a full list of Jupyter notebook tutorials using Imagen, see the Generative AI on Vertex AI cookbook.

What's next

Use the following links to view the feature documentation.

Image credit: All images generated using Imagen on Vertex AI.