Migrate to Cloud

In this guide, learn why you may want to migrate your development to Google Cloud and how to migrate your Python code to Gemini API on Vertex AI from Google AI.

Why migrate to Cloud

If you are new to Gemini, using the quickstarts and plans for Google AI Studio is the fastest way to get started.

However, as your generative AI solutions mature, you may need a platform for building and deploying generative AI applications and solutions end to end. Google Cloud provides a comprehensive ecosystem of tools to enable developers to harness the power of generative AI, from the initial stages of app deployment to managing complex data at scale. Google Cloud's Vertex AI platform offers a suite of MLOps tools that streamline the usage, deployment, and monitoring of AI models for efficiency and reliability.

The following table summarizes the main differences between Google AI and the Vertex AI to help you decide which option is right for your use case:

Features Google AI Gemini API Google Cloud Vertex AI Gemini API
Latest Gemini models Gemini Pro and Gemini Ultra Gemini Pro and Gemini Ultra
Sign up Google account Google Cloud account (with terms agreement and billing)
Authentication API key Google Cloud service account
User interface playground Google AI Studio Vertex AI Studio
API & SDK Python, Node.js, Android (Kotlin/Java), Swift, Go SDK supports Python, Node.js, Java, Go
Free tier Yes $300 Google Cloud credit for new users
Quota (Request per minute) 60 (can request increase) Increase upon request (default: 60)
Enterprise support No Customer encryption key
Virtual private cloud
Data residency
Access transparency
MLOps No Full MLOps on Vertex AI (Examples: model evaluation, Model Monitoring, Model Registry)

The following are additional considerations to note when migrating:

Additionally, integrations with databases, DevOps tools, logging, monitoring, and IAM provide a holistic approach to managing the entire generative AI lifecycle.

Here are some examples of common use cases that are well-suited for Google Cloud offerings.

Migrate from Gemini on Google AI to Vertex AI

This section shows how to migrate from using Google AI Gemini to Google Cloud's Vertex AI Gemini.

Start using Vertex AI Studio

The easiest way to get started using Gemini through Vertex AI is to use the Vertex AI Studio.

  1. If you previously created an API key from Google AI Studio, then a Google Cloud project was already created for you and you can use the same project. To find your Google Cloud project, go to the API key on Google AI Studio.

    Link to Google Cloud project

  2. Otherwise, you will need to create a Google Cloud project and enable the Vertex AI APIs. Visit Set up a project guide for instructions.
  3. Go to the Google Cloud console.
  4. Enable billing on your Google Cloud project if not already enabled. New users to Google Cloud will have a [$300] credit.
  5. Go to Vertex AI Studio with this link. You can also search for "Vertex AI Studio" in the search bar.

Now you can start using Vertex AI Studio. Visit the Vertex AI Studio documentation to learn more.

Python: Migrate from Google AI Gemini API to the Vertex AI Gemini API

The following sections show code snippets to help you migrate your Python code to use the Vertex AI Gemini API.

Vertex AI Python SDK Setup

On Vertex AI, you don't need an API key. Instead, Gemini on Vertex AI is managed using IAM access, which controls permission for a user, a group, or a service account to call the Gemini API through the Vertex AI SDK.

There are many ways to authenticate. You can follow this decision tree to choose the right authentication method for your use case .

To make inference calls to Vertex AI, you must also make sure you have Vertex AI User enabled.

Code example to install the client

Google AI Vertex AI
# To install the Python SDK, use this CLI command:
# pip install google-generativeai

from google.generativeai import GenerativeModel
from google.colab import userdata

genai.configure(userdata.get('API_KEY'))
        
# To install the Python SDK, use this CLI command:
# pip install google-cloud-aiplatform

import vertexai
from vertexai.preview.generative_models
          import GenerativeModel, Image

PROJECT_ID = ""
REGION = ""  # e.g. us-central1
vertexai.init(project=PROJECT_ID, location=REGION)
        

Code example to generate text from text prompt

Google AI Vertex AI
model = GenerativeModel('gemini-pro')

response = model.generate_content('The opposite of hot is')
print(response.text) #  The opposite of hot is cold.
        
model = GenerativeModel('gemini-pro')

response = model.generate_content('The opposite of hot is')
print(response.text) #  The opposite of hot is cold.
        

Code example to generate text from text and image

Google AI Vertex AI
import PIL.Image

multimodal_model = GenerativeModel('gemini-pro-vision')

image = PIL.Image.open('image.jpg')

response = multimodal_model.generate_content(['What is this picture?', image])
print(response.text) # A cat is shown in this picture.
        
multimodal_model = GenerativeModel("gemini-pro-vision")

image = Image.load_from_file("image.jpg")

response = multimodal_model.generate_content(["What is shown in this image?", image])

print(response.text) # A cat is shown in this picture.
        

Code example to generate multi-turn chat

Google AI Vertex AI
model = GenerativeModel('gemini-pro')

chat = model.start_chat()

print(chat.send_message("How are you?").text)
print(chat.send_message("What can you do?").text)
        
model = GenerativeModel("gemini-pro")

chat = model.start_chat()

print(chat.send_message("How are you?").text)
print(chat.send_message("What can you do?").text)
        

Delete unused API Keys

If you no longer need to use your Google AI Gemini API key, follow security best practices and delete it.

Next steps