OPENCLAW + CLAUDE

在 OpenClaw 中使用 Claude。

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

一個 API key · 相容 OpenAI 端點 · 每 token 計費五折
Use RunAPI to send a Claude chat completion request from OpenClaw.

Requirements:
- Call the RunAPI chat completions endpoint at https://runapi.ai/v1/chat/completions
- Set model to "claude-opus-4.8"
- Use the RUNAPI_API_KEY environment variable for authorization
- The response is synchronous — the assistant message is returned directly in the response body
- For streaming, set "stream": true to receive 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": "claude-opus-4.8",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Explain the difference between a mutex and a semaphore in three sentences."}
    ]
  }'
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "model": "claude-opus-4.8",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "A mutex is a locking mechanism that allows only one thread to access a resource at a time..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "completion_tokens": 87,
    "total_tokens": 111
  }
}
複製 curl 指令進行測試 claude
運作原理

三步驟在 OpenClaw 中使用 Claude

1

設定 RunAPI

設定 RUNAPI_API_KEY 環境變數。如果您已將 RunAPI 設定為 OpenClaw 供應商,相同的 key 即可用於 Claude——無需額外設定。OpenClaw 使用 openai-completions API 模式,指向 https://runapi.ai/v1。

export RUNAPI_API_KEY=runapi_xxx
2

呼叫 Claude

發送 POST 請求至 /v1/chat/completions,將 model 設為 claude-opus-4.8。包含至少一則使用者訊息的 messages 陣列。設定 max_tokens 控制回應長度。加入 "stream" true 以取得逐 token 的 SSE 輸出。

POST /v1/chat/completions
3

讀取回應

端點同步回傳助理訊息——無需輪詢任務。回應包含 token 使用量統計以確保計費透明。串流回應以 SSE 事件形式送達,每個事件包含一個差異區塊。

usage.total_tokens: 111
參數

Claude API 參數(相容 OpenAI)

參數 類型 說明
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 使用——兩者擇一,不要同時使用。

OpenClaw 上的 Claude 是什麼?

Claude 是 Anthropic 的 LLM 系列——Opus 4.8 擁有 200K 上下文和擴展思考功能、Sonnet 4.6 用於日常編碼和寫作、Haiku 4.5 用於快速低成本任務。通過 RunAPI,OpenClaw agent 以官方 Anthropic 單 token 價格的 50% 呼叫 Claude,支持提示詞緩存,可在重複上下文場景下進一步降低成本。

Claude 使用場景

帶工具呼叫的 agent 編程

使用 Claude 的函數呼叫和 MCP(模型上下文協議)構建自動化編碼工作流——代碼生成、PR 審查、多文件重構和測試編寫,配合工具輔助的上下文收集。

200K 上下文長文檔分析

將完整代碼庫、法律合同或研究論文輸入 Claude Opus 4.8 的 200K token 上下文窗口進行分析、摘要和問答,無需分塊處理。

帶審計追蹤的企業自動化

構建 Claude 處理文檔、提取數據並做出決策的自動化工作流,通過 token 用量追蹤實現成本透明和計費審計。

FAQ

Claude + OpenClaw 常見問題

OpenClaw 通用設定

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

OpenClaw 設定指南 →

Claude 模型目錄

查看所有 Claude 變體、每 token 定價與上下文視窗詳情。

Claude models →

立即在 OpenClaw 中試用 Claude。

取得免費 RunAPI key,將 prompt 貼入 OpenClaw,以 Anthropic 官方費率的 50% 開始使用 Claude。