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

# 在 Hermes Agent 中使用 Gemini。

Google Gemini 可透過 RunAPI 的 OpenAI 相容端點使用。Hermes Agent 透過 custom:runapi provider 呼叫它 — Gemini 3.5 Flash 適合對速度敏感的 agent 迴圈，3.x Pro 適合多步驟推理，2.5 Pro 適合長上下文的正式環境任務。不需要 Google Cloud 專案或 Vertex AI 憑證 — 只需你已為 chat 設定好的 RUNAPI_API_KEY 和 base_url。

## 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 環境變數。如果你已在 Hermes Agent 中將 RunAPI 新增為 custom:runapi provider，相同的 key 和 base_url 即可用於 Gemini — 只需更改 model ID。不需要 Google Cloud 憑證。
2. **透過 chat completions 呼叫 Gemini** — 發送 POST 請求到 /v1/chat/completions，將 model 設為 gemini-3.5-flash。傳入包含 system 和 user 角色的 messages 陣列。Hermes Agent 發送與呼叫 GPT 時相同的 OpenAI 相容請求格式 — RunAPI 根據 model 參數路由到 Gemini。
3. **讀取回應** — 回應以 OpenAI chat completion 格式同步返回。助手的回覆在 choices[0].message.content 中，token 使用量在 usage 物件中。若要串流，將 stream 設為 true，Hermes Agent 會自動解析 SSE delta 事件。

## 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 憑證就能在 Hermes Agent 中使用 Google Gemini 嗎？

是的。RunAPI 透過其 OpenAI 相容端點提供 Gemini。在 Hermes Agent 中將 RunAPI 設定為 custom:runapi provider，base_url 為 https://runapi.ai/v1，key_env 為 RUNAPI_API_KEY。不需要 Google Cloud 專案、Service Account 或 Vertex AI 設定。

### agent 工作流程應該使用哪個 Gemini 版本？

Gemini 3.5 Flash（gemini-3.5-flash）是最新且最快的 — 最適合即時 agent 迴圈和工具呼叫鏈。Gemini 2.5 Pro（gemini-2.5-pro）處理長上下文任務和複雜推理。Gemini 3.x Pro 預覽版本以較高成本提供最新的推理能力。

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

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

### Hermes Agent 可以在會話中途切換 Gemini 和其他 LLM 嗎？

可以。所有 RunAPI LLM 共用相同的 custom:runapi provider 和 API key。使用 /model 指令或 hermes model 在 gemini-3.5-flash、gpt-5.5、claude-opus-4.6 或其他任何 RunAPI 模型之間切換，無需更改 provider 設定。

### 透過 RunAPI 的 Gemini 支援函數呼叫和工具使用嗎？

是的。RunAPI 將 OpenAI 相容的 tools 和 tool_choice 參數傳遞給 Gemini。在請求主體中定義 tools，Gemini 會在助手訊息中返回 tool_calls。Hermes Agent 處理方式與處理 GPT 或 Claude 的工具呼叫相同。


## Links

- [Hermes Agent 設定指南 →](https://runapi.ai/zh-TW/hermes-agent)
- [Gemini models →](https://runapi.ai/zh-TW/models/gemini)
- [Model catalog](https://runapi.ai/zh-TW/models)
- [API docs](https://runapi.ai/zh-TW/docs)
