Gemini Developer API と Vertex AI

Gemini で生成 AI ソリューションを開発する場合、Google は Gemini Developer APIVertex AI Gemini API の 2 つの API プロダクトを提供しています。

Gemini Developer API を使用すると、Gemini を活用したアプリケーションを構築、本番環境に移行、スケーリングするための最速の方法を利用できます。ほとんどのデベロッパーは、特定のエンタープライズ管理が必要な場合を除き、Gemini Developer API を使用する必要があります。

Vertex AI は、Google Cloud Platform を基盤とする生成 AI アプリケーションの構築とデプロイのための、エンタープライズ向けの包括的な機能とサービスのエコシステムを提供します。

Google は最近、これらのサービス間の移行を簡素化しました。Gemini Developer API と Vertex AI Gemini API の両方に、統合された Google Gen AI SDK からアクセスできるようになりました。

コードの比較

このページでは、テキスト生成用の Gemini Developer API クイックスタートと Vertex AI クイックスタートのコードについて比較しています。

Python

google-genai ライブラリを介して、Gemini Developer API と Vertex AI サービスの両方にアクセスできます。google-genai のインストール手順については、ライブラリ ページをご覧ください。

Gemini Developer API

from google import genai

client = genai.Client()

response = client.models.generate_content(
    model="gemini-2.0-flash", contents="Explain how AI works in a few words"
)
print(response.text)

Vertex AI Gemini API

from google import genai

client = genai.Client(
    vertexai=True, project='your-project-id', location='us-central1'
)

response = client.models.generate_content(
    model="gemini-2.0-flash", contents="Explain how AI works in a few words"
)
print(response.text)

JavaScript と TypeScript

@google/genai ライブラリを介して、Gemini Developer API と Vertex AI サービスの両方にアクセスできます。@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-2.0-flash",
    contents: "Explain how AI works in a few words",
  });
  console.log(response.text);
}

main();

Vertex AI Gemini 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-2.0-flash",
    contents: "Explain how AI works in a few words",
  });
  console.log(response.text);
}

main();

Go

google.golang.org/genai ライブラリを介して、Gemini Developer API と Vertex AI サービスの両方にアクセスできます。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-2.0-flash", genai.Text("Tell me about New York?"), nil)

}

Vertex AI Gemini API

import (
  "context"
  "encoding/json"
  "fmt"
  "log"
  "google.golang.org/genai"
)

// Your GCP project
const project = "your-project"

// A GCP 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-2.0-flash", genai.Text("Tell me about New York?"), nil)

}

その他のユースケースとプラットフォーム

他のプラットフォームとユースケースについては、Gemini Developer API のドキュメントVertex AI のドキュメントでユースケース固有のガイドをご覧ください。

移行に関する考慮事項

移行する際は、次の点にご注意ください。

Gemini Developer API の Gemini API キーを使用する必要がなくなった場合は、セキュリティのベスト プラクティスに沿って削除します。

API キーを削除するには:

  1. Google Cloud API 認証情報ページを開きます。

  2. 削除する API キーを見つけて、[操作] アイコンをクリックします。

  3. [API キーを削除] を選択します。

  4. [認証情報の削除] モーダルで、[削除] を選択します。

    API キーの削除が反映されるまでには数分かかることがあります。削除が反映されると、以降その API キーを使ったトラフィックはすべて拒否されます。

次のステップ