Migrate from the Gemini Developer API to the Gemini API in Vertex AI

This guide shows how to migrate from the Gemini Developer API to the Gemini API in Vertex AI, covering the following topics:

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.

Common use cases for Google Cloud offerings

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

Differences between the Gemini Developer API and the Gemini API in Vertex AI

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

Features Gemini Developer API Vertex AI Gemini API
Endpoint names generativelanguage.googleapis.com aiplatform.googleapis.com
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, ABAP
  • Mobile/Web client: Android (Kotlin/Java), Swift, Web, Flutter
Server and mobile/web client SDKs
  • Server: Python, Node.js, Go, Java, ABAP
  • Mobile/Web client (via Vertex AI in 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)

Migrate to Gemini API in Vertex AI

This section shows you how to set up your Google Cloud project and start using the Gemini API in Vertex AI.

Migration considerations

Before you migrate, consider the following:

  • You can use your existing Google Cloud project (the same one you used to generate your Gemini API key) or create a new Google Cloud project.
  • Supported regions might differ between the Gemini Developer API and the Gemini API in Vertex AI. For a list of supported regions, see supported regions for generative AI on Google Cloud.
  • Any models you created in Google AI Studio need to be retrained in Vertex AI.

Start using Vertex AI Studio

The migration process depends on whether you already have a Google Cloud account.

Note: Google AI Studio and the Gemini Developer API are available only in specific regions and languages. If you are in a region where Google AI Studio is not supported, you can't perform these migration steps.

Select the tab that applies to you:

Already use Google Cloud

  1. Sign in to Google AI Studio.
  2. At the bottom of the left navigation pane, click Build with Vertex AI on Google Cloud.

    The Try Vertex AI and Google Cloud for free page opens.

  3. Click Agree & Continue.

    The Get Started with Vertex AI studio dialog appears.

  4. To enable the APIs required to run Vertex AI, click Agree & Continue.

    The Vertex AI console appears. To learn how to migrate your data from Google AI studio, see Migrate Prompts.

New to Google Cloud

  1. Sign in to Google AI Studio.
  2. At the bottom of the left navigation pane, click Build with Vertex AI on Google Cloud.

    The Create an account to get started with Google Cloud page opens.

  3. Click Agree & Continue.

    The Let's confirm your identity page appears.

  4. Click Start Free.

    The Get Started with Vertex AI studio dialog appears.

  5. To enable the APIs required to run Vertex AI, click Agree & Continue.

  6. Optional: To learn how to migrate your data from Google AI studio, see Migrate Prompts on this page Migrate Prompts.

Python: Migrate to the Gemini API in Vertex AI

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

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

Gemini Developer API Gemini API in 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-genai

from google import genai

PROJECT_ID = "PROJECT_ID"
LOCATION = "LOCATION"  # e.g. us-central1
client = genai.Client(project=PROJECT_ID, location=LOCATION, vertexai=True)
        

Code example to generate text from text prompt

Gemini Developer API Gemini API in Vertex AI
model = GenerativeModel("gemini-2.0-flash")

response = model.generate_content("The opposite of hot is")
print(response.text) #  The opposite of hot is cold.
        
from google import genai
from google.genai.types import HttpOptions

client = genai.Client(http_options=HttpOptions(api_version="v1"))
response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="How does AI work?",
)
print(response.text)
# Example response:
# Okay, let's break down how AI works. It's a broad field, so I'll focus on the ...
#
# Here's a simplified overview:
# ...

Code example to generate text from text and image

Gemini Developer API Gemini API in Vertex AI
import PIL.Image

multimodal_model = GenerativeModel("gemini-2.0-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.
        
from google import genai
from google.genai.types import HttpOptions, Part

client = genai.Client(http_options=HttpOptions(api_version="v1"))
response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents=[
        "What is shown in this image?",
        Part.from_uri(
            file_uri="gs://cloud-samples-data/generative-ai/image/scones.jpg",
            mime_type="image/jpeg",
        ),
    ],
)
print(response.text)
# Example response:
# The image shows a flat lay of blueberry scones arranged on parchment paper. There are ...

Code example to generate multi-turn chat

Gemini Developer API Gemini API in Vertex AI
model = GenerativeModel("gemini-2.0-flash")

chat = model.start_chat()

print(chat.send_message("How are you?").text)
print(chat.send_message("What can you do?").text)
        
from google import genai
from google.genai.types import HttpOptions, ModelContent, Part, UserContent

client = genai.Client(http_options=HttpOptions(api_version="v1"))
chat_session = client.chats.create(
    model="gemini-2.5-flash",
    history=[
        UserContent(parts=[Part(text="Hello")]),
        ModelContent(
            parts=[Part(text="Great to meet you. What would you like to know?")],
        ),
    ],
)
response = chat_session.send_message("Tell me a story.")
print(response.text)
# Example response:
# Okay, here's a story for you:
# ...

Migrate prompts to Vertex AI Studio

Your Google AI Studio prompt data is saved in a Google Drive folder. To migrate your prompts to Vertex AI Studio, follow these steps:

  1. Open Google Drive.
  2. Navigate to the AI_Studio folder where the prompts are stored. Location of prompts in Google Drive
  3. Download your prompts from Google Drive to a local directory. Prompts from Google Drive download as text (.txt) files.
  4. Before you upload the prompts to Vertex AI Studio, convert them to the JSON format by changing the file extension from .txt to .json.
  5. Open Vertex AI Studio in the Google Cloud console.
  6. In the Vertex AI menu, click Prompt management.
  7. Click Import prompt.
  8. In the Prompt file field, click Browse and select a JSON prompt file from your local directory.

    Note: To upload prompts in bulk, you must first manually combine your individual prompts into a single JSON file.

  9. Click Upload.

    The prompts are uploaded to the My Prompts tab.

Upload training data to Vertex AI Studio

To migrate your training data to Vertex AI, you need to upload your data to a Cloud Storage bucket. For more information, see Introduction to tuning .

Delete your unused API key

After you migrate and no longer need your Gemini API key for the Gemini Developer API, delete the key to follow security best practices.

To delete an API key:

  1. Open the Google Cloud API Credentials page.
  2. Find the API key that 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 that uses the deleted API key is rejected.

Important: If you delete a key that's still used in production and need to recover it, see gcloud beta services api-keys undelete.

What's next