เมื่อพัฒนาโซลูชัน Generative AI ด้วย Gemini ทาง Google มีผลิตภัณฑ์ API 2 รายการ ได้แก่ Gemini Developer API และ Gemini Platform API
Gemini Developer API เป็นเส้นทางที่เร็วที่สุดในการสร้าง ทำให้พร้อมใช้งานจริง และ ปรับขนาดแอปพลิเคชันที่ทำงานด้วย Gemini นักพัฒนาแอปส่วนใหญ่ควรใช้ Gemini Developer API เว้นแต่จะจำเป็นต้องใช้การควบคุมเฉพาะสำหรับองค์กร
แพลตฟอร์ม Gemini มีระบบนิเวศที่ครอบคลุมของฟีเจอร์และบริการที่พร้อมใช้งานในองค์กร สำหรับการสร้างและติดตั้งใช้งานแอปพลิเคชัน Generative AI ที่ขับเคลื่อนโดย Google Cloud
เมื่อเร็วๆ นี้ เราได้ทำให้การย้ายข้อมูลระหว่างบริการเหล่านี้ง่ายขึ้น ตอนนี้คุณเข้าถึงทั้ง Gemini Developer API และ Gemini Platform API ได้แล้ว ผ่าน Google GenAI SDK แบบรวมและ Interactions API
การเปรียบเทียบโค้ด: Interactions API (แนะนํา)
Interactions API เป็นวิธีที่แนะนําในการสร้างด้วยโมเดลและเอเจนต์ของ Gemini ตัวอย่างต่อไปนี้ เปรียบเทียบการสร้างข้อความระหว่าง Gemini Developer API กับแพลตฟอร์ม Gemini
Python
คุณเข้าถึงทั้ง Gemini Developer API และบริการแพลตฟอร์ม Gemini
ได้ผ่านไลบรารี google-genai (>= 2.3.0) ดูวิธีการติดตั้ง
google-genai ได้ในหน้าไลบรารี
Gemini Developer API
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.8-flash",
input="Explain how AI works in a few words",
)
print(interaction.output_text)
Gemini Platform API
from google import genai
client = genai.Client(
enterprise=True, project="your-project-id", location="global"
)
interaction = client.interactions.create(
model="gemini-3.8-flash",
input="Explain how AI works in a few words",
)
print(interaction.output_text)
JavaScript และ TypeScript
คุณสามารถเข้าถึงทั้ง Gemini Developer API และบริการแพลตฟอร์ม Gemini
ผ่านไลบรารี @google/genai (>= 2.3.0) ดูวิธีการติดตั้ง
@google/genai ได้ในหน้าไลบรารี
Gemini Developer API
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
const interaction = await ai.interactions.create({
model: "gemini-3.8-flash",
input: "Explain how AI works in a few words",
});
console.log(interaction.output_text);
Gemini Platform API
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({
enterprise: true,
project: "your_project",
location: "global",
});
const interaction = await ai.interactions.create({
model: "gemini-3.8-flash",
input: "Explain how AI works in a few words",
});
console.log(interaction.output_text);
การเปรียบเทียบโค้ด: API ของ generateContent
แม้ว่าเราจะแนะนำให้ใช้ Interactions API สำหรับโปรเจ็กต์ใหม่ แต่ระบบจะยังคงรองรับ generateContent API ต่อไป
Python
คุณสามารถเข้าถึงทั้ง Gemini Developer API และบริการแพลตฟอร์ม Gemini
ได้ผ่านไลบรารี google-genai ดูวิธีการติดตั้ง
google-genaiได้ที่หน้าไลบรารี
Gemini Developer API
from google import genai
client = genai.Client()
response = client.models.generate_content(
model="gemini-3.8-flash", contents="Explain how AI works in a few words"
)
print(response.text)
Gemini Platform API
from google import genai
client = genai.Client(
vertexai=True, project='your-project-id', location='us-central1'
)
response = client.models.generate_content(
model="gemini-3.8-flash", contents="Explain how AI works in a few words"
)
print(response.text)
JavaScript และ TypeScript
คุณสามารถเข้าถึงทั้ง Gemini Developer API และบริการแพลตฟอร์ม Gemini
ผ่าน@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-3.8-flash",
contents: "Explain how AI works in a few words",
});
console.log(response.text);
}
main();
Gemini Platform 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-3.8-flash",
contents: "Explain how AI works in a few words",
});
console.log(response.text);
}
main();
Go
คุณสามารถเข้าถึงทั้ง Gemini Developer API และบริการแพลตฟอร์ม Gemini
ผ่านgoogle.golang.org/genai library ดูวิธีการติดตั้ง
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-3.8-flash", genai.Text("Tell me about New York?"), nil)
}
Gemini Platform API
import (
"context"
"encoding/json"
"fmt"
"log"
"google.golang.org/genai"
)
// Your Google Cloud project
const project = "your-project"
// A Google Cloud 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-3.8-flash", genai.Text("Tell me about New York?"), nil)
}
กรณีการใช้งานและแพลตฟอร์มอื่นๆ
ดูคำแนะนำเฉพาะสำหรับ Use Case ในเอกสารประกอบเกี่ยวกับ Gemini Developer API และเอกสารประกอบเกี่ยวกับแพลตฟอร์ม Gemini สำหรับแพลตฟอร์มและ Use Case อื่นๆ
ข้อควรพิจารณาในการย้ายข้อมูล
สิ่งที่จะเกิดขึ้นเมื่อคุณย้ายข้อมูล
คุณจะต้องใช้บัญชีบริการของ Google Cloud เพื่อตรวจสอบสิทธิ์ ดูข้อมูลเพิ่มเติมได้ที่ เอกสารประกอบเกี่ยวกับแพลตฟอร์ม Gemini
คุณสามารถใช้โปรเจ็กต์ Google Cloud ที่มีอยู่ (โปรเจ็กต์เดียวกับที่ใช้สร้างคีย์ API) หรือจะสร้างโปรเจ็กต์ Google Cloud ใหม่ก็ได้
ภูมิภาคที่รองรับอาจแตกต่างกันระหว่าง Gemini Developer API กับ Gemini Platform API ในระหว่างเวอร์ชันตัวอย่าง Interactions API ในแพลตฟอร์ม Gemini รองรับเฉพาะปลายทาง
global(location="global") โปรดดูรายการภูมิภาคที่รองรับสำหรับ Generative AI ใน Google Cloudคุณต้องฝึกโมเดลที่สร้างใน Google AI Studio อีกครั้งในแพลตฟอร์ม Gemini
หากไม่จำเป็นต้องใช้คีย์ Gemini API สำหรับ Gemini Developer API อีกต่อไป โปรดทำตามแนวทางปฏิบัติแนะนำด้านความปลอดภัยและลบคีย์ดังกล่าว
วิธีลบคีย์ API
ค้นหาคีย์ API ที่ต้องการลบ แล้วคลิกไอคอนการดำเนินการ
เลือกลบคีย์ API
ในโมดัลลบข้อมูลเข้าสู่ระบบ ให้เลือกลบ
การลบคีย์ API จะใช้เวลาสักครู่ในการเผยแพร่ หลังจาก การเผยแพร่เสร็จสมบูรณ์แล้ว ระบบจะปฏิเสธการเข้าชมที่ใช้คีย์ API ที่ลบไปแล้ว
ขั้นตอนถัดไป
- ดูข้อมูลเพิ่มเติมได้ในคู่มือนักพัฒนาซอฟต์แวร์เกี่ยวกับ Interactions API บนแพลตฟอร์ม Gemini
- ดูข้อมูลเพิ่มเติมเกี่ยวกับโซลูชัน Generative AI บนแพลตฟอร์ม Gemini ได้ที่ ภาพรวมของ Generative AI บนแพลตฟอร์ม Gemini