Setting Up Anthropic Authentication in OpenClaw
Setting up authentication is often the most frustrating part of starting with a new tool. I have spent way too much time staring at “Unauthorized” errors or hunting for where to paste a specific token just to get a simple response. It is a friction point that gets in the way of actually building things.
I want to show you how to get your Anthropic credentials working in OpenClaw so you can move past the config and get to work.
What You’ll Need
Section titled “What You’ll Need”- Claude Max or Pro subscription (required only if you are using
setup-token) - Claude Code CLI installed (the
claudecommand must be available)
Quick Start
Section titled “Quick Start”I recommend using an API key if you are using Anthropic directly. It is the most stable way to connect.
Method 1: The API Key (Recommended)
Section titled “Method 1: The API Key (Recommended)”- Generate your key in the Anthropic Console.
- On your gateway host (the machine running
openclaw gateway), export the variable:
export ANTHROPIC_API_KEY="..."openclaw models status- If you run the Gateway as a background service (like systemd or launchd), put the key in your
.envfile so the daemon can see it:
cat >> ~/.openclaw/.env <<'EOF'ANTHROPIC_API_KEY=...EOF- Restart your Gateway process and verify the connection:
openclaw models statusopenclaw doctorIf you prefer an interactive setup, you can run openclaw onboard to let the wizard handle the storage for you.
Method 2: Claude Subscription (setup-token)
Section titled “Method 2: Claude Subscription (setup-token)”If you have a Claude subscription instead of a direct API account, you can use the setup-token flow. You must do this on the gateway host.
- Run the setup command:
Terminal window claude setup-token - Paste the resulting token into OpenClaw:
Terminal window openclaw models auth setup-token --provider anthropic
If you already have a token from another machine, you can paste it manually:
openclaw models auth paste-token --provider anthropicManaging Your Credentials
Section titled “Managing Your Credentials”Once you have multiple keys or profiles, you can control which one OpenClaw uses.
Per-session pinning
Section titled “Per-session pinning”In a chat session, use the /model command to pin a specific profile:
/model claude-3-5-sonnet@anthropic:work
Per-agent overrides
Section titled “Per-agent overrides”If you want a specific agent to always use a certain profile, use the CLI:
openclaw models auth order set --provider anthropic anthropic:defaultopenclaw models auth order get --provider anthropicopenclaw models auth order clear --provider anthropicTroubleshooting
Section titled “Troubleshooting””No credentials found”
Section titled “”No credentials found””If you see this, the Anthropic token profile is likely missing. Run claude setup-token on your gateway host again, then check the status:
openclaw models statusToken expiring or expired
Section titled “Token expiring or expired”I suggest using the automation-friendly check to catch this early:
openclaw models status --checkIf a profile is expiring, run claude setup-token and paste the new token.
”Only authorized for Claude Code” error
Section titled “”Only authorized for Claude Code” error”If you see a message stating the credential cannot be used for other API requests, Anthropic is restricting that specific token. You should switch to using an Anthropic API key instead.
Need more help? Talk to the AI Setup Assistant.
What’s Next
Section titled “What’s Next”OpenClaw Expert
Still stuck?
If this page didn't answer your case, ask OpenClaw Expert for step-by-step guidance.