在 OpenClaw 中使用 Claude。
Anthropic Claude 提供 Opus 4.8 以获得最强能力(200K 上下文、扩展思考)、Sonnet 4.6 以获得均衡性能、Haiku 4.5 以获得速度。OpenClaw 通过 RunAPI 的 OpenAI 兼容端点以 Anthropic 官方每 token 费率的 50% 调用 Claude——相同的模型、相同的输出、一半的成本。
使用 RunAPI 从 OpenClaw 发送 Claude 聊天补全请求。
要求:
- 调用 RunAPI 聊天补全端点 https://runapi.ai/v1/chat/completions
- 将 model 设置为 "claude-opus-4.8"
- 使用 RUNAPI_API_KEY 环境变量进行授权
- 响应是同步的——assistant 消息直接在响应体中返回
- 如需流式传输,设置 "stream": true 以接收 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
}
}
三步在 OpenClaw 中使用 Claude
Configure RunAPI
Set the RUNAPI_API_KEY environment variable. If you already configured RunAPI as an OpenClaw provider, the same key works for Claude — no extra setup needed. OpenClaw uses the openai-completions API mode pointed at https://runapi.ai/v1.
export RUNAPI_API_KEY=runapi_xxx
Call Claude
Send a POST request to /v1/chat/completions with model set to claude-opus-4.8. Include a messages array with at least one user message. Set max_tokens to control response length. Add "stream" true if you want token-by-token SSE output.
POST /v1/chat/completions
Read the response
The endpoint returns the assistant message synchronously — no task polling needed. The response includes token usage counts for billing transparency. Streaming responses arrive as SSE events, each containing a delta chunk.
usage.total_tokens: 111
Claude API 参数(OpenAI 兼容)
| 参数 | 类型 | 说明 |
|---|---|---|
model |
string |
Required. claude-opus-4.8, claude-sonnet-4.6, claude-haiku-4.5, or any Claude variant listed in the RunAPI catalog. |
messages |
array |
Required. Array of message objects with role (system, user, assistant) and content fields. |
max_tokens |
integer |
Maximum number of tokens in the response. Defaults vary by model — set explicitly for predictable billing. |
stream |
boolean |
When true, returns server-sent events with incremental token deltas instead of a single JSON response. |
temperature |
float |
Sampling temperature between 0 and 1. Lower values produce more deterministic output. |
top_p |
float |
Nucleus sampling cutoff. Alternative to temperature — use one or the other, not both. |
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 用量追踪实现成本透明和计费审计。
Claude + OpenClaw 常见问题
Yes. Configure RunAPI as an OpenAI-compatible provider in OpenClaw with base URL https://runapi.ai/v1. Set model to claude-opus-4.8 or any other Claude variant. The same RUNAPI_API_KEY handles chat, image, video, and music models.
RunAPI charges 50% of Anthropic's official rate. Opus 4.8 is $7.50/$37.50 per million input/output tokens through RunAPI versus $15/$75 direct. With prompt caching enabled, cached input tokens cost even less. Check the RunAPI pricing page for exact rates.
Rate limits depend on your RunAPI plan tier and are measured in requests per minute (RPM) and tokens per minute (TPM). Use prompt caching to reduce input token volume on repeated context. For high-throughput workloads, contact RunAPI for increased limits.
Extended thinking is available on the Anthropic Messages API endpoint at /v1/messages. When using the OpenAI-compatible /v1/chat/completions endpoint from OpenClaw, standard completion parameters apply. For extended thinking, call /v1/messages directly with the thinking parameter.
Opus 4.8 for complex multi-file refactors and architecture decisions. Sonnet 4.6 for everyday coding -- pull request reviews, test generation, and bug fixes. Haiku 4.5 for fast autocomplete and inline suggestions where latency matters more than depth.
立即在 OpenClaw 中试用 Claude。
免费获取 RunAPI 密钥,将提示词粘贴到 OpenClaw 中,以 Anthropic 官方费率的 50% 开始使用 Claude。