Skip to main content

Overview

The Anthropic provider integrates Claude models with LlamaIndex.TS, supporting all Claude 3, 3.5, 3.7, and 4 series models.

Installation

Basic Usage

Constructor Options

string
default:"claude-3-opus"
Claude model name
number
default:1
Sampling temperature (0-1)
number
Nucleus sampling parameter
number
Maximum tokens in response
string
Anthropic API key (defaults to ANTHROPIC_API_KEY env variable)
number
default:10
Maximum request retries
number
default:60000
Request timeout in milliseconds
AnthropicAdditionalChatOptions
Additional options like thinking mode

Supported Models

Claude 4 (Latest)

  • claude-4-5-sonnet / claude-sonnet-4-5-20250929
  • claude-4-1-opus / claude-opus-4-1-20250805
  • claude-4-0-opus / claude-opus-4-20250514
  • claude-4-0-sonnet / claude-sonnet-4-20250514

Claude 3.7

  • claude-3-7-sonnet / claude-3-7-sonnet-20250219

Claude 3.5

  • claude-3-5-sonnet-20241022
  • claude-3-5-sonnet-20240620
  • claude-3-5-haiku-20241022

Claude 3

  • claude-3-opus-20240229
  • claude-3-sonnet-20240229
  • claude-3-haiku-20240307
All models support 200K context window.

Streaming

Function Calling

Claude 3+ models support tool use:

Extended Thinking

Claude 4+ supports extended thinking blocks:

Multi-modal Input

Images

PDFs

Prompt Caching (Beta)

Use cache control to reduce costs for repeated content:

Configuration

Environment Variables

Global Settings

Response Format

Note: Anthropic does not support native structured output. Use tool calling for structured data:

Message Handling

Claude has specific requirements:

System Messages

System messages are handled separately:

Message Alternation

Messages must alternate between user and assistant:
The provider automatically merges consecutive messages.

Model Capabilities

Error Handling

Best Practices

  1. Use latest models: Claude 4.5 Sonnet offers best performance
  2. Enable thinking for complex tasks: Improves reasoning quality
  3. Use cache control: Reduce costs for repeated content
  4. Handle message alternation: Provider handles this automatically
  5. Leverage vision: Claude excels at image and PDF analysis
  6. Set appropriate maxTokens: Default is 4096, adjust as needed

See Also