Home Tutorials Categories Skills About
ZH EN JA KO
Model Integration

How to Configure the Claude API in OpenClaw

· 12 min read

Why Choose Claude as Your AI Model

Among the many AI models that OpenClaw supports, Anthropic's Claude series stands out for its strong language comprehension, long context window, and consistent output quality. It's especially reliable for everyday conversations, text analysis, and coding assistance, making it a top choice for many users.

This article walks you through getting a Claude API key and configuring it in OpenClaw.

Get an Anthropic API Key

First, you'll need to register an account on the Anthropic website and generate an API key:

  1. Go to Anthropic Console
  2. Sign up or log in
  3. Navigate to the API Keys page
  4. Click Create Key to generate a new API key
  5. Give the key a name, such as openclaw-home, for easy management
  6. Copy the generated key (it starts with sk-ant-) — save it somewhere safe, as you won't be able to view it again after closing the page

Before you start using it, you'll also need to add a payment method and fund your account in the Anthropic Console. The Claude API is billed per usage, though newly registered accounts typically receive some free credits for testing.

Configure Claude in OpenClaw

Option 1: Use the Onboard Wizard

If you're setting up OpenClaw for the first time, running openclaw onboard will prompt you to choose an AI model provider. Select Anthropic and paste your API key when prompted.

Option 2: Edit the Configuration File Manually

If you've already completed the initial setup, you can edit the configuration file directly at ~/.config/openclaw/openclaw.json5:

{
  providers: {
    anthropic: {
      enabled: true,
      apiKey: "sk-ant-api03-xxxxxxxxxxxx",
      defaultModel: "claude-sonnet-4-20250514",
      // Optional: set maximum token count
      maxTokens: 4096
    }
  },

  // Set the global default provider
  defaultProvider: "anthropic"
}

Option 3: Use Environment Variables

If you'd rather not store the key in plaintext in the configuration file (which is the recommended security practice), you can pass it through an environment variable:

export ANTHROPIC_API_KEY="sk-ant-api03-xxxxxxxxxxxx"

Then omit the apiKey field in the configuration file — OpenClaw will automatically read the environment variable:

{
  providers: {
    anthropic: {
      enabled: true,
      defaultModel: "claude-sonnet-4-20250514"
    }
  }
}

For Docker deployments, storing the key in the .env file is the recommended approach.

Available Claude Models

As of now, the following Claude models are available in OpenClaw:

Model ID Characteristics Best For
claude-sonnet-4-20250514 Balanced performance and cost Everyday conversations, general tasks
claude-opus-4-20250514 Strongest reasoning capabilities Complex analysis, long-form writing
claude-haiku-3-20250307 Fast and affordable Simple Q&A, high-frequency calls

For daily use, Sonnet is the sweet spot. Switch to Opus when you need to tackle complex tasks, and use Haiku for latency-sensitive or high-volume scenarios.

You can set a default model in the configuration file and switch between models dynamically during conversations:

{
  providers: {
    anthropic: {
      enabled: true,
      defaultModel: "claude-sonnet-4-20250514",
      models: {
        "claude-opus-4-20250514": {
          maxTokens: 8192
        },
        "claude-haiku-3-20250307": {
          maxTokens: 2048
        }
      }
    }
  }
}

Verify the Configuration

After making your changes, restart the OpenClaw Gateway:

openclaw restart

Then send a test message through the Dashboard:

openclaw dashboard

Type anything in the chat box. If you get a reply from Claude, the configuration is working.

You can also do a quick test from the command line:

openclaw chat "Hello, introduce yourself in one sentence"

If you get a response like "I'm Claude, an AI assistant developed by Anthropic," you're all set.

Managing Costs

The Claude API bills per token, with different rates for input and output. To avoid unexpected charges, consider these measures:

1. Set usage limits in the Anthropic Console:

Log in to the Console, go to Settings > Limits, and set a monthly spending cap. Once the cap is reached, the API will return errors instead of continuing to charge.

2. Limit the response length in OpenClaw:

{
  providers: {
    anthropic: {
      maxTokens: 2048  // Cap each response at 2048 tokens
    }
  }
}

3. Restrict which users can trigger the AI:

Set up allowlists in your channel configurations to prevent unrelated people from consuming your API credits through your chat platforms.

4. Monitor usage regularly:

The Usage page in the Anthropic Console provides detailed call statistics and cost breakdowns.

Multi-Provider Configuration

OpenClaw supports configuring multiple providers simultaneously. You can use Claude as your primary model while keeping Ollama as a fallback (runs locally, no cost):

{
  providers: {
    anthropic: {
      enabled: true,
      defaultModel: "claude-sonnet-4-20250514"
    },
    ollama: {
      enabled: true,
      defaultModel: "llama3"
    }
  },
  defaultProvider: "anthropic",
  fallbackProvider: "ollama"
}

When the Claude API is unavailable, OpenClaw will automatically switch to the Ollama local model, keeping your service running without interruption.

Wrapping Up

Claude is one of the best-performing models available in OpenClaw, and the setup is straightforward. By managing your key through environment variables, setting sensible usage limits, and configuring Ollama as a backup, you can build a personal AI assistant that's both high-quality and cost-effective. For questions, refer to the OpenClaw official documentation or visit the OpenClaw GitHub repository for help. For more model integration options, visit OpenClaw.

OpenClaw is a free, open-source personal AI assistant that supports WhatsApp, Telegram, Discord, and many more platforms