使用 Gemini 开发生成式 AI 解决方案时,Google 提供两款 API 产品:Gemini Developer API 和 Gemini Enterprise Agent Platform API。
Gemini Developer API 可帮助您以最快的速度构建、投入生产和扩缩 Gemini 赋能的应用。大多数开发者都应使用 Gemini Developer API,除非需要特定的企业控制功能。
Gemini Enterprise Agent Platform 提供全面的企业级功能和服务生态系统,可用于构建和部署由 Google Cloud Platform 提供支持的生成式 AI 应用。
我们最近简化了在这些服务之间迁移数据的流程。现在,您可以通过统一的 Google GenAI SDK 和 Interactions API 访问 Gemini Developer API 和 Gemini Enterprise Agent Platform API。
代码比较:Interactions API(推荐)
建议使用 Interactions API 来构建 Gemini 模型和智能体。以下示例比较了 Gemini Developer API 和 Gemini Enterprise Agent Platform 之间的文本生成。
Python
您可以通过 google-genai 库 (>= 2.3.0) 访问 Gemini Developer API 和 Gemini Enterprise Agent Platform 服务。如需了解如何安装 google-genai,请参阅库页面。
Gemini Developer API
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.8-flash",
input="Explain how AI works in a few words",
)
print(interaction.output_text)
Gemini Enterprise Agent Platform API
from google import genai
client = genai.Client(
enterprise=True, project="your-project-id", location="global"
)
interaction = client.interactions.create(
model="gemini-3.8-flash",
input="Explain how AI works in a few words",
)
print(interaction.output_text)
JavaScript 和 TypeScript
您可以通过 @google/genai 库 (>= 2.3.0) 访问 Gemini Developer API 和 Gemini Enterprise Agent Platform 服务。如需了解如何安装 @google/genai,请参阅库页面。
Gemini Developer API
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
const interaction = await ai.interactions.create({
model: "gemini-3.8-flash",
input: "Explain how AI works in a few words",
});
console.log(interaction.output_text);
Gemini Enterprise Agent Platform API
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({
enterprise: true,
project: "your_project",
location: "global",
});
const interaction = await ai.interactions.create({
model: "gemini-3.8-flash",
input: "Explain how AI works in a few words",
});
console.log(interaction.output_text);
代码比较:generateContent API
虽然建议新项目使用 Interactions API,但 generateContent API 仍受支持。
Python
您可以通过 google-genai 库访问 Gemini Developer API 和 Gemini Enterprise Agent Platform 服务。如需了解如何安装 google-genai,请参阅库页面。
Gemini Developer API
from google import genai
client = genai.Client()
response = client.models.generate_content(
model="gemini-3.8-flash", contents="Explain how AI works in a few words"
)
print(response.text)
Gemini Enterprise Agent Platform API
from google import genai
client = genai.Client(
vertexai=True, project='your-project-id', location='us-central1'
)
response = client.models.generate_content(
model="gemini-3.8-flash", contents="Explain how AI works in a few words"
)
print(response.text)
JavaScript 和 TypeScript
您可以通过 @google/genai 库访问 Gemini Developer API 和 Gemini Enterprise Agent Platform 服务。如需了解如何安装 @google/genai,请参阅库页面。
Gemini Developer API
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
async function main() {
const response = await ai.models.generateContent({
model: "gemini-3.8-flash",
contents: "Explain how AI works in a few words",
});
console.log(response.text);
}
main();
Gemini Enterprise Agent Platform API
import { GoogleGenAI } from '@google/genai';
const ai = new GoogleGenAI({
vertexai: true,
project: 'your_project',
location: 'your_location',
});
async function main() {
const response = await ai.models.generateContent({
model: "gemini-3.8-flash",
contents: "Explain how AI works in a few words",
});
console.log(response.text);
}
main();
Go
您可以通过 google.golang.org/genai 库访问 Gemini Developer API 和 Gemini Enterprise Agent Platform 服务。如需了解如何安装 google.golang.org/genai,请参阅库页面。
Gemini Developer API
import (
"context"
"encoding/json"
"fmt"
"log"
"google.golang.org/genai"
)
// Your Google API key
const apiKey = "your-api-key"
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, nil)
if err != nil {
log.Fatal(err)
}
// Call the GenerateContent method.
result, err := client.Models.GenerateContent(ctx, "gemini-3.8-flash", genai.Text("Tell me about New York?"), nil)
}
Gemini Enterprise Agent Platform API
import (
"context"
"encoding/json"
"fmt"
"log"
"google.golang.org/genai"
)
// Your Google Cloud project
const project = "your-project"
// A Google Cloud location like "us-central1"
const location = "some-gcp-location"
func main() {
ctx := context.Background()
client, err := genai.NewClient(ctx, &genai.ClientConfig
{
Project: project,
Location: location,
Backend: genai.BackendVertexAI,
})
// Call the GenerateContent method.
result, err := client.Models.GenerateContent(ctx, "gemini-3.8-flash", genai.Text("Tell me about New York?"), nil)
}
其他使用场景和平台
如需了解其他平台和应用场景,请参阅 Gemini Developer API 文档和 Gemini Enterprise Agent Platform 文档中针对特定应用场景的指南。
迁移注意事项
迁移时:
您需要使用 Google Cloud 服务账号进行身份验证。如需了解详情,请参阅 Gemini Enterprise Agent Platform 文档。
您可以使用现有的 Google Cloud 项目(即用于生成 API 密钥的项目),也可以创建新的 Google Cloud 项目。
Gemini Developer API 和 Gemini Enterprise Agent Platform API 支持的区域可能会有所不同。在预览期间,Gemini Enterprise Agent Platform 上的 Interactions API 仅支持
global端点 (location="global")。请参阅 Google Cloud 上的生成式 AI 支持的区域列表。您在 Google AI Studio 中创建的任何模型都需要在 Gemini Enterprise Agent Platform 中重新训练。
如果您不再需要使用 Gemini Developer API 的 Gemini API 密钥,请遵循安全性最佳实践并将其删除。
如需删除 API 密钥,请执行以下操作:
打开 Google Cloud API 凭据页面。
找到要删除的 API 密钥,然后点击操作图标。
选择删除 API 密钥。
在删除凭据模态框中,选择删除。
删除 API 密钥的操作需要几分钟时间才能生效。生效后,任何使用已删除的 API 密钥的流量都将遭到拒绝。
后续步骤
- 请参阅 Gemini Enterprise Agent Platform 上的 Interactions API 开发者指南。
- 如需详细了解 Gemini Enterprise Agent Platform 上的生成式 AI 解决方案,请参阅 Gemini Enterprise Agent Platform 上的生成式 AI 概览。