2026-01-09 00:32:48 +00:00
---
2026-01-26 19:04:46 +00:00
summary: "Model authentication: OAuth, API keys, and setup-token"
2026-01-09 00:32:48 +00:00
read_when:
- Debugging model auth or OAuth expiry
- Documenting authentication or credential storage
2026-01-31 16:04:03 -05:00
title: "Authentication"
2026-01-09 00:32:48 +00:00
---
2026-01-31 21:13:13 +09:00
2026-01-09 09:42:05 +10:30
# Authentication
2026-01-30 03:15:10 +01:00
OpenClaw supports OAuth and API keys for model providers. For Anthropic
2026-01-26 19:04:46 +00:00
accounts, we recommend using an **API key** . For Claude subscription access,
use the long‑ lived token created by `claude setup-token` .
2026-01-09 09:42:05 +10:30
2026-01-09 00:32:48 +00:00
See [/concepts/oauth ](/concepts/oauth ) for the full OAuth flow and storage
layout.
2026-01-09 09:42:05 +10:30
2026-01-10 17:36:50 +01:00
## Recommended Anthropic setup (API key)
2026-01-09 15:29:50 +01:00
2026-01-10 17:36:50 +01:00
If you’ re using Anthropic directly, use an API key.
2026-01-31 21:13:13 +09:00
1. Create an API key in the Anthropic Console.
2. Put it on the **gateway host** (the machine running `openclaw gateway` ).
2026-01-09 15:29:50 +01:00
```bash
2026-01-10 17:36:50 +01:00
export ANTHROPIC_API_KEY="..."
2026-01-30 03:15:10 +01:00
openclaw models status
2026-01-09 15:29:50 +01:00
```
2026-02-06 10:00:08 -05:00
3. If the Gateway runs under systemd/launchd, prefer putting the key in
2026-01-31 21:13:13 +09:00
`~/.openclaw/.env` so the daemon can read it:
2026-01-10 17:36:50 +01:00
```bash
2026-01-30 03:15:10 +01:00
cat >> ~/.openclaw/.env < < 'EOF'
2026-01-10 17:36:50 +01:00
ANTHROPIC_API_KEY=...
EOF
```
Then restart the daemon (or restart your Gateway process) and re-check:
2026-01-09 15:29:50 +01:00
```bash
2026-01-30 03:15:10 +01:00
openclaw models status
openclaw doctor
2026-01-09 15:29:50 +01:00
```
2026-01-10 17:36:50 +01:00
If you’ d rather not manage env vars yourself, the onboarding wizard can store
2026-01-30 03:15:10 +01:00
API keys for daemon use: `openclaw onboard` .
2026-01-10 17:36:50 +01:00
2026-01-16 23:10:10 +00:00
See [Help ](/help ) for details on env inheritance (`env.shellEnv` ,
2026-01-30 03:15:10 +01:00
`~/.openclaw/.env` , systemd/launchd).
2026-01-10 17:36:50 +01:00
2026-01-26 19:04:46 +00:00
## Anthropic: setup-token (subscription auth)
2026-01-10 17:36:50 +01:00
2026-01-26 19:04:46 +00:00
For Anthropic, the recommended path is an **API key** . If you’ re using a Claude
subscription, the setup-token flow is also supported. Run it on the **gateway host** :
2026-01-09 17:50:34 +01:00
```bash
2026-01-10 17:36:50 +01:00
claude setup-token
2026-01-09 17:50:34 +01:00
```
2026-01-30 03:15:10 +01:00
Then paste it into OpenClaw:
2026-01-09 17:50:34 +01:00
```bash
2026-01-30 03:15:10 +01:00
openclaw models auth setup-token --provider anthropic
2026-01-09 17:50:34 +01:00
```
2026-01-26 19:04:46 +00:00
If the token was created on another machine, paste it manually:
2026-01-09 00:32:48 +00:00
2026-01-26 19:04:46 +00:00
```bash
2026-01-30 03:15:10 +01:00
openclaw models auth paste-token --provider anthropic
2026-01-26 19:04:46 +00:00
```
2026-01-15 02:35:20 +00:00
2026-01-10 17:36:50 +01:00
If you see an Anthropic error like:
```
This credential is only authorized for use with Claude Code and cannot be used for other API requests.
```
…use an Anthropic API key instead.
Manual token entry (any provider; writes `auth-profiles.json` + updates config):
2026-01-09 09:42:05 +10:30
```bash
2026-01-30 03:15:10 +01:00
openclaw models auth paste-token --provider anthropic
openclaw models auth paste-token --provider openrouter
2026-01-09 09:42:05 +10:30
```
2026-01-09 00:32:48 +00:00
Automation-friendly check (exit `1` when expired/missing, `2` when expiring):
2026-01-09 09:42:05 +10:30
```bash
2026-01-30 03:15:10 +01:00
openclaw models status --check
2026-01-09 09:42:05 +10:30
```
2026-01-09 00:32:48 +00:00
Optional ops scripts (systemd/Termux) are documented here:
[/automation/auth-monitoring ](/automation/auth-monitoring )
2026-01-09 09:42:05 +10:30
2026-01-09 00:32:48 +00:00
> `claude setup-token` requires an interactive TTY.
2026-01-09 09:42:05 +10:30
2026-01-09 00:32:48 +00:00
## Checking model auth status
2026-01-09 09:42:05 +10:30
```bash
2026-01-30 03:15:10 +01:00
openclaw models status
openclaw doctor
2026-01-09 09:42:05 +10:30
```
2026-02-18 01:31:11 +01:00
## API key rotation behavior (gateway)
Some providers support retrying a request with alternative keys when an API call
hits a provider rate limit.
- Priority order:
- `OPENCLAW_LIVE_<PROVIDER>_KEY` (single override)
- `<PROVIDER>_API_KEYS`
- `<PROVIDER>_API_KEY`
- `<PROVIDER>_API_KEY_*`
- Google providers also include `GOOGLE_API_KEY` as an additional fallback.
- The same key list is deduplicated before use.
- OpenClaw retries with the next key only for rate-limit errors (for example
`429` , `rate_limit` , `quota` , `resource exhausted` ).
- Non-rate-limit errors are not retried with alternate keys.
- If all keys fail, the final error from the last attempt is returned.
2026-01-09 14:17:49 +00:00
## Controlling which credential is used
### Per-session (chat command)
2026-01-26 19:04:46 +00:00
Use `/model <alias-or-id>@<profileId>` to pin a specific provider credential for the current session (example profile ids: `anthropic:default` , `anthropic:work` ).
2026-01-12 06:38:16 +00:00
Use `/model` (or `/model list` ) for a compact picker; use `/model status` for the full view (candidates + next auth profile, plus provider endpoint details when configured).
2026-01-09 14:17:49 +00:00
### Per-agent (CLI override)
Set an explicit auth profile order override for an agent (stored in that agent’ s `auth-profiles.json` ):
```bash
2026-01-30 03:15:10 +01:00
openclaw models auth order get --provider anthropic
openclaw models auth order set --provider anthropic anthropic:default
openclaw models auth order clear --provider anthropic
2026-01-09 14:17:49 +00:00
```
Use `--agent <id>` to target a specific agent; omit it to use the configured default agent.
2026-01-09 00:32:48 +00:00
## Troubleshooting
2026-01-09 09:42:05 +10:30
2026-01-09 00:32:48 +00:00
### “No credentials found”
2026-01-09 09:42:05 +10:30
2026-01-09 17:50:34 +01:00
If the Anthropic token profile is missing, run `claude setup-token` on the
2026-01-09 00:32:48 +00:00
**gateway host**, then re-check:
2026-01-09 09:42:05 +10:30
```bash
2026-01-30 03:15:10 +01:00
openclaw models status
2026-01-09 09:42:05 +10:30
```
2026-01-09 00:32:48 +00:00
### Token expiring/expired
2026-01-30 03:15:10 +01:00
Run `openclaw models status` to confirm which profile is expiring. If the profile
2026-01-26 19:04:46 +00:00
is missing, rerun `claude setup-token` and paste the token again.
2026-01-09 00:32:48 +00:00
2026-01-09 09:42:05 +10:30
## Requirements
2026-01-09 00:32:48 +00:00
- Claude Max or Pro subscription (for `claude setup-token` )
2026-01-09 09:42:05 +10:30
- Claude Code CLI installed (`claude` command available)