Skip to main content

Overview

The Anthropic provider connects to Claude models including Sonnet, Opus, and Haiku. It supports advanced features like extended thinking, prompt caching, and tool use. Source: crates/goose/src/providers/anthropic.rs

Configuration

Environment Variables

string
required
Your Anthropic API key from https://console.anthropic.com
string
default:"https://api.anthropic.com"
API endpoint URL (for proxy or alternative endpoints)

Setup

Supported Models

Claude 4.6

  • claude-opus-4-6 - Most capable model
  • claude-sonnet-4-6 - Balanced performance

Claude 4.5 (Default)

  • claude-sonnet-4-5 (default) - Latest Sonnet with improved reasoning
  • claude-sonnet-4-5-20250929 - Dated version
  • claude-haiku-4-5 (fast model) - Fastest Claude 4.5
  • claude-haiku-4-5-20251001 - Dated version
  • claude-opus-4-5 - Most capable 4.5 model
  • claude-opus-4-5-20251101 - Dated version

Claude 4.0 (Legacy)

  • claude-sonnet-4-0
  • claude-sonnet-4-20250514 - Dated version
  • claude-opus-4-0
  • claude-opus-4-20250514 - Dated version
Context Limit: 200,000 tokens for all models Documentation: https://docs.anthropic.com/en/docs/about-claude/models

Usage

Basic Usage

Custom Configuration

Using Fast Models

The Anthropic provider automatically configures claude-haiku-4-5 as the fast model:

Advanced Features

Extended Thinking

Claude 3.7 Sonnet supports extended thinking mode:
When enabled, the provider automatically adds the appropriate beta headers:
  • anthropic-beta: output-128k-2025-02-19
  • anthropic-beta: token-efficient-tools-2025-02-19

Prompt Caching

Anthropic supports prompt caching to reduce costs on repeated content:

Streaming Responses

All Anthropic models support streaming:

Tool Use

Claude excels at tool use (function calling):

Implementation Details

Provider Metadata

API Format

The provider uses the Messages API format:

Authentication

Uses API key authentication via the x-api-key header:
API version is specified via header:

Conditional Headers

The provider dynamically adds beta headers for certain models:

Error Handling

The provider handles Anthropic-specific errors:

Fetching Available Models

Cost Tracking

The provider returns usage information with each response:

See Also