Anthropic Claude Setup

📘 Guide Status: This page covers configuring Anthropic’s Claude models as an OpenClaw model provider. For first-time OpenClaw setup, see the Quick Start Guide. For the full config layout, see Configuration File Structure.

Overview

Anthropic is the company behind Claude, a family of large language models known for strong reasoning, long-context understanding (up to 200K tokens on many models), and coding assistance. OpenClaw is model-agnostic: you can use Claude as the “brain” of your agent by configuring Anthropic as a model provider. Your OpenClaw agent then gets Claude’s capabilities-analysis, long documents, code-plus OpenClaw’s automation (files, browser, cron, messaging channels) and self-hosted control.

This guide covers:

  • Getting an Anthropic API key and where to set it
  • Adding the Anthropic provider block to your OpenClaw config
  • Choosing Claude model IDs (Sonnet, Opus, Haiku) and context limits
  • Cost considerations and optional limits
  • Anthropic-specific troubleshooting and best practices
  • Links to agents, memory, and other model providers

Prerequisites

Step 1: Get Your Anthropic API Key

Anthropic uses API keys for authentication. Never commit keys to the config file; use environment variables or a secrets manager.

  1. Sign in at console.anthropic.com.
  2. Create or copy an API key from the API keys section.
  3. Set the key in your environment, for example:
    export ANTHROPIC_API_KEY="sk-ant-..."
    On Windows (Command Prompt): set ANTHROPIC_API_KEY=sk-ant-.... For persistent setup, add to your shell profile or use a credential management approach recommended in our security best practices.

Step 2: Add the Anthropic Provider in Config

Edit your OpenClaw config with openclaw config edit (or open the file path shown by openclaw doctor). In the model providers section, add a block for Anthropic. Exact keys depend on your OpenClaw version; typical pattern:

  • Provider id: e.g. anthropic (you’ll reference this in your agent config).
  • API key: Reference the env var (e.g. ANTHROPIC_API_KEY) so the key is not stored in the config file.
  • Models: List of allowed model IDs (see below).
  • Optional: Request timeout, rate limits, or spending caps if your OpenClaw version supports them.

After editing, save the file. Restart the gateway if required by your version so it picks up the new provider. For the full config layout (gateway, channels, model providers, agents, skills, memory), see Configuration File Structure.

Step 3: Choose a Claude Model

Anthropic offers several Claude models. Use the model ID that matches the model you want (check Anthropic’s model list for the latest names and context lengths). Examples of common IDs:

Model Typical use
Claude 3.5 Sonnet Strong balance of speed, quality, and cost; good for most agent workloads and coding.
Claude 3 Opus Highest capability; best for complex reasoning and long-context tasks.
Claude 3 Haiku Faster and cheaper; good for simple Q&A and high-volume, low-latency tasks.

Many Claude models support large context windows (e.g. 200K tokens). In OpenClaw, your memory and agent context settings determine how much history is sent; keep context within your model’s limit to avoid errors and control API cost.

Step 4: Assign the Model to an Agent

In the agents section of your config, set the agent’s model to the Anthropic provider and the desired Claude model ID (e.g. claude-3-5-sonnet-20241022 or the current ID from Anthropic’s docs). Only model IDs listed under your Anthropic provider block will be allowed. See Agent customization for system prompts, multiple agents, and skills.

Verification

Run openclaw status and ensure the gateway and config are valid. Send a test message to your agent on a connected channel (e.g. Telegram). If the agent responds using Claude, the provider is working. For diagnostics, use openclaw doctor and openclaw logs; see the troubleshooting guide and model and API errors for common failures.

Common Issues (Anthropic / Claude)

Issue Solution
Invalid API key / 401 Check that ANTHROPIC_API_KEY is set in the environment the gateway uses, and that the key is correct and active in the Anthropic console.
Model not found / invalid model Use the exact model ID from Anthropic’s documentation; IDs can change with new versions. Ensure the model is listed in your provider’s allowed models.
Rate limit (429) Anthropic enforces rate limits. Reduce request frequency, or add backoff/limits in config if supported; consider a faster/cheaper model (e.g. Haiku) for high volume.
Overloaded / 529 Anthropic’s service may be temporarily busy. Retry with backoff; check status.anthropic.com if needed.
High cost or slow responses Use a smaller/faster model (e.g. Haiku) where possible; reduce context window size; set spending limits in the Anthropic console.

For more errors and fixes, see the full troubleshooting hub and model and API errors.

Best Practices

  • Secrets: Keep the API key in environment variables or a secrets manager; do not put it in the config file. See credential management and security best practices.
  • Context and cost: Match your memory and agent context to your model’s context limit; oversized context increases latency and API cost.
  • Updates: Keep OpenClaw and your config in sync with the official docs; check Anthropic’s docs for model ID and pricing changes.
  • Spending: Set usage or spending limits in the Anthropic console to avoid unexpected bills.

Other Model Providers

You can use multiple providers: e.g. Claude for complex tasks and a local model via Ollama for simple ones. See the Model Providers overview and the per-provider guides: OpenAI GPT, Google Gemini, DeepSeek, Local Models (Ollama).

Next Steps

Related Resources