Gemini を使用して生成 AI ソリューションを開発する場合、Google は Gemini Developer API と Vertex AI Gemini API の 2 つの API プロダクトを提供しています。
Gemini Developer API は、Gemini を活用したアプリケーションの構築、本番環境への移行、スケーリングを迅速に行うための手段です。特定のエンタープライズ コントロールが必要な場合を除き、ほとんどのデベロッパーは Gemini デベロッパー API を使用する必要があります。
Vertex AI は、Google Cloud Platform を基盤とする生成 AI アプリケーションの構築とデプロイのための、エンタープライズ対応の機能とサービスの包括的なエコシステムを提供します。
最近、これらのサービス間の移行を簡素化しました。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 ドキュメントのユースケース固有のガイドをご覧ください。
移行に関する考慮事項
移行すると、次のようになります。
認証には Google Cloud サービス アカウントを使用する必要があります。詳細については、Vertex AI のドキュメントをご覧ください。
既存の Google Cloud プロジェクト(API キーの生成に使用したプロジェクト)を使用することも、新しい Google Cloud プロジェクトを作成することもできます。
サポートされているリージョンは、Gemini Developer API と Vertex AI Gemini API で異なる場合があります。Google Cloud の生成 AI でサポートされているリージョンのリストをご覧ください。
Google AI Studio で作成したモデルは、Vertex AI で再トレーニングする必要があります。
Gemini Developer API で Gemini API キーを使用する必要がなくなった場合は、セキュリティのベスト プラクティスに沿って、それを削除します。
API キーを削除するには:
Google Cloud API 認証情報ページを開きます。
削除する API キーを見つけて、[操作] アイコンをクリックします。
[API キーを削除] を選択します。
[認証情報の削除] モーダルで、[削除] を選択します。
API キーの削除が反映されるまでには数分かかることがあります。削除が反映されると、以降その API キーを使ったトラフィックはすべて拒否されます。
次のステップ
- Vertex AI の生成 AI ソリューションの詳細については、Vertex AI の生成 AI の概要をご覧ください。