通過統一端點呼叫 Gemini 2.x / 3.x 全系, 支援文本 + 影像多模態輸入與 thinking
POST /v1/chat/completions
鉴权: {'type': 'bearer', 'prefix': 'sk-', 'description': 'API Key, 使用 `Authorization: Bearer sk-xxx` 鉴权'}
Gemini 模型完全相容 OpenAI Chat Completions 協議。本頁展示 Gemini 特有能力: - **多模態內容陣列**: `content` 可以是 `[{type:"text",text:...},{type:"image_url",image_url:{url:...}}]` - **Thinking / 推理**: 2.5 Pro / 3.1 Pro Preview 可通過 `reasoning_effort: "low"|"medium"|"high"` 開啟深度推理 - **長上下文**: 2.5 Pro 支援 200K tokens, Flash 128K+ - **結構化輸出**: `response_format: {type:"json_object"}` 或傳 `response_mime_type`
model | string | required | Gemini 模型 ID, 如 `gemini-2.5-pro` / `gemini-2.5-flash` / `gemini-2.5-flash-lite` / `gemini-3.1-pro-preview` / `gemini-3.1-flash-lite-preview` |
messages | array | required | 多模態訊息陣列。`content` 可為字串或混合陣列 |
role | string | required | |
content | string | required | 文本字串, 或內容塊陣列 `[{"type":"text","text":"..."},{"type":"image_url","image_url":{"url":"https://..."}}]` |
temperature | number | ||
top_p | number | ||
top_k | integer | (Gemini 特有) Top-K 取樣, 建議不與 top_p 同時使用 | |
max_tokens | integer | ||
stream | boolean | ||
reasoning_effort | string | (僅 2.5 Pro / 3.1 Pro Preview) 思考深度, high 更準但更慢 | |
response_format | object | 如 `{"type":"json_object"}` 強制 JSON 輸出 | |
stop | array |
200 — Gemini 生成結果 (OpenAI 格式)curl https://api.router.ai/v1/chat/completions \
-H "Authorization: Bearer sk-xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-2.5-pro",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "这张图里是什么?"},
{"type": "image_url", "image_url": {"url": "https://example.com/cat.jpg"}}
]
}
],
"reasoning_effort": "medium"
}'