> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openp.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Gemini 模型

> Gemini 3 预览版与 2.5 系列,以及思考、多模态、嵌入

OpenPAI 同时支持 **OpenAI 兼容协议** 与 **Gemini 原生协议**(`/v1beta/models/{model}:generateContent`),覆盖 Google 最新的 Gemini 3 预览版以及稳定的 2.5 系列。

## Gemini 3 系列(当前主力)

新一代旗舰,适合代理、复杂推理、实时语音等场景,目前是 Google 主推的系列。

| 模型 ID                           | 类型         | 定位                      |
| ------------------------------- | ---------- | ----------------------- |
| `gemini-3.1-pro-preview`        | 对话 / Agent | 最智能,顶级推理与代理能力,适合复杂多步任务  |
| `gemini-3.5-flash`              | 对话         | 前沿级性能,可媲美更大模型           |
| `gemini-3-flash`                | 对话         | 前沿能力 + 更低成本             |
| `gemini-3.1-flash-lite`         | 对话         | 高性能 + 极低成本,适合大批量轻量任务    |
| `gemini-3.1-flash-live-preview` | 实时音频       | 语音优先应用,双向低延迟流(Live API) |
| `gemini-3.1-flash-tts-preview`  | 语音合成       | 低延迟、自然的 TTS             |

<Note>预览(preview)模型可能随时调整接口与价格,生产建议同时配置一个稳定模型兜底。具体可用 ID 以 [控制台 → 模型](https://openp.ai/dashboard/models) 为准。</Note>

## Gemini 2.5 系列(稳定)

| 模型 ID                                   | 上下文 | 定位           |
| --------------------------------------- | --- | ------------ |
| `gemini-2.5-pro`                        | 1M  | 最强通用推理与代码    |
| `gemini-2.5-flash`                      | 1M  | 推理任务的最佳性价比   |
| `gemini-2.5-flash-lite`                 | 1M  | 最快、最便宜的多模态选项 |
| `gemini-2.5-flash-native-audio-preview` | 1M  | 亚秒级原生音频流     |

## 思考与推理强度

Gemini 2.5 / 3 系列支持 **显式思考预算**。两种方式皆可:

### 通过参数

```python theme={null}
resp = client.models.generate_content(
    model="gemini-2.5-pro",
    contents="证明哥德巴赫猜想",
    config=types.GenerateContentConfig(
        thinking_config=types.ThinkingConfig(thinking_budget=8000),
    ),
)
```

### 通过模型 ID 后缀

OpenPAI 透传以下模型 ID 别名,内部映射为相应的思考配置:

| 模型 ID                            | 行为                  |
| -------------------------------- | ------------------- |
| `gemini-2.5-pro-thinking`        | 默认中等思考预算            |
| `gemini-2.5-pro-thinking-128`    | 强制 128 token 思考     |
| `gemini-2.5-flash-thinking`      | Flash + 思考开启        |
| `gemini-2.5-flash-nothinking`    | Flash + 思考关闭(更便宜)   |
| `gemini-2.5-pro-low/medium/high` | 推理强度逐级提升            |
| `gemini-3.1-pro-preview-high`    | Gemini 3 Pro 最高推理预算 |

## 多模态生成

| 模型 ID                    | 用途                     |
| ------------------------ | ---------------------- |
| `nano-banana-pro`        | 顶级视觉创作 / 4K 专业设计       |
| `nano-banana-2`          | 高效图像生成 / 编辑            |
| `gemini-2.5-flash-image` | 原生图像生成 / 编辑            |
| `imagen-4`               | 极速文生图(2K)              |
| `veo-3.1`                | 视频生成(含原生音频),是否开放以控制台为准 |

调用示例:

```bash theme={null}
curl "https://openp.ai/v1beta/models/gemini-2.5-flash-image:generateContent" \
  -H "x-goog-api-key: $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"role":"user","parts":[{"text":"A red panda surfing, cartoon style"}]}],
    "generationConfig": {"responseModalities": ["IMAGE"]}
  }'
```

## 嵌入模型

| 模型 ID                  | 维度       | 定位             |
| ---------------------- | -------- | -------------- |
| `gemini-embedding-2`   | 3072(可缩) | 最新多模态嵌入,语义检索首选 |
| `gemini-embedding-001` | 3072(可缩) | 文本嵌入,RAG / 分类  |
| `text-embedding-004`   | 768      | 旧版,兼容用途        |

## 调用示例

### OpenAI 兼容协议

```python theme={null}
from openai import OpenAI
client = OpenAI(api_key="sk-...", base_url="https://openp.ai/v1")

resp = client.chat.completions.create(
    model="gemini-3.1-pro-preview",
    messages=[{"role": "user", "content": "用中文解释什么是傅立叶变换"}],
)
print(resp.choices[0].message.content)
```

### Gemini 原生协议

```bash theme={null}
curl "https://openp.ai/v1beta/models/gemini-3.1-pro-preview:generateContent" \
  -H "x-goog-api-key: $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"role":"user","parts":[{"text":"hello"}]}],
    "generationConfig": { "temperature": 0.7, "maxOutputTokens": 2048 }
  }'
```

### google-genai SDK

```python theme={null}
from google import genai

client = genai.Client(
    api_key="sk-XXXXXXXXXXXXXXXX",
    http_options={"base_url": "https://openp.ai"},
)

resp = client.models.generate_content(
    model="gemini-3.1-pro-preview",
    contents="给我 3 个旅行 vlog 标题",
)
print(resp.text)
```

## 视觉与多模态输入

Gemini 原生支持图片、PDF、音频、视频输入:

```json theme={null}
{
  "contents": [{
    "role": "user",
    "parts": [
      {"text": "总结这张图"},
      {"inline_data": {"mime_type": "image/png", "data": "<base64>"}}
    ]
  }]
}
```

## 函数调用

完整支持 Gemini `function_declarations` 与 `function_call`,通过 OpenAI 兼容端点访问时会自动转换为 `tools` / `tool_calls` 结构。详见 [函数调用](/advanced/function-calling)。

## 接口文档

* [generateContent](/api-reference/gemini/generate-content)
* [streamGenerateContent](/api-reference/gemini/stream-generate-content)
* [embedContent](/api-reference/gemini/embed-content)
