Anthropic(Claude)
Anthropic 建構 Claude 模型家族,並透過 API 提供存取。 在 OpenClaw 中,你可以使用 API 金鑰或 setup-token 進行身分驗證。 In OpenClaw you can authenticate with an API key or a setup-token. In OpenClaw you can authenticate with an API key or a setup-token.選項 A:Anthropic API 金鑰
Best for: standard API access and usage-based billing. 最適合: 標準 API 存取與依用量計費。 請在 Anthropic Console 建立你的 API 金鑰。CLI 設定
設定片段
提示詞快取(Anthropic API)
OpenClaw supports Anthropic’s prompt caching feature. This is API-only; subscription auth does not honor cache settings.設定
在你的模型設定中使用cacheRetention 參數:
| 值 | Cache Duration | Description |
|---|---|---|
none | No caching | Disable prompt caching |
short | 5 分鐘 | API 金鑰驗證的預設值 |
long | 1 小時 | 延長快取(需要 beta 旗標) |
Defaults
使用 Anthropic API 金鑰驗證時,OpenClaw 會自動為所有 Anthropic 模型套用cacheRetention: "short"(5 分鐘快取)。你可以在設定中明確設定 cacheRetention 以覆寫此行為。 You can override this by explicitly setting cacheRetention in your config. You can override this by explicitly setting cacheRetention in your config.
Legacy parameter
較舊的cacheControlTtl 參數仍支援以維持向後相容性:
"5m"對應至short"1h"對應至long
cacheRetention 參數。
OpenClaw 在 Anthropic API 請求中包含 extended-cache-ttl-2025-04-11 beta 旗標;若你覆寫提供者標頭,請保留它(參見 /gateway/configuration)。
選項 B:Claude setup-token
最適合: 使用你的 Claude 訂閱。取得 setup-token 的位置
Setup-token 由 Claude Code CLI 建立,而非 Anthropic Console。你可以在 任何機器 上執行: You can run this on any machine: You can run this on any machine:CLI 設定(setup-token)
設定片段(setup-token)
注意事項
- 使用
claude setup-token產生 setup-token 並貼上,或在閘道器主機上執行openclaw models auth setup-token。 - If you see “OAuth token refresh failed …” on a Claude subscription, re-auth with a setup-token. 若在 Claude 訂閱中看到「OAuth token refresh failed …」,請使用 setup-token 重新驗證。請參閱 /gateway/troubleshooting#oauth-token-refresh-failed-anthropic-claude-subscription。
- 驗證細節與重用規則請見 /concepts/oauth。
Troubleshooting
401 錯誤/權杖突然失效- Claude subscription auth can expire or be revoked. Claude 訂閱驗證可能會過期或被撤銷。請重新執行
claude setup-tokenand paste it into the gateway host. - 若 Claude CLI 登入存在於不同的機器上,請在閘道器主機上使用
openclaw models auth paste-token --provider anthropic。
- Auth is per agent. New agents don’t inherit the main agent’s keys.
- 重新為該代理程式執行入門引導,或在閘道器主機上貼上 setup-token/API 金鑰,然後使用
openclaw models status驗證。
anthropic:default 的認證
- 執行
openclaw models status以查看目前啟用的驗證設定檔。 - Re-run onboarding, or paste a setup-token / API key for that profile.
- 檢查
openclaw models status --json是否為auth.unusableProfiles。 - 新增另一個 Anthropic 設定檔,或等待冷卻結束。