OPENCLAW + GEMINI

在 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 key · OpenAI 相容 chat 端點 · 支援串流
Use RunAPI to send a chat request to Google Gemini 3.5 Flash.

Requirements:
- Use the RunAPI OpenAI-compatible endpoint at https://runapi.ai/v1/chat/completions
- Set model to "gemini-3.5-flash"
- Use the RUNAPI_API_KEY environment variable for authorization
- The response is synchronous — the reply arrives in choices[0].message.content
- For streaming, set stream to true and process server-sent events
curl -X POST https://runapi.ai/v1/chat/completions \
  -H "Authorization: Bearer $RUNAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.5-flash",
    "messages": [
      {"role": "system", "content": "You are a concise technical assistant."},
      {"role": "user", "content": "Explain the difference between gRPC and REST in three sentences."}
    ],
    "temperature": 0.7,
    "max_tokens": 256
  }'
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "model": "gemini-3.5-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "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."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 34,
    "completion_tokens": 71,
    "total_tokens": 105
  }
}
複製 curl 指令進行測試 gemini
運作原理

三個步驟在 OpenClaw 中使用 Gemini

1

設定 RunAPI

設定 RUNAPI_API_KEY 環境變數。如果你已將 RunAPI 設定為 OpenClaw 的 provider,相同的 key 和 baseUrl 即可用於 Gemini — 只需更改 model ID。不需要 Google Cloud 憑證。

export RUNAPI_API_KEY=runapi_xxx
2

透過 chat completions 呼叫 Gemini

發送 POST 請求到 /v1/chat/completions,將 model 設為 gemini-3.5-flash。傳入包含 system 和 user 角色的 messages 陣列。這個端點接受與你的 agent 呼叫 GPT 模型時相同的 OpenAI 相容格式。

POST /v1/chat/completions
3

讀取回應

回應以 OpenAI chat completion 格式同步返回。助手的回覆在 choices[0].message.content 中,token 使用量在 usage 物件中。若要串流,將 stream 設為 true 並解析 SSE 事件。

choices[0].message.content
參數

Gemini chat completions API 參數

參數 類型 說明
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 的替代方案來控制輸出隨機性。

OpenClaw 上的 Gemini 是什麼?

Google Gemini 通過 RunAPI 提供,無需 Google Cloud 項目、服務賬號或 Vertex AI 設定。OpenClaw 將其視為另一個 OpenAI 兼容模型——相同的 provider 設定和 RUNAPI_API_KEY。Gemini 3.5 Flash 為實時 agent 循環提供亞 100ms 首 token 延遲,而 Gemini 2.5 Pro 憑藉 100 萬 token 上下文窗口和思考模式處理複雜推理的長上下文任務。

Gemini 使用場景

文字、圖像、音頻和影片的多模態應用

在文本提示旁發送圖像、PDF、音頻文件或影片幀,讓 Gemini 進行分析、描述或提取結構化數據。Gemini 通過單次 API 呼叫原生處理所有輸入類型。

100 萬 token 上下文的長文檔分析

將整個代碼庫、法律文檔集或研究論文集輸入 Gemini 2.5 Pro 的 100 萬 token 上下文窗口進行分析和摘要,無需分塊或檢索工作流程。

使用 Flash 的實時 agent 循環

將 Gemini 3.5 Flash 用於對首 token 亞 100ms 延遲比峯值推理質量更重要的速度敏感型 agent 工具呼叫鏈。每百萬 token 成本處於最低水平之列。

FAQ

Gemini + OpenClaw 常見問題

OpenClaw 通用設定

尚未設定?請從 OpenClaw 的 RunAPI 設定指南開始。

OpenClaw 設定指南 →

Gemini 模型目錄

查看所有 Gemini 版本、定價方案和 API 文件。

Gemini models →

立即在 OpenClaw 中試用 Gemini。

取得免費的 RunAPI key,在你的 OpenClaw provider 中將 model 設為 gemini-3.5-flash,即可開始與 Gemini 對話。