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 代理以官方 Anthropic 每 token 費率的 50%,使用與 GPT 和 Gemini 相同的 OpenAI 相容端點和 API key 呼叫 Claude。支援提示詞快取以進一步降低重複上下文的成本。

Claude 使用情境

使用工具呼叫的代理式程式設計

搭配函數呼叫和 MCP(Model Context Protocol)使用 Claude,用於自動化程式設計工作流程——程式碼生成、Pull Request 審查、多檔案重構,以及透過工具輔助的上下文收集進行測試撰寫。

使用 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。