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

# 在 OpenClaw 中使用 Claude。

Anthropic Claude 提供 Opus 4.8 的頂級能力（200K 上下文、延伸思考）、Sonnet 4.6 的均衡效能，以及 Haiku 4.5 的速度。OpenClaw 透過 RunAPI 的相容 OpenAI 端點呼叫 Claude，定價為 Anthropic 官方每 token 費率的 50%——相同模型、相同輸出、一半成本。

## 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;claude-opus-4.8&quot;,
    &quot;max_tokens&quot;: 1024,
    &quot;messages&quot;: [
      {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;Explain the difference between a mutex and a semaphore in three sentences.&quot;}
    ]
  }&#39;

```

### Response

```json
{
  &quot;id&quot;: &quot;chatcmpl-abc123&quot;,
  &quot;object&quot;: &quot;chat.completion&quot;,
  &quot;model&quot;: &quot;claude-opus-4.8&quot;,
  &quot;choices&quot;: [
    {
      &quot;index&quot;: 0,
      &quot;message&quot;: {
        &quot;role&quot;: &quot;assistant&quot;,
        &quot;content&quot;: &quot;A mutex is a locking mechanism that allows only one thread to access a resource at a time...&quot;
      },
      &quot;finish_reason&quot;: &quot;stop&quot;
    }
  ],
  &quot;usage&quot;: {
    &quot;prompt_tokens&quot;: 24,
    &quot;completion_tokens&quot;: 87,
    &quot;total_tokens&quot;: 111
  }
}

```

## How it works

1. **設定 RunAPI** — 設定 RUNAPI_API_KEY 環境變數。如果您已將 RunAPI 設定為 OpenClaw 供應商，相同的 key 即可用於 Claude——無需額外設定。OpenClaw 使用 openai-completions API 模式，指向 https://runapi.ai/v1。
2. **呼叫 Claude** — 發送 POST 請求至 /v1/chat/completions，將 model 設為 claude-opus-4.8。包含至少一則使用者訊息的 messages 陣列。設定 max_tokens 控制回應長度。加入 &quot;stream&quot; true 以取得逐 token 的 SSE 輸出。
3. **讀取回應** — 端點同步回傳助理訊息——無需輪詢任務。回應包含 token 使用量統計以確保計費透明。串流回應以 SSE 事件形式送達，每個事件包含一個差異區塊。

## Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `model` | `string` | 必填。claude-opus-4.8、claude-sonnet-4.6、claude-haiku-4.5，或 RunAPI 目錄中列出的任何 Claude 變體。 |
| `messages` | `array` | 必填。訊息物件陣列，每個物件包含 role（system、user、assistant）與 content 欄位。 |
| `max_tokens` | `integer` | 回應中的最大 token 數量。預設值依模型而異——請明確設定以確保計費可預測。 |
| `stream` | `boolean` | 設為 true 時，以 server-sent events 回傳增量 token 差異，而非單一 JSON 回應。 |
| `temperature` | `float` | 取樣溫度，介於 0 到 1 之間。較低的值產生更具確定性的輸出。 |
| `top_p` | `float` | 核取樣截斷值。替代 temperature 使用——兩者擇一，不要同時使用。 |

## FAQ

### 可以透過 RunAPI 從 OpenClaw 呼叫 Claude 嗎？

可以。在 OpenClaw 中將 RunAPI 設定為相容 OpenAI 的供應商，base URL 設為 https://runapi.ai/v1。將 model 設為 claude-opus-4.8 或任何其他 Claude 變體。相同的 RUNAPI_API_KEY 可處理聊天、圖像、影片與音樂模型。

### RunAPI 的 Claude 定價與 Anthropic 直接定價相比如何？

RunAPI 收取 Anthropic 官方每 token 費率的 50%。Opus 4.8 透過 RunAPI 的費用為每百萬輸入/輸出 token $7.50/$37.50，而直接使用為 $15/$75。無需訂閱或量級承諾。

### 透過 RunAPI 在 OpenClaw 中的 Claude 串流可以運作嗎？

可以。在請求 body 中將 stream 設為 true。RunAPI 透過 Cloudflare Worker 代理 Claude 的 SSE 事件，讓您的 OpenClaw agent 能逐 token 接收輸出而不會阻塞。相容 OpenAI 的 SSE 格式適用於任何支援串流 chat completions 的用戶端。

### 可以透過 RunAPI 使用 Claude 的延伸思考功能嗎？

延伸思考可在 /v1/messages 的 Anthropic Messages API 端點上使用。當從 OpenClaw 使用相容 OpenAI 的 /v1/chat/completions 端點時，適用標準 completion 參數。如需延伸思考，請直接呼叫 /v1/messages 並帶入 thinking 參數。

### 在 OpenClaw 中進行程式碼任務應該選擇哪個 Claude 模型？

Opus 4.8 適合複雜的多檔案重構與架構決策。Sonnet 4.6 適合日常編碼——pull request 審查、測試生成與 bug 修復。Haiku 4.5 適合快速自動完成與行內建議，適用於延遲比深度更重要的場景。


## Links

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