Gemini Developer API לעומת Vertex AI

כשמפתחים פתרונות של AI גנרטיבי באמצעות Gemini, Google מציעה שני מוצרי API: Gemini Developer API ו-Vertex AI Gemini API.

Gemini Developer API הוא הדרך המהירה ביותר לפתח אפליקציות מבוססות-Gemini, להעביר אותן לסביבת הייצור ולהרחיב אותן. רוב המפתחים צריכים להשתמש ב-Gemini Developer API, אלא אם יש צורך באמצעי בקרה ספציפיים לארגון.

Vertex AI מציע סביבה עסקית מקיפה של תכונות ושירותים לעסקים, שמאפשרת ליצור ולפרוס אפליקציות של 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. הוראות להתקנת 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 מוסבר איך להתקין את @google/genai.

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 מוסבר איך להתקין את 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, &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 מפורט מידע נוסף על פלטפורמות ותרחישי שימוש אחרים.

שיקולים לגבי העברה

במהלך ההעברה:

אם אתם לא צריכים יותר להשתמש במפתח Gemini API לממשק Gemini Developer API, עליכם למחוק אותו לפי השיטות המומלצות לאבטחה.

כדי למחוק מפתח API:

  1. פותחים את הדף Google Cloud API Credentials.

  2. מאתרים את מפתח ה-API שרוצים למחוק ולוחצים על הסמל Actions.

  3. בוחרים באפשרות Delete API key (מחיקת מפתח ה-API).

  4. בחלון הדו-שיח Delete credential, בוחרים באפשרות Delete.

    המחיקה של מפתח API יכולה להימשך כמה דקות. אחרי שההפצה תושלם, כל תעבורת הנתונים שמשתמשת במפתח ה-API שנמחק תידחה.

השלבים הבאים