Gemini 對話
通過 OpenAI 兼容協議和 Interactions API 調用 Gemini 模型。
Gemini 全系對話模型走 OpenAI Chat Completions 兼容協議:POST https://api.hop-base.com/v1/chat/completions,Authorization: Bearer sk-你的密鑰。現有 OpenAI SDK / 第三方客戶端只需把模型 ID 換成 Gemini,代碼不用改。
可用模型
| 系列 | 模型 ID | 定位 |
|---|---|---|
| Gemini Omni | gemini-omni-flash-preview | 文字 / 圖片 / 視頻輸入 · 視頻輸出 |
| Gemini 3.6 | gemini-3.6-flash | 最新 Flash 主力 |
| Gemini 3.5 | gemini-3.5-flash / gemini-3.5-flash-lite | 速度成本均衡 / 輕量 |
| Gemini 3.1 Pro | gemini-3.1-pro-preview / gemini-3.1-pro-preview-customtools | 高階推理 / 自定義工具調用 |
| Gemini 3.1 | gemini-3.1-flash-lite / gemini-3.1-flash-lite-preview | 輕量低成本 |
| Gemini 3 | gemini-3-flash-preview | 3 代 Flash 預覽 |
| Gemini 2.5 | gemini-2.5-pro / gemini-2.5-flash / gemini-2.5-flash-lite | 穩定版 |
Google 官方基準價中,gemini-3.1-pro-preview 每 100 萬 tokens 輸入 $2 / 輸出 $12。HopBase 的實際價格依當前密鑰所屬分組計算,請以登錄後「模型廣場」為準。
curl 示例
curl https://api.hop-base.com/v1/chat/completions \
-H "Authorization: Bearer sk-你的密鑰" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.5-flash",
"messages": [{"role": "user", "content": "你好"}]
}'流式輸出(SSE,加 "stream": true)
curl https://api.hop-base.com/v1/chat/completions \
-H "Authorization: Bearer sk-你的密鑰" \
-H "Content-Type: application/json" \
-d '{"model": "gemini-3.1-pro-preview", "stream": true,
"messages": [{"role": "user", "content": "你好"}]}'Gemini 原生格式透傳
從 Gemini SDK 遷移的存量請求體不用改:同一端點也接受 Gemini 原生 contents 字段,服務端自動識別並按原生格式轉發。
curl https://api.hop-base.com/v1/chat/completions \
-H "Authorization: Bearer sk-你的密鑰" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.5-flash",
"contents": [{"role": "user", "parts": [{"text": "你好"}]}]
}'Gemini Omni · 視頻生成(原生 Interactions API)
gemini-omni-flash-preview 支持文字、圖片與視頻輸入,並可直接輸出視頻。文字生視頻只需傳 model 和 input;視頻編輯可在輸入內容中傳遠程 uri,或傳 base64 data 並指定 mime_type。完整視頻輸出必須使用 POST https://api.hop-base.com/v1/interactions,不要按 Chat Completions 的文字格式響應解析。
curl https://api.hop-base.com/v1/interactions \
-H "Authorization: Bearer sk-你的密鑰" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-omni-flash-preview",
"input": "生成一段 3 秒視頻:彩色小球在白色背景上慢慢滾動"
}'成功響應(視頻位於 steps[].content[])
{
"status": "completed",
"model": "gemini-omni-flash-preview",
"steps": [{
"type": "model_output",
"content": [{
"type": "video",
"mime_type": "video/mp4",
"data": "<base64-mp4>"
}]
}],
"usage": {
"total_input_tokens": 20,
"total_output_tokens": 17819,
"output_tokens_by_modality": [{"modality": "video", "tokens": 17376}]
}
}Omni 限制:輸入視頻最長 10 秒,可用於視頻編輯;輸出視頻為 3–10 秒、720p、24 FPS。輸出是 base64 MP4,請解碼 steps[].content[].data 後保存。
✅ 請使用 Gemini 分組密鑰,並只調用當前密鑰 GET /v1/models 返回的模型 ID。