Skip to content

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.

  • Claude Max or Pro subscription (required only if you are using setup-token)
  • Claude Code CLI installed (the claude command must be available)

I recommend using an API key if you are using Anthropic directly. It is the most stable way to connect.

  1. Generate your key in the Anthropic Console.
  2. On your gateway host (the machine running openclaw gateway), export the variable:
Terminal window
export ANTHROPIC_API_KEY="..."
openclaw models status
  1. If you run the Gateway as a background service (like systemd or launchd), put the key in your .env file so the daemon can see it:
Terminal window
cat >> ~/.openclaw/.env <<'EOF'
ANTHROPIC_API_KEY=...
EOF
  1. Restart your Gateway process and verify the connection:
Terminal window
openclaw models status
openclaw doctor

If 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.

  1. Run the setup command:
    Terminal window
    claude setup-token
  2. 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:

Terminal window
openclaw models auth paste-token --provider anthropic

Once you have multiple keys or profiles, you can control which one OpenClaw uses.

In a chat session, use the /model command to pin a specific profile: /model claude-3-5-sonnet@anthropic:work

If you want a specific agent to always use a certain profile, use the CLI:

Terminal window
openclaw models auth order set --provider anthropic anthropic:default
openclaw models auth order get --provider anthropic
openclaw models auth order clear --provider anthropic

If you see this, the Anthropic token profile is likely missing. Run claude setup-token on your gateway host again, then check the status:

Terminal window
openclaw models status

I suggest using the automation-friendly check to catch this early:

Terminal window
openclaw models status --check

If 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.

OpenClaw

OpenClaw Expert

Still stuck?

If this page didn't answer your case, ask OpenClaw Expert for step-by-step guidance.