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 modeSupported Models
Claude 4 (Latest)
claude-4-5-sonnet/claude-sonnet-4-5-20250929claude-4-1-opus/claude-opus-4-1-20250805claude-4-0-opus/claude-opus-4-20250514claude-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-20241022claude-3-5-sonnet-20240620claude-3-5-haiku-20241022
Claude 3
claude-3-opus-20240229claude-3-sonnet-20240229claude-3-haiku-20240307
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:Model Capabilities
Error Handling
Best Practices
- Use latest models: Claude 4.5 Sonnet offers best performance
- Enable thinking for complex tasks: Improves reasoning quality
- Use cache control: Reduce costs for repeated content
- Handle message alternation: Provider handles this automatically
- Leverage vision: Claude excels at image and PDF analysis
- Set appropriate maxTokens: Default is 4096, adjust as needed