Skip to content

Anthropic Provider

Integrates Anthropic's Claude models into Amplifier. Supports streaming, tool calling, extended thinking, and ChatRequest format.

Module ID

provider-anthropic

Installation

providers:
  - module: provider-anthropic
    source: git+https://github.com/microsoft/amplifier-module-provider-anthropic@main
    config:
      default_model: claude-sonnet-4-5

Configuration

Core Options

Option Type Default Description
api_key string $ANTHROPIC_API_KEY API authentication key
base_url string (none) Custom API endpoint (for proxies, local APIs)
default_model string claude-sonnet-4-5 Default model
max_tokens int 64000 Maximum response tokens
temperature float 0.7 Sampling temperature
timeout float 600.0 API timeout in seconds
priority int 100 Provider priority for selection

Feature Toggles

Option Type Default Description
use_streaming bool true Use streaming API (required for large contexts)
enable_prompt_caching bool true Enable prompt caching (90% cost reduction on cached tokens)
enable_web_search bool false Enable native web search tool
enable_1m_context bool false Enable 1M token context window (Sonnet and Opus only)
filtered bool true Filter to curated model list

Rate Limit & Retry

Option Type Default Description
max_retries int 5 Total retry attempts before failing
retry_jitter float 0.2 Randomness to add to delays (0.0-1.0)
max_retry_delay float 60.0 Maximum wait between retries (seconds)
min_retry_delay float 1.0 Minimum delay if no retry-after header
throttle_threshold float 0.02 Pre-emptive throttle trigger (2% capacity remaining)
throttle_delay float 1.0 Throttle delay when approaching limits (seconds)

Debug Options

Option Type Default Description
debug bool false Enable standard debug events
raw_debug bool false Enable ultra-verbose raw API I/O logging

Supported Models

Model Description
claude-sonnet-4-5 Claude Sonnet 4.5 (recommended, default)
claude-opus-4-6 Claude Opus 4.6 (most capable)
claude-haiku-4-5 Claude Haiku 4.5 (fastest, cheapest)

Extended Thinking

Enable extended thinking for complex reasoning tasks:

providers:
  - module: provider-anthropic
    config:
      default_model: claude-sonnet-4-5

Then in your request:

request = ChatRequest(
    model="claude-sonnet-4-5",
    messages=[...],
    enable_thinking=True
)

The response will include thinking blocks showing the model's reasoning process.

Prompt Caching

Anthropic's prompt caching reduces costs by 90% for repeated content. Enable it:

providers:
  - module: provider-anthropic
    config:
      enable_prompt_caching: true

The provider automatically marks eligible content for caching based on message structure.

Enable native web search (Claude 4+ models only):

providers:
  - module: provider-anthropic
    config:
      enable_web_search: true

The model can then search the web directly during conversations.

Rate Limit Management

The provider tracks rate limits from response headers and pre-emptively throttles when approaching limits:

providers:
  - module: provider-anthropic
    config:
      throttle_threshold: 0.02  # Throttle at 2% capacity remaining
      throttle_safety_margin: 1.0  # Add 1s safety delay

Events: - provider:throttle - Emitted when pre-emptive throttling occurs - provider:retry - Emitted before each retry attempt

Retry Configuration

providers:
  - module: provider-anthropic
    config:
      max_retries: 5
      min_retry_delay: 1.0
      max_retry_delay: 60.0
      retry_jitter: 0.2

The provider uses exponential backoff with jitter and honors retry-after headers from the API.

Error Handling

The provider translates Anthropic SDK exceptions to kernel errors:

SDK Exception Kernel Error Retryable
RateLimitError RateLimitError Yes
OverloadedError ProviderUnavailableError Yes (10× backoff)
InternalServerError ProviderUnavailableError Yes
AuthenticationError AuthenticationError No
BadRequestError (context length) ContextLengthError No
BadRequestError (content filter) ContentFilterError No
BadRequestError (other) InvalidRequestError No

Debug Events

Enable debug logging to see request/response details:

providers:
  - module: provider-anthropic
    config:
      debug: true  # Standard debug events
      raw_debug: true  # Ultra-verbose raw API I/O

Events: - llm:request:debug - Request summary (message counts, model, params) - llm:response:debug - Response summary (usage, stop reason) - llm:request:raw - Complete unmodified request params - llm:response:raw - Complete unmodified response object

Environment Variables

export ANTHROPIC_API_KEY="your-api-key-here"

Example Configuration

providers:
  - module: provider-anthropic
    source: git+https://github.com/microsoft/amplifier-module-provider-anthropic@main
    config:
      api_key: ${ANTHROPIC_API_KEY}
      default_model: claude-sonnet-4-5
      max_tokens: 8192
      temperature: 1.0
      enable_prompt_caching: true
      enable_web_search: false
      max_retries: 5
      retry_jitter: 0.2