agent-platform-migrate-from-ai-studio
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMigrating from Gemini API in AI Studio to Agent Platform
从AI Studio中的Gemini API迁移到Agent Platform
Use this skill when you need to transition an application from the
developer-centric Google AI Studio ecosystem
() to the enterprise-grade Google Cloud Agent
Platform ().
generativelanguage.googleapis.comaiplatform.googleapis.com当您需要将应用从面向开发者的Google AI Studio生态系统()迁移至企业级Google Cloud Agent Platform()时,可使用此技能。
generativelanguage.googleapis.comaiplatform.googleapis.comWhen to Invoke This Skill
何时调用此技能
- You want to migrate an application from Google AI Studio to Agent Platform (formerly Vertex AI).
- You have Google Cloud credits (e.g., the $300 Welcome Free Trial) that you want to apply toward Gemini API inferencing costs.
- You need to unify your inferencing pipelines, IAM permissions, telemetry, and billing with existing Google Cloud infrastructure (Compute Engine, Cloud SQL, BigQuery).
- You are deploying open-source orchestration engines (like OpenClaw or ADK agents) on Google Cloud VMs, and want the entire system to run under a unified Google Cloud billing structure.
- 您希望将应用从Google AI Studio迁移到Agent Platform(原Vertex AI)。
- 您拥有Google Cloud信用额度(例如300美元欢迎免费试用额度),希望将其用于Gemini API推理成本。
- 您需要将推理流水线、IAM权限、遥测数据和计费与现有Google Cloud基础设施(Compute Engine、Cloud SQL、BigQuery)统一。
- 您正在Google Cloud虚拟机上部署开源编排引擎(如OpenClaw或ADK Agent),并希望整个系统在统一的Google Cloud计费结构下运行。
Gemini API Comparison
Gemini API对比
| Feature / Control | Google AI Studio (Gemini Developer API) | Agent Platform (Enterprise Gemini API) |
|---|---|---|
| API Endpoint | | |
| Target Audience | Developers, startups, students, researchers building production apps. | Enterprise production, MLOps engineers |
| GCP Credit Support | No (GCP credits/Free Trial cannot be applied) | Yes (Fully covered by Welcome or custom credits) |
| Data Privacy | Data may be reviewed to improve Google products | Prompts/responses are never used for training |
| Security & IAM | API key, OAuth | Google Cloud IAM (Service Accounts, OAuth 2.0, VPC-SC) |
| Compliance & SLAs | None (Best-effort availability) | 24/7 Enterprise Support, SLAs, HIPAA, SOC2 |
| Throughput Options | Shared / Rate-limited | Pay-as-you-go OR Provisioned Throughput |
| MLOps Ecosystem | Basic prompt management | Model Registry, Model Monitoring, Pipeline Evaluation |
| Inferencing Scope | Global endpoints only | Both Global and strict Regional endpoints |
See
Google Cloud Documentation
to learn more about the differences between the two offerings.
| 功能/控制项 | Google AI Studio(Gemini开发者API) | Agent Platform(企业级Gemini API) |
|---|---|---|
| API端点 | | |
| 目标受众 | 开发者、初创企业、学生、研究人员,用于构建生产应用。 | 企业级生产环境、MLOps工程师 |
| GCP信用额度支持 | 不支持(GCP信用额度/免费试用无法使用) | 支持(完全适用欢迎信用额度或自定义信用额度) |
| 数据隐私 | 数据可能会被用于改进Google产品 | 提示词/响应绝不会用于模型训练 |
| 安全与IAM | API密钥、OAuth | Google Cloud IAM(服务账号、OAuth 2.0、VPC-SC) |
| 合规性与SLA | 无(尽力而为的可用性) | 7×24小时企业支持、SLA、HIPAA、SOC2合规 |
| 吞吐量选项 | 共享/速率限制 | 按需付费或预配置吞吐量 |
| MLOps生态系统 | 基础提示词管理 | 模型注册表、模型监控、流水线评估 |
| 推理范围 | 仅全局端点 | 全局及严格区域端点 |
查看
Google Cloud文档
了解这两种服务的更多差异。
Migration Guide
迁移指南
Billing and Credits
计费与信用额度
Google Cloud Free Trial credits
do not apply to AI Studio.
To use your credits for Gemini models, you must route calls through the Agent
Platform.
- Create a Google Cloud billing account. You must provide a valid payment method during setup to verify identity.
- If you are a new customer, ensure your $300 Welcome credit is active in the Billing Console.
- Avoid Billing Surprises: To prevent automatic fallback to your standard
form of payment when credits are exhausted, you should establish a budget
alert:
- Go to Billing -> Budgets & Alerts -> Create Budget.
- Set the threshold to map to your credit limit or maximum comfortable spend.
Google Cloud免费试用额度
不适用于AI Studio。
要将信用额度用于Gemini模型,您必须通过Agent Platform发起调用。
- 创建Google Cloud计费账号。设置过程中您必须提供有效的支付方式以验证身份。
- 如果您是新客户,请确保300美元欢迎信用额度在计费控制台中处于激活状态。
- 避免计费意外:为防止信用额度耗尽时自动切换为标准支付方式,您应设置预算告警:
- 进入计费 -> 预算与告警 -> 创建预算。
- 将阈值设置为您的信用额度上限或可接受的最高支出。
Enable the Agent Platform API
启用Agent Platform API
You must explicitly enable the Agent Platform API on your target Google Cloud
Project. Run the following command via your local shell:
bash
gcloud services enable aiplatform.googleapis.com --project="YOUR_PROJECT_ID"您必须在目标Google Cloud项目上显式启用Agent Platform API。在本地终端运行以下命令:
bash
gcloud services enable aiplatform.googleapis.com --project="YOUR_PROJECT_ID"Authentication & Authorization (IAM)
身份验证与授权(IAM)
User Auth
用户身份验证
For local debugging or script execution, authenticate using
Application Default Credentials
(ADC).
Option 1 - Automated Script:
bash
bash <(curl -sSL https://storage.googleapis.com/cloud-samples-data/adc/setup_adc.sh)Option 2 - Manual Setup:
bash
gcloud auth login
gcloud auth application-default loginGrant your user identity the required IAM role to perform inferencing calls:
bash
gcloud projects add-iam-policy-binding "YOUR_PROJECT_ID" \
--member="user:YOUR_EMAIL@domain.com" \
--role="roles/aiplatform.user"对于本地调试或脚本执行,使用
应用默认凭据
(ADC)进行身份验证。
选项1 - 自动化脚本:
bash
bash <(curl -sSL https://storage.googleapis.com/cloud-samples-data/adc/setup_adc.sh)选项2 - 手动设置:
bash
gcloud auth login
gcloud auth application-default login为您的用户身份授予执行推理调用所需的IAM角色:
bash
gcloud projects add-iam-policy-binding "YOUR_PROJECT_ID" \
--member="user:YOUR_EMAIL@domain.com" \
--role="roles/aiplatform.user"Service Auth
服务身份验证
When running your application on Google Cloud infrastructure such as a Compute
Engine VM, authenticate using the machine's attached Service Account. For
example, the
Compute Engine Default Service Account.
- Grant the virtual machine's underlying Service Account the user role:
bash
gcloud projects add-iam-policy-binding "YOUR_PROJECT_ID" \
--member="serviceAccount:PROJECT_NUMBER-compute@developer.gserviceaccount.com" \
--role="roles/aiplatform.user"- Compute Engine Access Scopes:
Legacy access scopes can override IAM bindings. When provisioning or
modifying your GCE instance, you must verify that the VM access scope is
configured to either Allow full access to all Cloud APIs
() or explicitly includes the standard cloud-platform scope.
https://www.googleapis.com/auth/cloud-platform
当您在Google Cloud基础设施(如Compute Engine虚拟机)上运行应用时,使用虚拟机附加的服务账号进行身份验证。例如,
Compute Engine默认服务账号。
- 为虚拟机底层的服务账号授予用户角色:
bash
gcloud projects add-iam-policy-binding "YOUR_PROJECT_ID" \
--member="serviceAccount:PROJECT_NUMBER-compute@developer.gserviceaccount.com" \
--role="roles/aiplatform.user"- Compute Engine访问范围:
旧版访问范围可能会覆盖IAM绑定。在配置或修改GCE实例时,您必须验证VM访问范围已配置为允许访问所有Cloud API
(),或明确包含标准cloud-platform范围。
https://www.googleapis.com/auth/cloud-platform
Use the Gemini API in Agent Platform
在Agent Platform中使用Gemini API
SDKs (Client Libraries)
SDK(客户端库)
You can continue to use the unified
Google GenAI SDK
(). This SDK works with both AI Studio and Agent Platform. You
only need to switch the routing flags via your runtime environment variables to
target the Agent Platform backend.
google-genaiSet your target environment details:
bash
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
export GOOGLE_CLOUD_LOCATION="global" # Or your chosen regional endpoint
export GOOGLE_GENAI_USE_ENTERPRISE=TRUENow, your standard python code shifts from using AI Studio to Agent Platform
without altering the core initialization blocks:
python
from google import genai您可以继续使用统一的
Google GenAI SDK
()。此SDK同时适用于AI Studio和Agent Platform。您只需通过运行时环境变量切换路由标志,即可指向Agent Platform后端。
google-genai设置目标环境详情:
bash
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
export GOOGLE_CLOUD_LOCATION="global" # 或您选择的区域端点
export GOOGLE_GENAI_USE_ENTERPRISE=TRUE现在,您的标准Python代码无需修改核心初始化代码块,即可从使用AI Studio切换到Agent Platform:
python
from google import genaiThe client automatically picks up the GOOGLE_GENAI_USE_ENTERPRISE=TRUE environment flag
客户端会自动读取GOOGLE_GENAI_USE_ENTERPRISE=TRUE环境变量
client = genai.Client()
response = client.models.generate_content(
model='gemini-3-flash-preview',
contents='Hello world!',
)
print(response.text)
undefinedclient = genai.Client()
response = client.models.generate_content(
model='gemini-3-flash-preview',
contents='Hello world!',
)
print(response.text)
undefinedAgent Development Kit (ADK)
Agent开发工具包(ADK)
To call Gemini models in Agent Platform from an Agent Development Kit agent,
follow these steps.
- Authenticate to Google Cloud.
If running an ADK agent in Google Cloud (e.g. Agent Platform Runtime), use the
agent's assigned service account. Alternatively, if running ADK locally, run:
bash
gcloud auth application-default login- Set env variables. Ensure these are set no matter if your ADK agent is running in Google Cloud or locally:
bash
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
export GOOGLE_CLOUD_LOCATION="global"
export GOOGLE_GENAI_USE_ENTERPRISE=TRUE- Initialize the ADK agent. You can use the same model string you used with AI
Studio (e.g. ).
gemini-3-flash-preview
python
from google.adk.agents.llm_agent import Agent
def get_current_time(city: str) -> dict:
"""Returns the current time in a specified city."""
return {"status": "success", "city": city, "time": "10:30 AM"}
root_agent = Agent(
model='gemini-3-flash-preview',
name='root_agent',
description="Tells the current time in a specified city.",
instruction="You are a helpful assistant that tells the current time in cities. Use the 'get_current_time' tool for this purpose.",
tools=[get_current_time],
)To learn more about integrating ADK agents with Agent Platform,
see the ADK documentation.
要从Agent开发工具包(ADK)Agent调用Agent Platform中的Gemini模型,请遵循以下步骤。
- 登录Google Cloud。
如果在Google Cloud中运行ADK Agent(例如Agent Platform Runtime),使用Agent分配的服务账号。或者,如果在本地运行ADK,请执行:
bash
gcloud auth application-default login- 设置环境变量。无论ADK Agent是在Google Cloud中运行还是本地运行,都必须设置这些变量:
bash
export GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID"
export GOOGLE_CLOUD_LOCATION="global"
export GOOGLE_GENAI_USE_ENTERPRISE=TRUE- 初始化ADK Agent。您可以使用与AI Studio中相同的模型字符串(例如)。
gemini-3-flash-preview
python
from google.adk.agents.llm_agent import Agent
def get_current_time(city: str) -> dict:
"""返回指定城市的当前时间。"""
return {"status": "success", "city": city, "time": "10:30 AM"}
root_agent = Agent(
model='gemini-3-flash-preview',
name='root_agent',
description="告知指定城市的当前时间。",
instruction="您是一个乐于助人的助手,负责告知各个城市的当前时间。请使用'get_current_time'工具完成此任务。",
tools=[get_current_time],
)要了解更多关于ADK Agent与Agent Platform集成的信息,请
查看ADK文档。
Antigravity CLI
Antigravity CLI
Google Cloud users can now access
Antigravity 2.0, including the Antigravity CLI, with Gemini Enterprise Agent
Platform.
-
Install the Antigravity CLI to your local environment.
-
Start the Antigravity CLI.bash
agy -
Follow the CLI setup prompts - select Use a Google Cloud Project.
-
Complete the OAuth flow in the opened browser window using your authenticated Google Cloud Workspace or user identity.
-
Copy the confirmation token, and paste it directly back into your terminal.
-
Follow the prompts to enter your Google Cloud Project ID.
-
Select your Google Cloud location (e.g.).
global -
Optionally, run thecommand to select a different Gemini model in Agent Platform.
/model
Google Cloud用户现在可以通过Gemini Enterprise Agent Platform
访问
Antigravity 2.0,包括Antigravity CLI。
-
安装Antigravity CLI 到您的本地环境。
-
启动Antigravity CLI。bash
agy -
按照CLI设置提示操作 - 选择使用Google Cloud项目。
-
在打开的浏览器窗口中使用已认证的Google Cloud Workspace或用户身份完成OAuth流程。
-
复制确认令牌,并直接粘贴回终端。
-
按照提示输入您的Google Cloud项目ID。
-
选择您的Google Cloud位置(例如)。
global -
可选地,运行命令以在Agent Platform中选择不同的Gemini模型。
/model
OpenClaw
OpenClaw
To configure an OpenClaw agent to use Gemini models in Agent Platform, Follow
these steps.
⚠️ Important: OpenClaw 2026.5.28 currently has a bug. Please use
2026.5.20 for now.
google-vertex-
Ensure that the runtime where OpenClaw is running (e.g. GCE VM with Service Account) has theIAM role - see Authentication and Authorization section above.
aiplatform.user -
Get the project number from the user's project ID. Outside of GCE, run:
bash
export PROJECT_NUMBER=$(gcloud projects describe "$PROJECT_ID" --format="value(projectNumber)")
echo "Project number: $PROJECT_NUMBER"Within a GCE VM, run:
bash
export PROJECT_NUMBER=$(curl "http://metadata.google.internal/computeMetadata/v1/project/numeric-project-id" -H "Metadata-Flavor: Google")
echo "Project number: $PROJECT_NUMBER"- From outside the GCE instance, generate using the Google Cloud project number. Then,
GOOGLE_APPLICATION_CREDENTIALSthese credentials to the GCE VM.scp
bash
mkdir -p ~/.config/gcloud
gcloud iam service-accounts keys create ~/.config/gcloud/application_default_credentials.json --iam-account="${PROJECT_NUMBER}-compute@developer.gserviceaccount.com"-
Edit the configuration file that's usually located at:. Ensure you prefix the Gemini model with
~/.openclaw/openclaw.json.google-vertex/⚠️ Important:- Do not use Gemini 3.5 models, since OpenClaw's provider does not support it yet. Older models work.
google-vertex - When using the
Gemini 3 Flash Preview
model in Agent Platform, always set the location to , NOT a regional endpoint.
global
- Do not use Gemini 3.5 models, since OpenClaw's
json
{
"env": {
"vars": {
"GOOGLE_CLOUD_PROJECT": "PROJECT_ID",
"GOOGLE_CLOUD_LOCATION": "global",
"GOOGLE_APPLICATION_CREDENTIALS": "~/.config/gcloud/application_default_credentials.json"
}
},
"agents": {
"defaults": {
"model": {
"primary": "google-vertex/gemini-3-flash-preview"
},
"workspace": "~/.openclaw/workspace",
"compaction": {
"mode": "safeguard"
},
"heartbeat": {
"model": "google-vertex/gemini-3-flash-preview"
}
},
"list": [
{
"id": "main",
"workspace": "~/.openclaw/workspace",
"model": "google-vertex/gemini-3-flash-preview"
}
]
},
"session": {
"dmScope": "per-channel-peer"
},
"tools": {
"profile": "coding"
}
}- Restart OpenClaw.
bash
openclaw gateway restart- Verify the OpenClaw connection to Agent Platform:
bash
openclaw models status
openclaw agent --agent main --message "Hello world!"要配置OpenClaw Agent以使用Agent Platform中的Gemini模型,请遵循以下步骤。
⚠️ 重要提示:OpenClaw 2026.5.28当前存在 bug。请暂时使用2026.5.20版本。
google-vertex-
确保运行OpenClaw的运行环境(例如带有服务账号的GCE虚拟机)拥有IAM角色 - 请参阅上方的身份验证与授权部分。
aiplatform.user -
从用户的项目ID获取项目编号。在GCE外部运行:
bash
export PROJECT_NUMBER=$(gcloud projects describe "$PROJECT_ID" --format="value(projectNumber)")
echo "Project number: $PROJECT_NUMBER"在GCE虚拟机内部运行:
bash
export PROJECT_NUMBER=$(curl "http://metadata.google.internal/computeMetadata/v1/project/numeric-project-id" -H "Metadata-Flavor: Google")
echo "Project number: $PROJECT_NUMBER"- 在GCE实例外部,使用Google Cloud项目编号生成。然后,通过
GOOGLE_APPLICATION_CREDENTIALS将这些凭据传输到GCE虚拟机。scp
bash
mkdir -p ~/.config/gcloud
gcloud iam service-accounts keys create ~/.config/gcloud/application_default_credentials.json --iam-account="${PROJECT_NUMBER}-compute@developer.gserviceaccount.com"-
编辑通常位于以下路径的配置文件:。确保在Gemini模型前添加
~/.openclaw/openclaw.json前缀。google-vertex/⚠️ 重要提示:- 请勿使用Gemini 3.5模型,因为OpenClaw的提供商目前尚不支持该模型。旧版模型可正常使用。
google-vertex - 当在Agent Platform中使用
Gemini 3 Flash Preview
模型时,请始终将位置设置为,而非区域端点。
global
- 请勿使用Gemini 3.5模型,因为OpenClaw的
json
{
"env": {
"vars": {
"GOOGLE_CLOUD_PROJECT": "PROJECT_ID",
"GOOGLE_CLOUD_LOCATION": "global",
"GOOGLE_APPLICATION_CREDENTIALS": "~/.config/gcloud/application_default_credentials.json"
}
},
"agents": {
"defaults": {
"model": {
"primary": "google-vertex/gemini-3-flash-preview"
},
"workspace": "~/.openclaw/workspace",
"compaction": {
"mode": "safeguard"
},
"heartbeat": {
"model": "google-vertex/gemini-3-flash-preview"
}
},
"list": [
{
"id": "main",
"workspace": "~/.openclaw/workspace",
"model": "google-vertex/gemini-3-flash-preview"
}
]
},
"session": {
"dmScope": "per-channel-peer"
},
"tools": {
"profile": "coding"
}
}- 重启OpenClaw。
bash
openclaw gateway restart- 验证OpenClaw与Agent Platform的连接:
bash
openclaw models status
openclaw agent --agent main --message "Hello world!"Additional Resources
额外资源
- Google Cloud Free Trial Features & Limits
- Migrate from Google AI Studio to Gemini Enterprise Agent Platform
- Gemini Enterprise Agent Platform - Models
- Agent Development Kit Documentation - Connect to Models in Agent Platform
- OpenClaw Documentation - Connect to Google models
- Google Cloud Budget Alerts - Setup Guide