Gemini 3.5 Flash API
เอกสารอ้างอิง API ฉบับสมบูรณ์สำหรับโมเดล Gemini 3.5 Flash โมเดลภาษาขนาดใหญ่ ที่ขับเคลื่อนโดย Google.
ตัวเลือกโมเดล {#}
API นี้รองรับโมเดล Gemini 3.5 Flash 3 รูปแบบ:
เปรียบเทียบอย่างรวดเร็ว
Gemini 3.5 Flash ข้อความเป็นข้อความ
จุดเชื่อมต่อ
POST /api/v1/chat/completions
พารามิเตอร์คำขอ
จำเป็น
การรองรับข้อความ
ไม่บังคับ
ตัวอย่างคำขอ
const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Accept': 'text/event-stream',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gemini-3.5-flash-text-to-text',
messages: [
{
role: 'user',
content: 'Write a concise summary of how transformer models work.'
}
],
stream: true,
max_tokens: 2048
})
});
Gemini 3.5 Flash รูปภาพเป็นข้อความ
จุดเชื่อมต่อ
POST /api/v1/chat/completions
พารามิเตอร์คำขอ
จำเป็น
การรองรับข้อความ
ไม่บังคับ
ตัวอย่างคำขอ
const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Accept': 'text/event-stream',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gemini-3.5-flash-image-to-text',
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'Describe the image and extract any visible text.' },
{
type: 'image_url',
image_url: {
url: 'https://example.com/sample-image.jpg'
}
}
]
}
],
stream: true,
max_tokens: 2048
})
});
Gemini 3.5 Flash การวิเคราะห์ไฟล์
จุดเชื่อมต่อ
POST /api/v1/chat/completions
พารามิเตอร์คำขอ
จำเป็น
การรองรับข้อความ
ไม่บังคับ
ตัวอย่างคำขอ
const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Accept': 'text/event-stream',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gemini-3.5-flash-file-analysis',
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'Summarize this file and extract the key risks.' },
{
type: 'file',
file: {
filename: 'demo.pdf',
file_data: 'https://example.com/demo.pdf'
}
}
]
}
],
stream: true,
max_tokens: 4096
})
});
รูปแบบการตอบกลับ
โมเดล LLM Gemini 3.5 Flash ส่งคืนการตอบกลับ completion ที่เข้ากันได้กับ Google เมื่อใช้ stream: true การตอบกลับจะเป็น Server-Sent Events; เมื่อใช้ stream: false การตอบกลับจะเป็นออบเจกต์ JSON เดี่ยว
การตอบกลับเมื่อสำเร็จ
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"gemini-3.5-flash-text-to-text","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"gemini-3.5-flash-text-to-text","choices":[{"index":0,"delta":{"content":"Here is a concise summary"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"gemini-3.5-flash-text-to-text","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"gemini-3.5-flash-text-to-text","choices":[],"usage":{"prompt_tokens":12,"completion_tokens":8,"total_tokens":20}}
data: [DONE]
การตอบกลับข้อผิดพลาด
event: error
data: {"error":{"message":"API requests too frequent, exceeding rate limit","type":"rate_limit_error","code":"1302","param":null}}
แนวทางปฏิบัติที่ดี
- ใช้ข้อความแบบมีโครงสร้าง: ส่งประวัติการสนทนาผ่าน
messages[] แทนการรวมบริบททั้งหมดไว้ใน prompt เดียว
- เลือกตัวแปรโมเดลให้เหมาะสม: ใช้ Text to Text สำหรับงานข้อความเท่านั้น ใช้ Image to Text สำหรับการทำความเข้าใจรูปภาพ และใช้ File Analysis เมื่อต้องการเอกสารหรือเนื้อหาแบบผสม
- ประมวลผลอีเวนต์ SSE: เพิ่ม
choices[0].delta.content สำหรับการแสดงผลแบบสตรีม และถือว่า data: [DONE] คือการเสร็จสิ้นสำเร็จ
- ส่งเฉพาะอินพุตที่รองรับ: ในไคลเอนต์ปัจจุบัน โมเดลข้อความจะละเว้นส่วนไฟล์และรูปภาพที่ไม่รองรับ