Gemini 聊天 (含多模态)

通过统一端点调用 Gemini 2.x / 3.x 全系, 支持文本 + 图像多模态输入与 thinking

POST /v1/chat/completions

Auth: {'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`

Request body

modelstringrequiredGemini 模型 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`
messagesarrayrequired多模态消息数组。`content` 可为字符串或混合数组
    rolestringrequired
    contentstringrequired文本字符串, 或内容块数组 `[{"type":"text","text":"..."},{"type":"image_url","image_url":{"url":"https://..."}}]`
temperaturenumber
top_pnumber
top_kinteger(Gemini 特有) Top-K 采样, 建议不与 top_p 同时使用
max_tokensinteger
streamboolean
reasoning_effortstring(仅 2.5 Pro / 3.1 Pro Preview) 思考深度, high 更准但更慢
response_formatobject如 `{"type":"json_object"}` 强制 JSON 输出
stoparray

Responses

Example

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"
  }'

API reference