Gemini で生成 AI ソリューションを開発する場合、Gemini Developer API と Vertex AI Gemini API のどちらかを選択します。
Gemini Developer API を使用すると、Gemini アプリケーションの構築、本番環境への移行、スケーリングを簡単に行うことができます。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 サービスの両方にアクセスできます。ライブラリのインストール手順については、ライブラリのページをご覧ください。
from google import genai
client = genai.Client(api_key="YOUR_API_KEY ")
response = client.models.generate_content(
model="gemini-2.0-flash", contents="Explain how AI works in a few words"
)
print(response.text)
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 サービスの両方にアクセスできます。ライブラリのインストール手順については、ライブラリのページをご覧ください。
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: "YOUR_API_KEY " });
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();
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 サービスの両方にアクセスできます。ライブラリのインストール手順については、ライブラリのページをご覧ください。
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, &genai.ClientConfig{
APIKey: apiKey,
Backend: genai.BackendGeminiAPI,
})
// Call the GenerateContent method.
result, err := client.Models.GenerateContent(ctx, "gemini-2.0-flash", genai.Text("Tell me about New York?"), nil)
}
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 デベロッパー 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 の概要をご覧ください。