Run Gemini on Google Cloud
In this guide, learn why you might want to migrate your development projects to Google Cloud and how to migrate your Python code from the Google AI Gemini API to the Gemini API on Vertex AI.
However, as your generative AI solutions mature, you might need a platform to build and deploy end-to-end generative AI applications and solutions. Google Cloud provides a comprehensive ecosystem of tools that empower developers to harness the power of generative AI, from the initial stages of application deployment to managing complex data at scale. Google Cloud's Vertex AI platform offers a suite of MLOps tools that streamline the consumption, deployment, and monitoring of AI models to improve efficiency and reliability.
The following table summarizes the key differences between Google AI and Vertex AI to help you determine which option is suitable for your use case:
Feature | 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 (including Terms Agreement and Billing) |
Authentication | API Key | Google Cloud Service Account |
Playground | Google AI Studio | Vertex AI Studio |
API and SDK | Python, Node.js, Android (Kotlin/Java), Swift, Go | SDK supports Python, Node.js, Java, Go |
Free Tier | Yes | $300 Google Cloud credits for new users |
Quota (Requests Per Minute) | 60 (can request increase) | Increase on request (default: 60) |
Enterprise Support | No | Data privacy commitments, customer-managed encryption keys, Virtual Private Cloud (VPC), data residency, access transparency |
MLOps | No | Full MLOps on Vertex AI (e.g., model evaluation, model monitoring, model registry) |
Here are other considerations to keep in mind when migrating:
Any models you created in Google AI Studio will need to be retrained in Vertex AI.
Additionally, integration with databases, DevOps tools, logging, monitoring, and IAM provides a comprehensive approach to managing the entire generative AI lifecycle.
Here are some examples of common use cases that are well-suited for Google Cloud products.
Achieve end-to-end MLOps capabilities with Vertex AI, from tuning to vector similarity search and machine learning pipelines.
Bring LLMs to your data in the cloud. If you have data stored in Cloud Storage or BigQuery, you can prompt LLMs to process that data. For example, extract information, summarize information, or ask questions.
Migrate from Gemini on Google AI to Vertex AI#
This section describes how to migrate from using Google AI Gemini to Google Cloud's Vertex AI Gemini.
Get Started with Vertex AI Studio#
The easiest way to get started with Gemini through Vertex AI is to use Vertex AI Studio.
1.
If you previously created an API key through Google AI Studio, a Google Cloud project has already been created for you, and you can use the same project. To find your Google Cloud project, go to API Keys in Google AI Studio.
1.
Otherwise, you will need to create a Google Cloud project and enable the Vertex AI API. For instructions, see the Set up your project guide. 3.
Enable billing for your Google Cloud project, if you haven't already. New Google Cloud users get [$300] in free credits. 4.
Go to Vertex AI Studio via this link. You can also search for "Vertex AI Studio" in the search bar. Python: Migrate from Google AI Gemini API to 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 do not need an API key. Gemini on Vertex AI uses IAM (Identity and Access Management) access controls that govern what users, groups, or service accounts can do when calling the Gemini API through the Vertex AI SDK.
To make inference calls to Vertex AI, you must also ensure that you have enabled Vertex AI User. Code Example for Installing the Client#
Google AI | Vertex AI |
---|
pythonpip install google-generativeaifrom google.generativeai import GenerativeModelfrom google.colab import userdatagenai.configure(userdata.get('API_KEY')) | pythonpip install google-cloud-aiplatformimport vertexaifrom google.cloud.aiplatform.private_preview.generative_models import GenerativeModel, ImagePROJECT_ID = ""REGION = "" # e.g. us-central1vertexai.init(project=PROJECT_ID, location=REGION) |
Code Example for Generating Text from a Text Prompt#
Google AI | Vertex AI |
---|
pythonmodel = GenerativeModel('gemini-pro')response = model.generate_content('The opposite of hot is')print(response.text) # The opposite of hot is cold. | pythonmodel = GenerativeModel('gemini-pro')response = model.generate_content('The opposite of hot is')print(response.text) # The opposite of hot is cold. |
Code Example for Generating Text from Text and Image#
Google AI | Vertex AI |
---|
pythonimport PIL.Imagemultimodal_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. | pythonmultimodal_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 for Generating Multi-Turn Chat#
Google AI | Vertex AI |
---|
pythonmodel = GenerativeModel('gemini-pro')chat = model.start_chat()print(chat.send_message("How are you?").text)print(chat.send_message("What can you do?").text) | pythonmodel = GenerativeModel("gemini-pro")chat = model.start_chat()print(chat.send_message("How are you?").text)print(chat.send_message("What can you do?").text) |
If you no longer need to use the Google AI Gemini API key, follow security best practices and delete it. Modified at 2025-04-24 09:15:11