Prerequisites

Quick Start in 3 Steps

Step 1 — Set your API key:

openclaw config set anthropic.api_key "sk-ant-..."

Step 2 — Set Claude as your provider:

openclaw config set provider anthropic
openclaw config set anthropic.model claude-3-5-sonnet-20241022

Step 3 — Run your first task:

openclaw run "Analyze this codebase and suggest improvements"

Claude Model Lineup

ModelContext WindowBest ForSpeed
claude-3-5-sonnet-20241022200K tokensCoding, analysis, balancedFast
claude-3-opus-20240229200K tokensComplex reasoning, researchSlow
claude-3-haiku-20240307200K tokensSimple tasks, lowest costVery Fast
claude-3-sonnet-20240229200K tokensBalanced cost/qualityMedium

API Key Setup

# Get your key at console.anthropic.com
openclaw config set claude.api_key "sk-ant-..."

# Or environment variable
export ANTHROPIC_API_KEY="sk-ant-..."

# Set Claude as default provider
openclaw config set provider claude

Configuration

# config.yaml
provider: claude
claude:
  api_key: "${ANTHROPIC_API_KEY}"
  model: claude-3-5-sonnet-20241022
  max_tokens: 8192
  temperature: 0.3
# Override model per-run
openclaw run "Analyze this legal document" --provider claude --model claude-3-opus-20240229

# Use Haiku for fast, cheap tasks
openclaw run "Extract keywords from text" --provider claude --model claude-3-haiku-20240307

200K Context Window Advantage

Claude's 200K context window (roughly 150,000 words) enables processing entire codebases, lengthy reports, or full-book analysis in a single request:

# Summarize a 100-page PDF (via file tool)
openclaw run "Summarize this entire document and extract key findings" \
  --provider claude \
  --attach report.pdf

# Analyze a large codebase
openclaw run "Review all Python files for security issues" \
  --provider claude \
  --context ./src/**/*.py

Rate Limits

Anthropic enforces per-API-key rate limits depending on your usage tier. OpenClaw automatically retries on HTTP 429 responses. You can monitor usage at console.anthropic.com.

Vision and Image Analysis

Claude 3 and later models support image input (Vision). Send screenshots, diagrams, or photos alongside your task:

# Analyze a screenshot
openclaw run "Explain what's shown in this UI screenshot" \
  --provider claude \
  --image ./screenshot.png

# Review a system architecture diagram
openclaw run "Identify potential bottlenecks in this architecture" \
  --provider claude \
  --image ./architecture.png

# Extract data from a scanned document
openclaw run "Extract all table data from this scan as JSON" \
  --provider claude \
  --image ./scanned-table.jpg
📋
Supported formats: JPEG, PNG, GIF, and WebP. Maximum image size is 5 MB per image. You can include up to 20 images per request.

Prompt Caching (Cost Optimization)

Claude's prompt caching feature lets you cache frequently-used context (like a system prompt or reference document), reducing costs by up to 90% on repeated calls:

# config.yaml — enable prompt caching
provider: claude
claude:
  api_key: "${ANTHROPIC_API_KEY}"
  model: claude-3-5-sonnet-20241022
  prompt_caching: true     # cache repeated system prompts
  cache_ttl: 300           # seconds to keep cache alive
# Cache a large document and query it multiple times
openclaw run "What is the refund policy?" --provider claude --cache-context ./terms.pdf
openclaw run "What are the data retention rules?" --provider claude  # uses cache

Cost and Model Comparison

ModelInput CostOutput CostBest For
Claude 3 Haiku$0.25 / 1M tokens$1.25 / 1M tokensHigh-volume, simple tasks
Claude 3.5 Sonnet$3.00 / 1M tokens$15.00 / 1M tokensBalanced daily use, coding
Claude 3 Opus$15.00 / 1M tokens$75.00 / 1M tokensComplex analysis, research
💡
Cost Tip: Use Claude 3 Haiku for classification, extraction, and simple Q&A at minimal cost. Reserve Opus for tasks that require deep reasoning or legal/medical analysis.

When to Choose Claude

  • Long document analysis — 200K context processes entire codebases or books in one request
  • Safety-critical content — Claude has built-in guardrails ideal for enterprise use
  • Code analysis and review — Claude 3.5 Sonnet excels at explaining and refactoring complex code
  • Research and writing — high coherence over long outputs, ideal for reports
  • Image + document processing — vision + text in a single request

Troubleshooting

ErrorCauseFix
401 UnauthorizedInvalid API keyVerify key at console.anthropic.com
429 Too Many RequestsRate limit exceededOpenClaw auto-retries; check your usage tier to upgrade
400 context_length_exceededInput too longUse --model claude-3-5-sonnet-20241022 (200K context) or split input
500 API ErrorAnthropic outageCheck status.anthropic.com
Unrecognized model nameWrong model identifierCheck the exact model ID in the models table above

What's Next