Gemini Developer API เทียบกับ Vertex AI

เมื่อพัฒนาโซลูชัน Generative AI ด้วย Gemini ทาง Google มีผลิตภัณฑ์ API 2 รายการ ได้แก่ Gemini Developer API และ Vertex AI Gemini API

Gemini Developer API เป็นเส้นทางที่เร็วที่สุดในการสร้าง ใช้งานจริง และปรับขนาดแอปพลิเคชันที่ทำงานด้วย Gemini นักพัฒนาซอฟต์แวร์ส่วนใหญ่ควรใช้ Gemini Developer API เว้นแต่จะมีความจำเป็นในการควบคุมองค์กรที่เฉพาะเจาะจง

Vertex AI มีระบบนิเวศที่ครอบคลุมของฟีเจอร์และบริการที่พร้อมใช้งานสำหรับองค์กรสําหรับการสร้างและใช้งานแอปพลิเคชัน Generative 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 ได้จากหน้าคลัง

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

คุณสามารถเข้าถึงทั้ง Gemini Developer API และบริการ Vertex AI ผ่าน@google/genai ไลบรารี ดูวิธีการติดตั้ง @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

คุณสามารถเข้าถึงทั้ง Gemini Developer API และบริการ Vertex AI ผ่านgoogle.golang.org/genai ไลบรารี ดูวิธีการติดตั้ง 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)

}

กรณีการใช้งานและแพลตฟอร์มอื่นๆ

ดูคำแนะนำเฉพาะกรณีการใช้งานในเอกสารประกอบ API สำหรับนักพัฒนาซอฟต์แวร์ของ Gemini และเอกสารประกอบ Vertex AI สำหรับแพลตฟอร์มและกรณีการใช้งานอื่นๆ

ข้อควรพิจารณาในการย้ายข้อมูล

สิ่งที่จะเกิดขึ้นเมื่อคุณย้ายข้อมูล

หากไม่จําเป็นต้องใช้คีย์ Gemini API สําหรับ Gemini Developer API อีกต่อไป ให้ทําตามแนวทางปฏิบัติแนะนําด้านความปลอดภัยและลบคีย์

วิธีลบคีย์ API

  1. เปิดหน้าข้อมูลเข้าสู่ระบบ Google Cloud API

  2. ค้นหาคีย์ API ที่ต้องการลบ แล้วคลิกไอคอนการดําเนินการ

  3. เลือกลบคีย์ API

  4. ในโมดัลลบข้อมูลเข้าสู่ระบบ ให้เลือกลบ

    การลบคีย์ API จะใช้เวลาสักครู่จึงจะมีผล หลังจากการนำไปใช้งานเสร็จสมบูรณ์แล้ว ระบบจะปฏิเสธการเข้าชมที่ใช้คีย์ API ที่ลบไปแล้ว

ขั้นตอนถัดไป