---
title: &quot;透過 RunAPI 在 OpenClaw 中使用 Gemini — LLM API 指南&quot;
url: &quot;https://runapi.ai/zh-HK/openclaw-gemini.md&quot;
canonical: &quot;https://runapi.ai/zh-HK/openclaw-gemini&quot;
locale: &quot;zh-HK&quot;
model: &quot;gemini&quot;
---

# 在 OpenClaw 中使用 Gemini。

Google Gemini 可透過 RunAPI 的 OpenAI 相容端點使用 — Gemini 3.5 Flash 提供低於 100ms 的首 token 延遲，3.x Pro 適合複雜推理，2.5 Pro 則適用於正式環境工作負載。OpenClaw 將其視為另一個 OpenAI 相容模型，因此驅動 GPT 的同一個 provider 設定和 RUNAPI_API_KEY 也能呼叫 Gemini。不需要 Google Cloud 專案、Service Account 或 Vertex AI 設定。

## API example

```bash
curl -X POST https://runapi.ai/v1/chat/completions \
  -H &quot;Authorization: Bearer $RUNAPI_API_KEY&quot; \
  -H &quot;Content-Type: application/json&quot; \
  -d &#39;{
    &quot;model&quot;: &quot;gemini-3.5-flash&quot;,
    &quot;messages&quot;: [
      {&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You are a concise technical assistant.&quot;},
      {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Explain the difference between gRPC and REST in three sentences.&quot;}
    ],
    &quot;temperature&quot;: 0.7,
    &quot;max_tokens&quot;: 256
  }&#39;

```

### Response

```json
{
  &quot;id&quot;: &quot;chatcmpl-abc123&quot;,
  &quot;object&quot;: &quot;chat.completion&quot;,
  &quot;model&quot;: &quot;gemini-3.5-flash&quot;,
  &quot;choices&quot;: [
    {
      &quot;index&quot;: 0,
      &quot;message&quot;: {
        &quot;role&quot;: &quot;assistant&quot;,
        &quot;content&quot;: &quot;gRPC uses HTTP/2 and Protocol Buffers for strongly-typed, multiplexed RPC calls with built-in code generation. REST uses HTTP/1.1 (or 2) with JSON payloads and relies on URL paths and HTTP verbs for resource semantics. gRPC is faster for service-to-service calls; REST is simpler to debug and more widely supported by browsers.&quot;
      },
      &quot;finish_reason&quot;: &quot;stop&quot;
    }
  ],
  &quot;usage&quot;: {
    &quot;prompt_tokens&quot;: 34,
    &quot;completion_tokens&quot;: 71,
    &quot;total_tokens&quot;: 105
  }
}

```

## How it works

1. **設定 RunAPI** — 設定 RUNAPI_API_KEY 環境變數。如果你已將 RunAPI 設定為 OpenClaw 的 provider，相同的 key 和 baseUrl 即可用於 Gemini — 只需更改 model ID。不需要 Google Cloud 憑證。
2. **透過 chat completions 呼叫 Gemini** — 發送 POST 請求到 /v1/chat/completions，將 model 設為 gemini-3.5-flash。傳入包含 system 和 user 角色的 messages 陣列。這個端點接受與你的 agent 呼叫 GPT 模型時相同的 OpenAI 相容格式。
3. **讀取回應** — 回應以 OpenAI chat completion 格式同步返回。助手的回覆在 choices[0].message.content 中，token 使用量在 usage 物件中。若要串流，將 stream 設為 true 並解析 SSE 事件。

## Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `model` | `string` | 必填。gemini-3.5-flash、gemini-2.5-flash、gemini-2.5-pro、gemini-3-flash-preview、gemini-3-pro-preview 或 gemini-3.1-pro-preview。 |
| `messages` | `array` | 必填。包含 role（system、user、assistant）和 content 欄位的訊息物件陣列。 |
| `temperature` | `number` | 選填。取樣溫度，介於 0 到 2 之間。較低的值產生更確定性的輸出。預設值因模型而異。 |
| `max_tokens` | `integer` | 選填。回應中生成的最大 token 數。 |
| `stream` | `boolean` | 選填。設為 true 時，回應以 server-sent events 串流傳送。每個事件包含帶有部分內容的 delta。 |
| `top_p` | `number` | 選填。Nucleus 取樣閾值，介於 0 到 1 之間。作為 temperature 的替代方案來控制輸出隨機性。 |

## FAQ

### 不需要 Google Cloud 專案就能在 OpenClaw 中使用 Google Gemini 嗎？

是的。RunAPI 透過其 OpenAI 相容端點提供 Gemini 存取。你只需要一個 RUNAPI_API_KEY — 不需要 Google Cloud 專案、Service Account JSON 或 Vertex AI 帳單設定。

### RunAPI 提供哪些 Gemini 模型？

RunAPI 提供 Gemini 3.5 Flash（最新、最快）、Gemini 2.5 Flash、Gemini 2.5 Pro、Gemini 3 Flash Preview、Gemini 3 Pro Preview 和 Gemini 3.1 Pro Preview。將版本 slug 作為 model 參數傳入 — 例如 gemini-3.5-flash 或 gemini-2.5-pro。

### RunAPI 上的 Gemini 如何計費？

Gemini 在 RunAPI 上按 token 計費，採用隨用隨付定價。輸入和輸出 token 分別計量。無月費、無最低消費。請查看 RunAPI 定價頁面了解目前的每百萬 token 費率。

### 可以在同一個 OpenClaw 工作階段中切換 Gemini 和 GPT 嗎？

可以。兩者使用相同的 RunAPI provider 設定和 API key。將 model 參數從 gemini-3.5-flash 改為 gpt-5.5（或任何其他 RunAPI 模型），無需重新設定 provider。OpenClaw 依照每個請求選擇模型。

### 透過 RunAPI 的 Gemini 支援串流回應嗎？

是的。在請求主體中將 stream 設為 true。RunAPI 以 OpenAI 相容的 delta 格式將 Gemini 回應串流為 server-sent events，因此 OpenClaw 處理方式與 GPT 串流相同。


## Links

- [OpenClaw 設定指南 →](https://runapi.ai/zh-HK/openclaw)
- [Gemini models →](https://runapi.ai/zh-HK/models/gemini)
- [Model catalog](https://runapi.ai/zh-HK/models)
- [API docs](https://runapi.ai/zh-HK/docs)
