Gemini 3.5 Flash API
由 Google 提供支援的 Gemini 3.5 Flash 大模型完整 API 參考。
模型版本
此 API 支援三個 Gemini 3.5 Flash 模型變體:
快速比較
Gemini 3.5 Flash Text to Text
端點
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 Image to Text
端點
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 File Analysis
端點
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
})
});
回應格式
Gemini 3.5 Flash 大模型會返回 Google 相容的 completion 回應。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] 視為成功完成。
- 僅傳送支援的輸入: 在目前用戶端中,文字模型會忽略不支援的檔案與圖片部分。