Skip to main content
The Anthropic provider enables Claude models with support for extended thinking, prompt caching, and tool calling.

Configuration

The AnthropicHandler accepts the following options:
string
required
Your Anthropic API key. Get one from Anthropic Console
string
Custom base URL for API requests. Defaults to Anthropic’s production API
string
required
Claude model to use. Examples:
  • claude-4.5-sonnet-20250514
  • claude-sonnet-4-20250514
  • claude-opus-4-20250514
  • claude-3-5-sonnet-20241022
number
default:"0"
Token budget for extended thinking. Set to 0 to disable thinking.Recommended values:
  • Light tasks: 2000-5000 tokens
  • Medium tasks: 5000-10000 tokens
  • Complex tasks: 10000-24000 tokens
function
Callback invoked when retrying failed requests

Basic Setup

Extended Thinking

Claude models support extended thinking for complex reasoning tasks:

Thinking Modes

Redacted Thinking

Some thinking blocks may be redacted (encrypted):

Prompt Caching

The handler automatically enables prompt caching for supported models:

Cache Strategy

The handler implements this caching strategy from anthropic.ts:74-80:
  1. System prompt marked with cache_control: { type: "ephemeral" }
  2. New tasks can reuse cached system prompt
  3. Cache breakpoints set at end of system prompt
  4. Reduces token usage on subsequent requests

Tool Calling

Tool Use Constraints

From anthropic.ts:84-90:
Tool forcing is incompatible with thinkingWhen thinkingBudgetTokens > 0, tools cannot be forced with tool_choice: { type: "any" }. The handler automatically handles this:
  • Thinking disabled: tool_choice: { type: "any" } (forces tool use)
  • Thinking enabled: tool_choice: undefined (auto mode)

1M Context Window

Enable the experimental 1M context window:

Streaming Response

The handler processes these Anthropic stream events:

message_start

content_block_start

content_block_delta

Error Handling

The handler includes automatic retry logic:

Custom Error Handling

Model Information

Implementation Reference

Source: ~/workspace/source/src/core/api/providers/anthropic.ts Key methods:
  • ensureClient() - Creates Anthropic SDK client with proxy support
  • createMessage() - Streams responses with thinking/caching/tools
  • getModel() - Returns model ID and metadata

Next Steps

OpenAI Provider

Configure OpenAI models

OpenRouter Provider

Access multiple providers

Provider Overview

View all providers

Custom Provider

Build your own