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
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:
|Google AI Gemini API
|Google Cloud Vertex AI Gemini API
|Latest Gemini models
|Gemini Pro and Gemini Ultra
|Gemini Pro and Gemini Ultra
|Google Cloud account (with terms agreement and billing)
|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
|$300 Google Cloud credit for new users
|Quota (Request per minute)
|60 (can request increase)
|Increase upon request (default: 60)
Customer encryption key
Virtual private cloud
|Full MLOps on Vertex AI (Examples: model evaluation, Model Monitoring, Model Registry)
The following are additional considerations to note when migrating:
- You can use your existing Google Cloud project (the same one you used to generate your API key) or you can create a new Google Cloud project.
- Supported regions may differ between Google AI Studio and Vertex AI. See the list of supported regions for generative AI on Google Cloud.
- Any models you created in Google AI Studio need to be retrained in Vertex AI.
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.
- Productionize your apps and solutions. Products like Cloud Functions and Cloud Run lets you to deploy apps with enterprise-grade scale, security and privacy. Find more details about security and privacy on the Security, Privacy, and Cloud Compliance on Google Cloud guide.
- Use Vertex AI for end to end MLOps capabilities from tuning to vector similarity-search and ML pipelines.
- Trigger your LLM call with event-driven architecture with Cloud Functions or Cloud Run.
- Monitor usage of your app with Cloud Logging and BigQuery.
- Store your data with enterprise-grade security, at scale with services like BigQuery, Cloud Storage, and Cloud SQL.
- Perform retrieval-augmented generation (RAG) using data in the cloud with BigQuery or Cloud Storage.
- Create and schedule data pipelines. You can schedule jobs using Cloud Scheduler.
- Apply LLMs to your data in the cloud. If you store data in Cloud Storage or BigQuery, you can prompt LLMs over that data. For example to extract information, summarize or ask questions about it.
- Leverage Google Cloud's data governance/residency policies to manage your data lifecycle.
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.
- 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.
- Otherwise, you will need to create a Google Cloud project and enable the Vertex AI APIs. Visit Set up a project guide for instructions.
- Go to the Google Cloud console.
- Enable billing on your Google Cloud project if not already enabled. New users to Google Cloud will have a [$300] credit.
- 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
Code example to generate text from text prompt
Code example to generate text from text and image
Code example to generate multi-turn chat
Delete unused API Keys
If you no longer need to use your Google AI Gemini API key, follow security best practices and delete it.