Build with Gemini on Google Cloud

If you are new to Gemini, using the quickstarts 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 development to app deployment, app hosting, and managing complex data at scale.

Google Cloud's Vertex AI platform offers a suite of MLOps tools that streamline usage, deployment, and monitoring of AI models for efficiency and reliability. Additionally, integrations with databases, DevOps tools, logging, monitoring, and IAM provide a holistic approach to managing the entire generative AI lifecycle.

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

Features Google AI Gemini API Vertex AI Gemini API
Gemini models Gemini 1.5 Flash, Gemini 1.5 Pro, Gemini 1.0 Pro, Gemini 1.0 Pro Vision (deprecated) Gemini 1.5 Flash, Gemini 1.5 Pro, Gemini 1.0 Pro, Gemini 1.0 Pro Vision, Gemini 1.0 Ultra, Gemini 1.0 Ultra Vision
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 Server and mobile/web client SDKs
  • Server: Python, Node.js, Go, Dart
  • Mobile/Web client: Android (Kotlin/Java), Swift, Web, Flutter
Server and mobile/web client SDKs
  • Server: Python, Node.js, Go, Java
  • Mobile/Web client (via Vertex AI for Firebase): Android (Kotlin/Java), Swift, Web, Flutter
No-cost usage of API & SDK Yes, where applicable $300 Google Cloud credit for new users
Quota (requests per minute) Varies based on model and pricing plan (see detailed information) Varies based on model and region (see detailed information)
Enterprise support No Customer encryption key
Virtual private cloud
Data residency
Access transparency
Scalable infrastructure for application hosting
Databases and data storage
MLOps No Full MLOps on Vertex AI (examples: model evaluation, Model Monitoring, Model Registry)

To learn which products, frameworks, and tools are the best match for building your generative AI application on Google Cloud, see Build a generative AI application on Google Cloud.

Migrate from Gemini on Google AI to Vertex AI

If your application uses Google AI Gemini APIs, you'll need to migrate to Google Cloud's Vertex AI Gemini APIs.

When you migrate:

Note that if you want to call the Gemini API directly from a production mobile or web app, then migrate to use the Vertex AI in Firebase client SDKs (available for Swift, Android, Web, and Flutter apps). These client SDKs offer critical security options and other features for production mobile and web apps.

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.

While there are many ways to authenticate, the easiest method for authenticating in a development environment is to install the Google Cloud CLI then use your user credentials to sign in to the CLI.

To make inference calls to Vertex AI, you must also make sure that your user or service account has the Vertex AI User role.

Code example to install the client

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

import google.generativeai as genai
from google.generativeai import GenerativeModel

API_KEY="API_KEY"
genai.configure(api_key=API_KEY)
        
# To install the Python SDK, use this CLI command:
# pip install google-cloud-aiplatform

import vertexai
from vertexai.generative_models import GenerativeModel, Image

PROJECT_ID = "PROJECT_ID"
REGION = "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-1.5-flash")

response = model.generate_content("The opposite of hot is")
print(response.text) #  The opposite of hot is cold.
        
model = GenerativeModel("gemini-1.5-flash")

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-1.5-flash")

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-1.5-flash")

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-1.5-flash")

chat = model.start_chat()

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

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.

To delete an API key:

  1. Open the Google Cloud API Credentials page.

  2. Find the API key you want to delete and click the Actions icon.

  3. Select Delete API key.

  4. In the Delete credential modal, select Delete.

    Deleting an API key takes a few minutes to propagate. After propagation completes, any traffic using the deleted API key is rejected.

Next steps