Skip to main content

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)

Never commit API keys to source control. Always use environment variables or secure secret management.

Basic Usage

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:
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:
Claude models automatically engage extended thinking for complex problems. You can encourage this behavior by prompting the model to “think step by step” or “analyze carefully.”

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
Claude maintains strong performance even with very long contexts, making it ideal for document analysis and research tasks.

Best Practices

  • 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
Claude’s 200k context window is a key advantage:
  1. Process entire documents without chunking
  2. Maintain long conversation history
  3. Analyze multiple related documents together
  4. Keep extensive context for better coherence
Claude responds well to clear, structured prompts:
  1. Be explicit about desired output format
  2. Use XML-style tags for structure (Claude is trained on XML)
  3. Provide examples when possible
  4. Break complex tasks into steps
  5. Use “think step by step” for reasoning tasks
Anthropic has rate limits based on your tier:
  1. Implement exponential backoff retry logic
  2. Monitor usage in the Anthropic console
  3. Consider upgrading your tier for higher limits
  4. Batch similar requests when possible
Claude excels at tool use:
  1. Provide clear, detailed function descriptions
  2. Use descriptive parameter names
  3. Claude can chain multiple tool calls intelligently
  4. Claude can call tools in parallel when appropriate

Troubleshooting

If you see authentication errors:
  1. Verify the API key is correct and active
  2. Check if using Anthropic direct or Azure Foundry
  3. For Azure: ensure managed identity has proper permissions
  4. Verify the resource name is correct for Foundry
If you’re hitting rate limits:
  1. Check your usage tier at console.anthropic.com
  2. Implement exponential backoff
  3. Reduce request frequency
  4. Consider upgrading to a higher tier
  5. Monitor concurrent requests
If the model is not available:
  1. Check if you have access to the model
  2. Verify the model name is correct
  3. Some newer models require API access approval
  4. Check if using the right endpoint (Anthropic vs Azure)
If you exceed context length:
  1. Claude has 200k token limit
  2. Count both input and output tokens
  3. Implement conversation pruning for long sessions
  4. Consider summarizing older context

Cost Optimization

Anthropic pricing varies by model:
  1. Use appropriate models: claude-haiku-4-5 is significantly cheaper than opus-4
  2. Monitor token usage: Input and output tokens are priced differently
  3. Optimize prompts: Shorter, clearer prompts use fewer tokens
  4. Cache system prompts: Reuse system instructions across requests
  5. Leverage long context: Process documents once instead of multiple chunks
Check current pricing at anthropic.com/pricing

Comparison with Other Providers

Claude excels at document analysis, creative writing, and following complex instructions. GPT-4o may be better for code generation and certain reasoning tasks.

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