Anthropic Provider
The Anthropic provider gives you access to Claude models, known for their strong reasoning capabilities, extended context windows, and thoughtful responses. Claude excels at complex analysis, creative writing, and following detailed instructions.Installation
Authentication
Anthropic supports both direct API access and Azure AI Foundry hosted models.Direct Anthropic API
.env
Azure AI Foundry (Anthropic via Azure)
Basic Usage
Configuration
- Environment Variables
- Explicit Configuration
Streaming Responses
Function Calling (Tool Use)
Claude has excellent function calling capabilities:Claude can intelligently decide when and how to use multiple tools, even calling them in parallel when appropriate.
Available Models
Anthropic offers several Claude model families:| Model | Context Window | Best For | Strengths |
|---|---|---|---|
| claude-sonnet-4-20250514 | 200k | Balanced performance and speed | General purpose, reasoning |
| claude-opus-4-20250514 | 200k | Highest intelligence | Complex analysis, research |
| claude-haiku-4-5 | 200k | Speed and efficiency | Quick tasks, cost-effective |
| claude-3-5-sonnet | 200k | Previous generation | Legacy applications |
| claude-3-5-haiku | 200k | Fast, previous generation | Quick responses |
All Claude models support function calling, vision (image inputs), and extended thinking (reasoning). Context windows are 200k tokens for all current models.
Extended Thinking (Reasoning)
Claude models support extended thinking for complex reasoning tasks:Vision Capabilities
All Claude models support image inputs:Claude models have excellent vision capabilities and can analyze charts, diagrams, documents, photos, and screenshots with high accuracy.
Long Context
Claude models have 200k token context windows, enabling:- Processing entire books or codebases
- Analyzing lengthy documents
- Maintaining long conversations
- Handling extensive research materials
Best Practices
Choose the Right Model
Choose the Right Model
- Use claude-haiku-4-5 for quick, cost-effective tasks
- Use claude-sonnet-4 for balanced performance (most use cases)
- Use claude-opus-4 when maximum intelligence is critical
- All models support function calling and vision
Leverage Long Context
Leverage Long Context
Claude’s 200k context window is a key advantage:
- Process entire documents without chunking
- Maintain long conversation history
- Analyze multiple related documents together
- Keep extensive context for better coherence
Optimize Prompts
Optimize Prompts
Claude responds well to clear, structured prompts:
- Be explicit about desired output format
- Use XML-style tags for structure (Claude is trained on XML)
- Provide examples when possible
- Break complex tasks into steps
- Use “think step by step” for reasoning tasks
Handle Rate Limits
Handle Rate Limits
Anthropic has rate limits based on your tier:
- Implement exponential backoff retry logic
- Monitor usage in the Anthropic console
- Consider upgrading your tier for higher limits
- Batch similar requests when possible
Use Function Calling Effectively
Use Function Calling Effectively
Claude excels at tool use:
- Provide clear, detailed function descriptions
- Use descriptive parameter names
- Claude can chain multiple tool calls intelligently
- Claude can call tools in parallel when appropriate
Troubleshooting
Authentication Errors
Authentication Errors
If you see authentication errors:
- Verify the API key is correct and active
- Check if using Anthropic direct or Azure Foundry
- For Azure: ensure managed identity has proper permissions
- Verify the resource name is correct for Foundry
Rate Limit Errors
Rate Limit Errors
If you’re hitting rate limits:
- Check your usage tier at console.anthropic.com
- Implement exponential backoff
- Reduce request frequency
- Consider upgrading to a higher tier
- Monitor concurrent requests
Model Not Available
Model Not Available
If the model is not available:
- Check if you have access to the model
- Verify the model name is correct
- Some newer models require API access approval
- Check if using the right endpoint (Anthropic vs Azure)
Context Length Errors
Context Length Errors
If you exceed context length:
- Claude has 200k token limit
- Count both input and output tokens
- Implement conversation pruning for long sessions
- Consider summarizing older context
Cost Optimization
Anthropic pricing varies by model:- Use appropriate models: claude-haiku-4-5 is significantly cheaper than opus-4
- Monitor token usage: Input and output tokens are priced differently
- Optimize prompts: Shorter, clearer prompts use fewer tokens
- Cache system prompts: Reuse system instructions across requests
- Leverage long context: Process documents once instead of multiple chunks
Check current pricing at anthropic.com/pricing
Comparison with Other Providers
| Feature | Claude | GPT-4o | Advantage |
|---|---|---|---|
| Context Window | 200k | 128k | Claude |
| Vision | ✅ Excellent | ✅ Excellent | Tie |
| Function Calling | ✅ Excellent | ✅ Excellent | Tie |
| Reasoning | ✅ Extended thinking | ✅ o1/o3 models | Different approaches |
| Cost | $ | $$ | Claude (generally) |
| Document Analysis | ✅ Superior | ✅ Good | Claude |
| Creative Writing | ✅ Superior | ✅ Good | Claude |
| Code Generation | ✅ Good | ✅ Superior | GPT-4o |
Next Steps
Function Tools
Learn how to add function calling to your agents
Sessions & Memory
Manage multi-turn conversations with memory
Tools
Add function calling to Claude agents
Workflows
Build multi-agent workflows with Claude