Hi👋
Great news for .NET developers: Anthropic’s Claude models (Claude Sonnet 4.5, Haiku 4.5, Opus 4.1) are now available in Microsoft Foundry (public preview anthropic.com). This makes Azure the only cloud platform providing access to both OpenAI’s GPT and Anthropic’s Claude frontier models side-by-side (azure.microsoft.com). In practical terms, you can deploy a Claude model to your Microsoft Foundry resource and consume it through Azure’s familiar endpoints and billing system, just like an Azure OpenAI model. With these powerful models (Claude is renowned for advanced reasoning, coding assistance, and long-horizon tasks), Azure developers can build production applications and enterprise-grade AI agents leveraging Claude’s capabilities – all within the Microsoft ecosystem.
Azure Foundry + Anthropic Claude: Quick Intro 🚀
Ok, let’s start > Microsoft Foundry is an Azure service geared towards hosting a variety of AI models (beyond just OpenAI). To start using Claude on Azure, you deploy a Claude model to your Foundry resource via the Azure portal (in Models + Endpoints, choose Deploy model > Anthropic Claude, then select the model like claude-sonnet-4-5). Once deployed, you’ll get an endpoint URL (e.g. https://<your-resource>.services.ai.azure.com/anthropic/v1/messages) and an API key or Azure AD authentication option, similar to other Azure Cognitive Services. Microsoft’s documentation provides a full guide for deploying Claude models in Foundry (learn.microsoft.com) – after deployment you can even test prompts in the Foundry Playground.
This is a “serverless” integration this means you use Azure’s credentials (API key or Entra ID token) to call the Claude Messages API at the Azure endpoint. The integration supports multiple languages – you can call Claude from Python, JavaScript, or C# SDKs with either API key or Azure AD authentication. In C#, this typically involves using either Anthropic’s .NET SDK or Microsoft Extensions for AI (MEAI). Let’s focus on the latter and how to get Claude working with it.
Microsoft.Extensions.AI (MEAI) – Does it Support Claude Yet? 🤔
Microsoft Extensions for AI (MEAI) is a new set of .NET libraries providing unified interfaces (like IChatClient) to interact with AI models (Azure OpenAI, local models, etc.). It’s the backbone for building AI features in .NET apps (and is used in Microsoft’s AI Agent Framework). Ideally, MEAI will eventually support Anthropic’s Claude natively – however, as of now (late 2025) the official MEAI does not yet have built-in support for Claude deployments in Foundry. The issue is that Claude’s API format differs from OpenAI’s, so the current Azure OpenAI clients can’t directly talk to Claude without some tweaks (elbruno.com).
Key differences in the API format (Claude vs OpenAI) include:
- Authentication: OpenAI uses
Authorization: Bearer <key>headers, whereas Claude’s API expects anx-api-key: <key>header (or Azure AD token). - API versioning: Claude requires an
anthropic-versionheader (e.g.anthropic-version: 2023-06-01), whereas OpenAI’s API doesn’t need a version header. - JSON payload: The field for max tokens is named differently (
max_tokensfor Claude vsmax_completion_tokensfor OpenAI), and Claude’s API has a separate top-levelsystemprompt field instead of including system messages in the messages array. Also, Claude doesn’t accept empty messages in the history. - Streaming format: The Server-Sent Events from Claude use different event labels (e.g.
event: content_block_deltawith chunks of text, and a finalevent: message_stopinstead of OpenAI’sdata: [DONE]terminator).
A Claude deployment (Haiku 4.5) in Azure Foundry – note the usage example on the right uses Anthropic’s API style (x-api-key, anthropic-version headers, etc.) differing from the OpenAI API.
Because of these differences, a vanilla Azure OpenAI client (which MEAI uses under the hood) cannot directly call the Claude endpoint – it would send the wrong headers/JSON and get errors. Official support is in progress – Microsoft has indicated that new AI provider connectors (like Anthropic) will be integrated via the MEAI abstractionsgithub.com. In fact, Anthropic has released a C# SDK (NuGet Anthropic package) that implements the IChatClient interface (nuget.orgnuget.org), which suggests that future versions of MEAI may simply require plugging in Anthropic’s client. But until full official support arrives (and while the SDK is maturing), developers have a workaround: use a compatibility shim that converts between OpenAI and Claude formats.
Bridging the Gap – Using Claude via a Custom MEAI Client (Temp Fix)
To get Claude working with MEAI today, we can bridge the format gap. One approach (if you love DIY) is to create a custom DelegatingHandler that intercepts HTTP calls and transforms them on the fly. This handler can swap out headers, adjust JSON payload fields, and convert streaming events from Claude into OpenAI-style chunks. Bruno 👋 (that’s me!) implemented exactly this in a ClaudeToOpenAIMessageHandler class (elbruno.com), and demonstrated how to attach it to an Azure OpenAI client to enable Claude calls. That solution works, but to save everyone time, I went ahead and wrapped it up into a reusable NuGet package: elbruno.Extensions.AI.Claude (v0.1.0-preview.6 at the time of writing).
elbruno.Extensions.AI.Claude – a plug-in Claude Client for MEAI
The elbruno.Extensions.AI.Claude package provides an out-of-the-box AzureClaudeClient that implements MEAI’s IChatClient interface and speaks to Claude behind the scenes. In simpler terms, it’s like a drop-in replacement for AzureOpenAIClient, but pointed at Claude. Some highlights of this library:
- Works with all Claude models in Foundry – Sonnet 4.5, Haiku 4.5, Opus 4.1 – as long as they’re deployed to your Microsoft Foundry resource.
- Implements
IChatClient– so you can use it anywhere in the Microsoft.Extensions.AI pipeline (it behaves just like the clients for OpenAI, Olive, etc.). - Supports Azure AD (Entra ID) or API Key auth – i.e., you can use
DefaultAzureCredentialfor managed identity/CLI login, or provide the Foundry API key directly. - Streaming and Tools – You can stream responses (piece by piece) and even use it with the AI Agent / Tools integration from the new Microsoft Agent Framework (MCP) – under the hood it converts SSE events so streaming just works like OpenAI’s.
It’s essentially the “glue” so you don’t have to manually transform requests. Important: This is a preview/temporary solution meant for learning and prototyping. For production, wait for official support (and official SDKs) to ensure reliability and maintenance. Now, let’s see how to use this package in your C# project.
Installation
First, install the NuGet package (preview version):
dotnet add package elbruno.Extensions.AI.Claude --version 0.1.0-preview.6
This will pull in the library and the necessary Microsoft.Extensions.AI abstractions.
1. Using Default Azure Credentials (Managed Identity)
If your app is running in Azure (or you have Azure CLI/VS credentials locally), you can use DefaultAzureCredential to authenticate to Foundry (keyless access via Entra ID). This avoids handling API keys directly. For example:
using Azure.Identity;
using elbruno.Extensions.AI.Claude;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.AI.OpenAI; // for ChatMessage/ChatRole types
// Assume these are set as environment vars or user-secrets:
var endpointUri = new Uri(Environment.GetEnvironmentVariable("AZURE_CLAUDE_ENDPOINT")!);
// e.g. "https://<your-foundry-resource>.services.ai.azure.com/anthropic/v1/messages"
var deploymentName = Environment.GetEnvironmentVariable("AZURE_CLAUDE_MODEL") ?? "claude-haiku-4-5";
// Create a Claude client using DefaultAzureCredential (Entra ID auth)
IChatClient chatClient = new AzureClaudeClient(endpointUri, deploymentName, new DefaultAzureCredential());
// Send a chat prompt to Claude
var conversation = new List<ChatMessage>
{
new(ChatRole.System, "Respond in bullet points."), // system instruction
new(ChatRole.User, "Give me two shipping ideas for a Claude-powered agent.") // user prompt
};
ChatResponse reply = await chatClient.CompleteAsync(conversation);
// Print the assistant's reply
Console.WriteLine(reply.Message.Text);
In the above snippet, we instantiate AzureClaudeClient with the Foundry endpoint, the deployment name (model), and a credential. The client seamlessly handles constructing the proper request to Claude. We then use it like any other chat client – build a message list (note: we included a system message example), and call CompleteAsync to get a response. The result (ChatResponse) contains an Assistant message (with Text) that we can output. Behind the scenes, the library added the required x-api-key/anthropic-version headers and formatted our messages for Claude, so we didn’t have to worry about those details.
Configuration: Make sure you set the environment variables or configuration for AZURE_CLAUDE_ENDPOINT (your Foundry messages endpoint URL) and AZURE_CLAUDE_MODEL (your deployment name, e.g. "claude-haiku-4-5"). If using DefaultAzureCredential, ensure your identity has access to the Foundry resource. Alternatively, you can supply a specific TokenCredential (like a ClientSecretCredential or ManagedIdentityCredential) if needed.
2. Using API Key Authentication
For scenarios like local development or if you haven’t set up Azure AD auth, you can use the Foundry API key. When you deploy a model in Foundry, Azure will generate an API key (similar to Azure OpenAI keys) that you can use for auth. Using the API key is as simple as providing the key string to the AzureClaudeClient constructor. For example:
using elbruno.Extensions.AI.Claude;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.AI.OpenAI;
var config = new ConfigurationBuilder()
.AddUserSecrets<Program>() // or appsettings, etc.
.AddEnvironmentVariables()
.Build();
var endpointUri = new Uri(config["AZURE_CLAUDE_ENDPOINT"]!);
var deploymentName = config["AZURE_CLAUDE_MODEL"] ?? "claude-sonnet-4-5";
var apiKey = config["AZURE_CLAUDE_APIKEY"]!; // Foundry API key for your deployment
IChatClient chatClient = new AzureClaudeClient(endpointUri, deploymentName, apiKey);
// Example: stream the response from Claude
var prompt = new List<ChatMessage>
{
new(ChatRole.System, "Keep outputs under 30 words."),
new(ChatRole.User, "Pitch a 1-line elevator speech for this integration.")
};
await foreach (ChatMessageChunk chunk in chatClient.CompleteStreamingAsync(prompt))
{
if (!string.IsNullOrEmpty(chunk.Text))
Console.Write(chunk.Text); // print partial chunks as they stream in
}
Console.WriteLine("\n(done)");
Here we configure the client with the endpoint, model name, and API key. We then demonstrate streaming usage with CompleteStreamingAsync – this returns an IAsyncEnumerable<ChatMessageChunk> that we can iterate over. As Claude generates the answer, chunks will arrive (the library transforms Claude’s SSE into nice ChatMessageChunk objects). We print out chunk.Text as they come, resulting in a streaming response in the console. Finally, we add a newline when done. Streaming is super useful for responsive UIs or long responses, and thanks to the MEAI abstraction, it works identically to streaming from OpenAI models.
Note: When using API key mode, be sure to store your key securely (e.g., user-secrets, Azure Key Vault, environment variable) and never hard-code it. The above code assumes you’ve stored the key in a config source and retrieved it.
That’s it! With just a few lines, we have Claude responding to our .NET app. The AzureClaudeClient can be used anywhere you would use an IChatClient – meaning you can integrate Claude into ASP.NET minimal APIs, WPF apps, or even replace GPT in an existing app with minimal changes.
Claude + .NET Agent Framework (Bonus 🌟)
One of the exciting possibilities of having Claude in Azure is using it for AI Agents. Microsoft’s new Agent Framework (part of the Foundry Agent Service) allows developers to create goal-driven agents that can plan steps and use tools (via the Model Context Protocol) to interact with external systems. Claude’s models are particularly strong in reasoning and following instructions, making them ideal as the “brain” of such agents. In fact, inside Foundry’s Agent Service, Claude models serve as the reasoning core for complex, multi-step workflows.
The good news: because our AzureClaudeClient implements IChatClient, you can plug Claude into the .NET Agent Framework just like any other model. This means you could have an agent that uses Claude for planning and also uses Tools (e.g., web search, calculator) through the MCP interface – all running in C#. The MEAI abstraction makes this swap easy. (If you try this out, let me know – I’d love to see Claude-powered agents in action! 🤖)
Bonus: check out this 4-minute video overview of the elbruno.Extensions.AI.Claude package and how it works. 🎥
Final Thoughts
Anthropic Claude’s arrival on Azure opens up a whole new range of possibilities for .NET developers. You can now choose between GPT-4, Claude, and other models in one unified platform, selecting the best model for each task. In this post, we saw how to get started with Claude using C# – from deployment in Foundry to calling it via a custom client library. We also discussed the current limitations (no official support yet in MEAI) and how our temporary fix bridges the gap. As always, treat this workaround as an educational solution. Official support for Claude in the .NET ecosystem is on the horizon – so keep an eye on the Microsoft.Extensions.AI library and Azure updates. In the meantime, have fun experimenting with Claude in your .NET projects! With minimal code, you can tap into Claude’s powerful reasoning and get creative – whether it’s building smart chatbots, coding assistants, or multi-step AI agents.
Happy coding! 👋
References and Resources
- Anthropic Claude on Azure – Anthropic announcement: “Claude Sonnet 4.5, Haiku 4.5, and Opus 4.1 models are now available in public preview in Microsoft Foundry.”anthropic.com; Azure blog: Anthropic partnership brings Claude models to Azure (Foundry) azure.microsoft.com.
- Deploying Claude in Foundry – Microsoft Learn: Deploy and use Claude models in Microsoft Foundry (preview) learn.microsoft.com (guidance on setting up Foundry resource and deploying models).
- Microsoft Extensions.AI (MEAI) – .NET library providing
IChatClientabstraction elbruno.com and integration for AI models (docs: elbruno.com). Currently works with Azure OpenAI; Anthropic support is work-in-progress. - API Differences (OpenAI vs Claude) – Key format differences are summarized (auth header, version, JSON fields, streaming events) elbruno.com. These differences necessitate transformation when using Claude with existing clients.
- Custom Claude Integration – El Bruno blog: Using Claude Models in Foundry with MEAI (temp fix) – explains the
ClaudeToOpenAIMessageHandlerapproach elbruno.com and provides a full sample bridging Claude to MEAI. - elbruno.Extensions.AI.Claude – NuGet package [elbruno.Extensions.AI.Claude 0.1.0-preview.6][7] (GitHub: Bruno’s repo) implementing an
AzureClaudeClient(supports IChatClient, DefaultAzureCredential, API keys, streaming, etc.)elbruno.comelbruno.com. This is a temporary client to use Claude in .NET until official SDK integration arrives. - Foundry Agent Service – Microsoft Foundry’s agent orchestration supports Claude models as reasoning engines azure.microsoft.com, enabling advanced agent scenarios (multi-step workflows, tool use via MCP). Great for future exploration with the .NET Agent Framework!
Happy coding!
Greetings
El Bruno
More posts in my blog ElBruno.com.
More info in https://beacons.ai/elbruno

Leave a comment