כשמפתחים פתרונות של AI גנרטיבי באמצעות Gemini, המפתחים יכולים לבחור בין Gemini Developer API לבין Vertex AI Gemini API.
Gemini Developer API מספק דרך קלה לפתח אפליקציות Gemini, להעביר אותן לסביבת הייצור ולהרחיב אותן. Vertex AI מציע סביבה עסקית מקיפה של תכונות ושירותים שמוכנים לשימוש בארגונים, ליצירה ולפריסה של אפליקציות בינה מלאכותית גנרטיבית שמגובות על ידי פלטפורמת Google Cloud.
הבחירה הטובה ביותר תלויה בצרכים שלכם, אבל לאחרונה הפכנו את המעבר בין השירותים האלה לפשוט יותר. עכשיו אפשר לגשת גם ל-Gemini Developer API וגם ל-Vertex AI Gemini API דרך Google Gen AI SDK המאוחד, שמציע גמישות רבה יותר.
השוואת קוד
בהמשך מופיעות כמה השוואות של קוד זה לצד זה בין Gemini Developer API לבין מדריכי למתחילים של Vertex AI ליצירת טקסט.
Python
אפשר לגשת ל-Gemini Developer API ולשירותי Vertex AI דרך הספרייה google-genai
.
הוראות להתקנת הספרייה מפורטות בדף libraries.
Gemini Developer API
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)
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
אפשר לגשת ל-Gemini Developer API ולשירותי Vertex AI דרך הספרייה @google/genai
.
הוראות להתקנת הספרייה מפורטות בדף libraries.
Gemini Developer API
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();
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
אפשר לגשת ל-Gemini Developer API ולשירותי Vertex AI דרך הספרייה google.golang.org/genai
.
הוראות להתקנת הספרייה מפורטות בדף libraries.
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, &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)
}
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. הרשימה של האזורים הנתמכים ל-AI גנרטיבי ב-Google Cloud
כל המודלים שיצרתם ב-Google AI Studio צריכים לעבור אימון מחדש ב-Vertex AI.
אם אתם כבר לא צריכים להשתמש במפתח Gemini API לממשק Gemini Developer API, כדאי למחוק אותו לפי השיטות המומלצות לאבטחה.
כדי למחוק מפתח API:
פותחים את הדף Google Cloud API Credentials.
מאתרים את מפתח ה-API שרוצים למחוק ולוחצים על הסמל Actions.
בוחרים באפשרות Delete API key (מחיקת מפתח ה-API).
בחלון הדו-שיח Delete credential, בוחרים באפשרות Delete.
המחיקה של מפתח API יכולה להימשך כמה דקות. אחרי שההפצה תושלם, כל תעבורת הנתונים שמשתמשת במפתח ה-API שנמחק תידחה.