2026-01-11 02:27:30 +01:00
---
2026-01-30 03:15:10 +01:00
summary: "Use Anthropic Claude via API keys or setup-token in OpenClaw"
2026-01-11 02:27:30 +01:00
read_when:
2026-01-30 03:15:10 +01:00
- You want to use Anthropic models in OpenClaw
2026-01-26 19:04:46 +00:00
- You want setup-token instead of API keys
2026-01-31 16:04:03 -05:00
title: "Anthropic"
2026-01-11 02:27:30 +01:00
---
2026-01-31 21:13:13 +09:00
2026-01-11 02:27:30 +01:00
# Anthropic (Claude)
Anthropic builds the **Claude** model family and provides access via an API.
2026-01-30 03:15:10 +01:00
In OpenClaw you can authenticate with an API key or a **setup-token** .
2026-01-11 02:27:30 +01:00
## Option A: Anthropic API key
**Best for:** standard API access and usage-based billing.
Create your API key in the Anthropic Console.
### CLI setup
```bash
2026-01-30 03:15:10 +01:00
openclaw onboard
2026-01-11 02:27:30 +01:00
# choose: Anthropic API key
# or non-interactive
2026-01-30 03:15:10 +01:00
openclaw onboard --anthropic-api-key "$ANTHROPIC_API_KEY"
2026-01-11 02:27:30 +01:00
```
### Config snippet
```json5
{
env: { ANTHROPIC_API_KEY: "sk-ant-..." },
2026-02-05 16:54:44 -05:00
agents: { defaults: { model: { primary: "anthropic/claude-opus-4-6" } } },
2026-01-11 02:27:30 +01:00
}
```
2026-01-20 15:07:46 +00:00
## Prompt caching (Anthropic API)
2026-02-01 23:16:37 +09:00
OpenClaw supports Anthropic's prompt caching feature. This is **API-only** ; subscription auth does not honor cache settings.
2026-01-20 15:07:46 +00:00
2026-02-01 23:16:37 +09:00
### Configuration
Use the `cacheRetention` parameter in your model config:
| Value | Cache Duration | Description |
| ------- | -------------- | ----------------------------------- |
| `none` | No caching | Disable prompt caching |
| `short` | 5 minutes | Default for API Key auth |
| `long` | 1 hour | Extended cache (requires beta flag) |
2026-01-20 15:07:46 +00:00
```json5
{
agents: {
defaults: {
models: {
2026-02-05 16:54:44 -05:00
"anthropic/claude-opus-4-6": {
2026-02-01 23:16:37 +09:00
params: { cacheRetention: "long" },
2026-01-31 21:13:13 +09:00
},
},
},
},
2026-01-20 15:07:46 +00:00
}
```
2026-02-01 23:16:37 +09:00
### Defaults
When using Anthropic API Key authentication, OpenClaw automatically applies `cacheRetention: "short"` (5-minute cache) for all Anthropic models. You can override this by explicitly setting `cacheRetention` in your config.
2026-02-23 18:45:30 +00:00
### Per-agent cacheRetention overrides
Use model-level params as your baseline, then override specific agents via `agents.list[].params` .
```json5
{
agents: {
defaults: {
model: { primary: "anthropic/claude-opus-4-6" },
models: {
"anthropic/claude-opus-4-6": {
params: { cacheRetention: "long" }, // baseline for most agents
},
},
},
list: [
{ id: "research", default: true },
{ id: "alerts", params: { cacheRetention: "none" } }, // override for this agent only
],
},
}
```
Config merge order for cache-related params:
1. `agents.defaults.models["provider/model"].params`
2. `agents.list[].params` (matching `id` , overrides by key)
This lets one agent keep a long-lived cache while another agent on the same model disables caching to avoid write costs on bursty/low-reuse traffic.
### Bedrock Claude notes
- Anthropic Claude models on Bedrock (`amazon-bedrock/*anthropic.claude*` ) accept `cacheRetention` pass-through when configured.
- Non-Anthropic Bedrock models are forced to `cacheRetention: "none"` at runtime.
- Anthropic API-key smart defaults also seed `cacheRetention: "short"` for Claude-on-Bedrock model refs when no explicit value is set.
2026-02-01 23:16:37 +09:00
### Legacy parameter
The older `cacheControlTtl` parameter is still supported for backwards compatibility:
- `"5m"` maps to `short`
- `"1h"` maps to `long`
We recommend migrating to the new `cacheRetention` parameter.
2026-01-30 03:15:10 +01:00
OpenClaw includes the `extended-cache-ttl-2025-04-11` beta flag for Anthropic API
2026-01-20 15:07:46 +00:00
requests; keep it if you override provider headers (see [/gateway/configuration ](/gateway/configuration )).
2026-02-18 03:28:56 +01:00
## 1M context window (Anthropic beta)
Anthropic's 1M context window is beta-gated. In OpenClaw, enable it per model
with `params.context1m: true` for supported Opus/Sonnet models.
```json5
{
agents: {
defaults: {
models: {
"anthropic/claude-opus-4-6": {
params: { context1m: true },
},
},
},
},
}
```
OpenClaw maps this to `anthropic-beta: context-1m-2025-08-07` on Anthropic
requests.
2026-02-23 12:29:09 -05:00
Note: Anthropic currently rejects `context-1m-*` beta requests when using
OAuth/subscription tokens (`sk-ant-oat-*` ). OpenClaw automatically skips the
context1m beta header for OAuth auth and keeps the required OAuth betas.
2026-01-26 19:04:46 +00:00
## Option B: Claude setup-token
2026-01-11 02:27:30 +01:00
2026-01-26 19:04:46 +00:00
**Best for:** using your Claude subscription.
2026-01-11 02:27:30 +01:00
2026-01-16 02:19:54 +00:00
### Where to get a setup-token
2026-01-16 02:36:29 +00:00
Setup-tokens are created by the **Claude Code CLI** , not the Anthropic Console. You can run this on **any machine** :
2026-01-16 02:19:54 +00:00
```bash
claude setup-token
```
2026-01-30 03:15:10 +01:00
Paste the token into OpenClaw (wizard: **Anthropic token (paste setup-token)** ), or run it on the gateway host:
2026-01-16 02:19:54 +00:00
```bash
2026-01-30 03:15:10 +01:00
openclaw models auth setup-token --provider anthropic
2026-01-16 02:19:54 +00:00
```
2026-01-16 02:36:29 +00:00
If you generated the token on a different machine, paste it:
```bash
2026-01-30 03:15:10 +01:00
openclaw models auth paste-token --provider anthropic
2026-01-16 02:36:29 +00:00
```
2026-02-06 09:35:57 -05:00
### CLI setup (setup-token)
2026-01-11 02:27:30 +01:00
```bash
2026-01-26 19:04:46 +00:00
# Paste a setup-token during onboarding
2026-01-30 03:15:10 +01:00
openclaw onboard --auth-choice setup-token
2026-01-11 02:27:30 +01:00
```
2026-02-06 09:35:57 -05:00
### Config snippet (setup-token)
2026-01-11 02:27:30 +01:00
```json5
{
2026-02-05 16:54:44 -05:00
agents: { defaults: { model: { primary: "anthropic/claude-opus-4-6" } } },
2026-01-11 02:27:30 +01:00
}
```
## Notes
2026-01-30 03:15:10 +01:00
- Generate the setup-token with `claude setup-token` and paste it, or run `openclaw models auth setup-token` on the gateway host.
2026-01-26 19:04:46 +00:00
- If you see “OAuth token refresh failed …” on a Claude subscription, re-auth with a setup-token. See [/gateway/troubleshooting#oauth-token-refresh-failed-anthropic-claude-subscription ](/gateway/troubleshooting#oauth-token-refresh-failed-anthropic-claude-subscription ).
2026-01-11 02:27:30 +01:00
- Auth details + reuse rules are in [/concepts/oauth ](/concepts/oauth ).
2026-01-24 23:58:45 +00:00
## Troubleshooting
**401 errors / token suddenly invalid**
2026-01-31 21:13:13 +09:00
2026-01-24 23:58:45 +00:00
- Claude subscription auth can expire or be revoked. Re-run `claude setup-token`
and paste it into the **gateway host** .
- If the Claude CLI login lives on a different machine, use
2026-01-30 03:15:10 +01:00
`openclaw models auth paste-token --provider anthropic` on the gateway host.
2026-01-24 23:58:45 +00:00
2026-01-25 00:07:13 +00:00
**No API key found for provider "anthropic"**
2026-01-31 21:13:13 +09:00
2026-01-25 00:07:13 +00:00
- Auth is **per agent** . New agents don’ t inherit the main agent’ s keys.
- Re-run onboarding for that agent, or paste a setup-token / API key on the
2026-01-30 03:15:10 +01:00
gateway host, then verify with `openclaw models status` .
2026-01-25 00:07:13 +00:00
2026-01-26 19:04:46 +00:00
**No credentials found for profile `anthropic:default` **
2026-01-31 21:13:13 +09:00
2026-01-30 03:15:10 +01:00
- Run `openclaw models status` to see which auth profile is active.
2026-01-24 23:58:45 +00:00
- Re-run onboarding, or paste a setup-token / API key for that profile.
**No available auth profile (all in cooldown/unavailable)**
2026-01-31 21:13:13 +09:00
2026-01-30 03:15:10 +01:00
- Check `openclaw models status --json` for `auth.unusableProfiles` .
2026-01-24 23:58:45 +00:00
- Add another Anthropic profile or wait for cooldown.
More: [/gateway/troubleshooting ](/gateway/troubleshooting ) and [/help/faq ](/help/faq ).