> For AI agents: the complete documentation index is available at https://little-butterfly-9bfe.sentia389.workers.dev/llms.txt, the full documentation bundle is available at https://little-butterfly-9bfe.sentia389.workers.dev/llms-full.txt.

# Gemini 4

Google Cloud 的 Neon、Hydrogen、Carbon 和 Argon 均支持原生 GenerateContent 和 OpenAI 兼容 Chat Completions。Gemini Developer API 也在模型目录列出这四个 ID，提供原生 GenerateContent 入口。Developer API 的 OpenAI 兼容指南以 Hydrogen 为例，并明确列出 Neon 和 Hydrogen 的 `reasoning_effort: "xhigh"`。使用该兼容入口前，可用同一 Gemini API Key 查询 `GET /v1beta/openai/models`。见[模型目录与入口](https://little-butterfly-9bfe.sentia389.workers.dev/models/google/index.md#%E7%9B%B4%E8%BF%9E-google-%E5%AE%98%E6%96%B9-api)。

| Google 模型 ID        | 适用场景                 | 原生 `thinkingLevel`                | 单段输出上限（token）               |
| ------------------- | -------------------- | --------------------------------- | --------------------------- |
| `gemini-4-neon`     | 低延迟的复杂代码、多步推理和多模态工作流 | `LOW`、`MEDIUM`、`HIGH`（默认）、`XHIGH` | 65,536                      |
| `gemini-4-hydrogen` | 注重速度的日常代码、分析和工具调用    | `LOW`、`MEDIUM`、`HIGH`（默认）、`XHIGH` | 65,536                      |
| `gemini-4-carbon`   | 深度分析、复杂工程和长流程任务      | `LOW`、`MEDIUM`（默认）、`HIGH`         | 流式 65,536，直接非流式 HTTP 32,768 |
| `gemini-4-argon`    | 注重推理效率的复杂代码、数学和科学任务  | `LOW`、`MEDIUM`（默认）、`HIGH`         | 流式 65,536，直接非流式 HTTP 32,768 |

Gemini 4 的输入与输出共用 1,048,576 token，输出包括推理、函数调用和最终文本。超过单段限制的长输出可用原生 GenerateContent 或 Interactions API 续生成。Google Cloud 的 GenerateContent 续生成需要 `v1beta1`，OpenAI 兼容 Chat 接口不提供该续生成机制。

## Gemini Developer API 原生示例

设置 `GEMINI_API_KEY` 为 Google AI Studio 的 Gemini API Key。用 `generationConfig.thinkingConfig.thinkingLevel` 设置原生推理档。`generationConfig.maxOutputTokens` 设置输出预算，同时为输入预留上下文。

```bash
curl --fail-with-body --silent --show-error \
  --url 'https://generativelanguage.googleapis.com/v1beta/models/gemini-4-neon:generateContent' \
  --header "x-goog-api-key: ${GEMINI_API_KEY:?请设置 Gemini API Key}" \
  --header 'Content-Type: application/json' \
  --data-binary '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "请用一句话解释为什么需要备份。"
          }
        ]
      }
    ],
    "generationConfig": {
      "thinkingConfig": {
        "thinkingLevel": "LOW"
      }
    }
  }'
```

非流式响应节选如下，从 `candidates[].content.parts[].text` 读取正文。

```json
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "text": "备份可以在原始数据丢失或损坏时帮助恢复。"
          }
        ]
      },
      "finishReason": "STOP"
    }
  ]
}
```

原生流式请求改用 `:streamGenerateContent?alt=sse`。从 Gemini 3 迁移时，移除原生请求的 `thinkingBudget`，并选择表中的 `thinkingLevel`。

## 改用 OpenAI 兼容 Chat

将原生请求的 `contents` 改写为 `messages`。在 Google Cloud 兼容入口，`max_tokens` 对应输出预算，`max_completion_tokens` 是它的别名。推理参数在顶层 `reasoning_effort` 和 `extra_body.google.thinking_config` 中二选一。Gemini Developer API 有独立的 `reasoning_effort` 映射，先按所用服务核对目标型号的可选档位。[Google Cloud 支持的参数](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/migrate/openai/overview#supported-parameters) · [Gemini Developer API 推理映射](https://aistudio.google.com/docs/openai#thinking)

通过 routerlio 调用时，按[网关型号查询](https://little-butterfly-9bfe.sentia389.workers.dev/models/google/index.md#%E9%80%9A%E8%BF%87-routerlio-%E8%B0%83%E7%94%A8)选择令牌可见的 ID，按渠道支持选择[原生接口](https://little-butterfly-9bfe.sentia389.workers.dev/start/gemini.md)或 [Chat Completions](https://little-butterfly-9bfe.sentia389.workers.dev/start/chat-completions.md)，再确认该渠道能接收的推理字段。

## 官方参考

- [Gemini 4 Neon 规格](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/4-neon)
- [Gemini 4 Hydrogen 规格](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/4-hydrogen)
- [Gemini 4 Carbon 规格](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/4-carbon)
- [Gemini 4 Argon 规格](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/4-argon)
- [Google Cloud Gemini 4 推理与续生成指南](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/start/get-started-with-gemini-4)
- [Google Cloud Chat Completions 支持清单](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/migrate/openai/overview#supported-models)
- [Gemini Developer API OpenAI 兼容指南](https://aistudio.google.com/docs/openai)
