elbruno.Extensions.AI.Claude
A C# library for using Claude models (Sonnet 4.5, Haiku 4.5, Opus 4.1) deployed in Microsoft Foundry, implementing Microsoft.Extensions.AI abstractions
Install
| Product | Versions |
|---|---|
| .NET |
README
elbruno.Extensions.AI.Claude
A C# library for using Claude models deployed in Microsoft Foundry, implementing the Microsoft.Extensions.AI abstractions.
Overview
This library provides an AzureClaudeClient that allows you to interact with Claude models (e.g., Claude Sonnet 4.5) deployed in Microsoft Foundry. It follows the same patterns as AzureOpenAIClient and implements the standard IChatClient interface from Microsoft.Extensions.AI.
Features
- β
Full
IChatClientimplementation - β Support for both streaming and non-streaming completions
- β Azure authentication using Azure Identity
- β System messages support
- β Multi-turn conversations
- β Token usage tracking
- β Configurable chat options (temperature, top-p, max tokens)
Installation
dotnet add package elbruno.Extensions.AI.Claude
Prerequisites
- An Azure subscription
- A Claude model deployed in Microsoft Foundry
- Appropriate Azure credentials configured
Quick Start
using Azure.Identity;
using elbruno.Extensions.AI.Claude;
using Microsoft.Extensions.AI;
// Configure the client
var endpoint = new Uri("https://your-endpoint.services.ai.azure.com");
var deploymentName = "claude-sonnet-4-5"; // Your deployment name
var credential = new DefaultAzureCredential();
// Create the client
var client = new AzureClaudeClient(endpoint, deploymentName, credential);
// Send a message
var messages = new List<ChatMessage>
{
new(ChatRole.User, "What is the capital of France?")
};
var response = await client.CompleteAsync(messages);
Console.WriteLine(response.Message.Text);
Usage Examples
Simple Completion
var messages = new List<ChatMessage>
{
new(ChatRole.User, "Explain quantum computing in simple terms.")
};
var response = await client.CompleteAsync(messages);
Console.WriteLine(response.Message.Text);
Console.WriteLine($"Tokens used: {response.Usage?.TotalTokenCount}");
Streaming Completion
var messages = new List<ChatMessage>
{
new(ChatRole.User, "Write a short story about a robot.")
};
await foreach (var update in client.CompleteStreamingAsync(messages))
{
if (!string.IsNullOrEmpty(update.Text))
{
Console.Write(update.Text);
}
}
Multi-turn Conversation
var conversation = new List<ChatMessage>
{
new(ChatRole.System, "You are a helpful coding assistant."),
new(ChatRole.User, "How do I create a list in Python?"),
};
var response1 = await client.CompleteAsync(conversation);
conversation.Add(response1.Message);
conversation.Add(new ChatMessage(ChatRole.User, "Can you show me an example?"));
var response2 = await client.CompleteAsync(conversation);
With Chat Options
var options = new ChatOptions
{
Temperature = 0.7,
TopP = 0.9,
MaxOutputTokens = 2048
};
var messages = new List<ChatMessage>
{
new(ChatRole.User, "Generate creative ideas for a tech startup.")
};
var response = await client.CompleteAsync(messages, options);
Configuration
Environment Variables
You can configure the client using environment variables:
export AZURE_CLAUDE_ENDPOINT="https://your-endpoint.services.ai.azure.com"
export AZURE_CLAUDE_MODEL="claude-sonnet-4-5"
Authentication
The library uses Azure Identity for authentication. You can use any of the following:
DefaultAzureCredential(recommended for development and production)ManagedIdentityCredential(for Azure resources)EnvironmentCredential(for environment variables)AzureCliCredential(for local development)
Example with specific credential:
var credential = new ManagedIdentityCredential();
var client = new AzureClaudeClient(endpoint, deploymentName, credential);
Supported Models
This library supports Claude models deployed in Microsoft Foundry through global standard deployment. The following models are currently available:
Available Models
Claude Sonnet 4.5 (deployment name:
claude-sonnet-4-5) - Anthropic's most capable model for building real-world agents and handling complex, long-horizon tasks. Best for agentic workflows, computer use capabilities, and production deployments.Claude Haiku 4.5 (deployment name:
claude-haiku-4-5) - Delivers near-frontier performance with optimal speed and cost. One of the best coding and agent models, ideal for free products and scaled sub-agents.Claude Opus 4.1 (deployment name:
claude-opus-4-1) - Industry leader for coding. Delivers sustained performance on long-running tasks requiring focused effort and thousands of steps, significantly expanding what AI agents can solve.
All models support:
- 1 million token context window
- Extended thinking for enhanced reasoning
- Image and text input
- Code generation, analysis, and debugging (Sonnet 4.5 and Opus 4.1)
Choosing the Right Model
- Claude Sonnet 4.5: Best for balanced performance and capabilities, production workflows, complex reasoning, and agentic tasks
- Claude Haiku 4.5: Best for speed and cost optimization, high-volume processing, fast responses
- Claude Opus 4.1: Best for complex coding tasks, long-running agent workflows, and enterprise applications requiring sustained performance
API Reference
AzureClaudeClient
Constructor
public AzureClaudeClient(
Uri endpoint,
string modelId,
TokenCredential credential,
HttpClient? httpClient = null)
Properties
Metadata- ReturnsChatClientMetadatawith provider name and model ID
Methods
CompleteAsync- Sends a completion request and returns the full responseCompleteStreamingAsync- Sends a streaming completion requestGetService- Gets a service of the specified typeDispose- Disposes resources
Building the Project
# Clone the repository
git clone https://github.com/elbruno/elbruno-extensions-ai-claude.git
cd elbruno-extensions-ai-claude
# Build the solution
dotnet build
# Run tests
dotnet test
# Pack the NuGet package
dotnet pack src/elbruno.Extensions.AI.Claude/elbruno.Extensions.AI.Claude.csproj
Testing
The project includes unit tests for core functionality. Run them with:
dotnet test
Sample Application
A sample console application is included in the samples directory. To run it:
# Set environment variables
export AZURE_CLAUDE_ENDPOINT="your-endpoint"
export AZURE_CLAUDE_MODEL="claude-sonnet-4-5"
# Run the sample
dotnet run --project samples/elbruno.Extensions.AI.Claude.Samples
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
References
- Microsoft Foundry Documentation
- Deploy and use Claude models in Microsoft Foundry
- Microsoft.Extensions.AI Documentation
- Claude API Documentation
- Azure Identity Library
Support
For issues and questions:
- Open an issue on GitHub
- Contact: El Bruno
Changelog
0.1.0 (Initial Release)
- Initial implementation of AzureClaudeClient
- Support for completions and streaming
- Azure authentication support
- Full IChatClient interface implementation
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.