Gemini Developer API 與 Gemini Enterprise Agent Platform 的比較

使用 Gemini 開發生成式 AI 解決方案時,Google 提供兩種 API 產品:Gemini Developer API 和 Gemini Enterprise Agent Platform API。

Gemini Developer API 提供最快速的途徑,協助您建構、正式推出及擴展 Gemini 輔助應用程式。除非需要特定企業控制項,否則大多數開發人員都應使用 Gemini 開發人員 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 開發人員 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 說明文件中特定用途的指南。

遷移注意事項

遷移時:

如果不再需要使用 Gemini API 金鑰存取 Gemini Developer API,請按照安全性最佳做法刪除金鑰。

刪除 API 金鑰的做法如下:

  1. 開啟「Google Cloud API 憑證」頁面。

  2. 找出要刪除的 API 金鑰,然後點選「動作」圖示。

  3. 選取「刪除 API 金鑰」。

  4. 在「刪除憑證」模式中,選取「刪除」。

    刪除 API 金鑰需要幾分鐘的時間才會生效。作業完畢後,凡是使用已刪除 API 金鑰的流量都會遭拒。

後續步驟