Skip to main content
Weaver provides native SDK support for Anthropic’s Claude models with both API key and OAuth authentication.

Authentication Methods

1. API Key Authentication

Standard Anthropic API key authentication.

Get API Key

  1. Visit Anthropic Console
  2. Navigate to API Keys
  3. Create a new API key
  4. Copy the key (starts with sk-ant-)

Configure Weaver

Option A: Configuration File Add to ~/.weaver/config.json:
{
  "providers": {
    "anthropic": {
      "api_key": "sk-ant-...",
      "api_base": "https://api.anthropic.com/v1"
    }
  },
  "agents": {
    "defaults": {
      "provider": "anthropic",
      "model": "claude-sonnet-4-5-20250929"
    }
  }
}
Option B: Environment Variable Add to .env:
ANTHROPIC_API_KEY=sk-ant-...

2. OAuth Authentication

Use OAuth for token-based authentication:
weaver auth login --provider anthropic
Configure in ~/.weaver/config.json:
{
  "providers": {
    "anthropic": {
      "auth_method": "oauth"
    }
  }
}
OAuth authentication automatically refreshes tokens and is recommended for long-running deployments.

Available Models

Weaver supports all Claude model variants:
ModelDescriptionContext Window
claude-sonnet-4-5-20250929Latest Sonnet (default)200K tokens
claude-3.5-sonnet-20241022Previous Sonnet version200K tokens
claude-3-opus-20240229Most capable Claude 3200K tokens
claude-3-haiku-20240307Fast and efficient200K tokens

Configuration Options

api_key
string
Anthropic API key (required for API key auth)
api_base
string
default:"https://api.anthropic.com/v1"
Anthropic API endpoint URL
auth_method
string
Authentication method: api_key (default), oauth, or token
proxy
string
HTTP/HTTPS proxy URL for API requests (optional)

Model Parameters

Configure model behavior:
{
  "agents": {
    "defaults": {
      "model": "claude-sonnet-4-5-20250929",
      "max_tokens": 8192,
      "temperature": 0.7
    }
  }
}
max_tokens
integer
default:"4096"
Maximum tokens in response (Claude enforces max_tokens)
temperature
float
default:"0.7"
Controls randomness in responses (0.0 = deterministic, 1.0 = very random)

Message Format

Weaver automatically converts between standard and Claude message formats:

System Messages

{
  "role": "system",
  "content": "You are a helpful assistant"
}
Converted to Claude’s system parameter.

User Messages

{
  "role": "user",
  "content": "Hello!"
}

Tool Results

{
  "role": "tool",
  "tool_call_id": "call_123",
  "content": "{\"result\": \"success\"}"
}
Converted to Claude’s tool_result blocks. Source: pkg/providers/claude_provider.go:59-97

Tool Calling

Claude natively supports tool calling. Weaver automatically converts tool definitions:
// Weaver format
type ToolDefinition struct {
  Type     string
  Function ToolFunctionDefinition
}

// Converted to Claude ToolParam
{
  "name": "function_name",
  "description": "Function description",
  "input_schema": {
    "properties": {...},
    "required": [...]
  }
}
Source: pkg/providers/claude_provider.go:125-149

Tool Response Parsing

Claude returns tool calls in content blocks:
{
  "type": "tool_use",
  "id": "toolu_123",
  "name": "function_name",
  "input": {...}
}
Weaver parses these into standard ToolCall format. Source: pkg/providers/claude_provider.go:151-194

Implementation Details

Weaver’s Anthropic integration uses:
  • ClaudeProvider with native Anthropic SDK (github.com/anthropics/anthropic-sdk-go)
  • Automatic token refresh via token source function
  • Native tool calling support with input schema validation
  • Proper message format conversion for system/user/assistant/tool roles
Source: pkg/providers/claude_provider.go

Usage Examples

Basic Usage

# Use latest Sonnet
weaver chat --model claude-sonnet-4-5-20250929

# Use Opus for complex tasks
weaver chat --model claude-3-opus-20240229

# Use Haiku for speed
weaver chat --model claude-3-haiku-20240307

With Tool Calling

{
  "agents": {
    "defaults": {
      "model": "claude-sonnet-4-5-20250929",
      "max_tokens": 8192,
      "max_tool_iterations": 20
    }
  }
}

With Proxy

Configure proxy for restricted networks:
{
  "providers": {
    "anthropic": {
      "api_key": "sk-ant-...",
      "proxy": "http://proxy.company.com:8080"
    }
  }
}

Response Handling

Weaver parses Claude responses with proper finish reason mapping:
Claude ReasonWeaver ReasonDescription
end_turnstopNatural completion
tool_usetool_callsTool calling triggered
max_tokenslengthHit token limit
Source: pkg/providers/claude_provider.go:174-183

Troubleshooting

API Key Issues

# Verify API key
echo $ANTHROPIC_API_KEY

# Test with curl
curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-3-haiku-20240307","max_tokens":100,"messages":[{"role":"user","content":"Hi"}]}'

OAuth Issues

# Re-authenticate
weaver auth logout --provider anthropic
weaver auth login --provider anthropic

# Check credentials
weaver auth list

Common Errors

  • Verify API key is correct and starts with sk-ant-
  • For OAuth: Run weaver auth login --provider anthropic
  • Check that the API key hasn’t been revoked
  • Claude requires max_tokens parameter
  • Set in config: "max_tokens": 8192
  • Weaver defaults to 4096 if not specified
  • Check your API usage in Anthropic Console
  • Implement exponential backoff
  • Consider upgrading to a higher tier
  • Ensure tool definitions include proper schema
  • Check that required fields are specified
  • Verify JSON in tool responses is valid

Next Steps

Provider Overview

Back to all providers

Tool Calling

Use tools with Claude

Build docs developers (and LLMs) love