Blog Post

Azure AI Foundry Blog
3 MIN READ

Building AI Apps with the Foundry Local C# SDK

samkemp's avatar
samkemp
Icon for Microsoft rankMicrosoft
Sep 17, 2025

With the release of the Foundry Local C# SDK, .NET developers now have a powerful tool to integrate local AI into their applications.

What Is Foundry Local?

Foundry Local is a lightweight runtime designed to run AI models directly on user devices. It supports a wide range of hardware (CPU, GPU, NPU) and provides a consistent developer experience across platforms. The SDKs are available in multiple languages, including Python, JavaScript, Rust, and now C#.

Why a C# SDK?

The C# SDK brings Foundry Local into the heart of the .NET ecosystem. It allows developers to:

  • Download and manage models locally.
  • Run inference using OpenAI-compatible APIs.
  • Integrate seamlessly with existing .NET applications.

This means you can build intelligent apps that run offline, reduce latency, and maintain data privacy—all without sacrificing developer productivity.

Bootstrap Process: How the SDK Gets You Started

One of the most developer-friendly aspects of the C# SDK is its automatic bootstrap process. Here's what happens under the hood when you initialise the SDK:

  1. Service Discovery and Startup The SDK automatically locates the Foundry Local installation on the device and starts the inference service if it's not already running.
  2. Model Download and Caching If the specified model isn't already cached locally, the SDK will download the most performant model variant (e.g. GPU, CPU, NPU) for the end user's hardware from the Foundry model catalog. This ensures you're always working with the latest optimised version.
  3. Model Loading into Inference Service Once downloaded (or retrieved from cache), the model is loaded into the Foundry Local inference engine, ready to serve requests.

This streamlined process means developers can go from zero to inference with just a few lines of code—no manual setup or configuration required.

Leverage Your Existing AI Stack

One of the most exciting aspects of the Foundry Local C# SDK is its compatibility with popular AI tools such as:

  • OpenAI SDK - Foundry local provides an OpenAI compliant chat completions (and embedding) API meaning. If you’re already using `OpenAI` chat completions API, you can reuse your existing code with minimal changes.
  • Semantic Kernel - Foundry Local also integrates well with Semantic Kernel, Microsoft’s open-source framework for building AI agents. You can use Foundry Local models as plugins or endpoints within Semantic Kernel workflows—enabling advanced capabilities like memory, planning, and tool calling.

Quick Start Example

Follow these three steps:

1. Create a new project

Create a new C# project and navigate to it:

dotnet new console -n hello-foundry-local cd hello-foundry-local

2. Install NuGet packages

Install the following NuGet packages into your project:

dotnet add package Microsoft.AI.Foundry.Local --version 0.1.0 dotnet add package OpenAI --version 2.2.0-beta.4

3. Use the OpenAI SDK with Foundry Local

The following example demonstrates how to use the OpenAI SDK with Foundry Local. The code initializes the Foundry Local service, loads a model, and generates a response using the OpenAI SDK.

Copy-and-paste the following code into a C# file named Program.cs:

using Microsoft.AI.Foundry.Local; using OpenAI; using OpenAI.Chat; using System.ClientModel; using System.Diagnostics.Metrics; var alias = "phi-3.5-mini"; var manager = await FoundryLocalManager.StartModelAsync(aliasOrModelId: alias); var model = await manager.GetModelInfoAsync(aliasOrModelId: alias); ApiKeyCredential key = new ApiKeyCredential(manager.ApiKey); OpenAIClient client = new OpenAIClient(key, new OpenAIClientOptions { Endpoint = manager.Endpoint }); var chatClient = client.GetChatClient(model?.ModelId); var completionUpdates = chatClient.CompleteChatStreaming("Why is the sky blue'"); Console.Write($"[ASSISTANT]: "); foreach (var completionUpdate in completionUpdates) { if (completionUpdate.ContentUpdate.Count > 0) { Console.Write(completionUpdate.ContentUpdate[0].Text); } }

Run the code using the following command:

dotnet run

Final thoughts

The Foundry Local C# SDK empowers developers to build intelligent, privacy-preserving applications that run anywhere. Whether you're working on desktop, mobile, or embedded systems, this SDK offers a robust and flexible way to bring AI closer to your users.

Ready to get started? Dive into the official documentation:

You can also make contributions to the C# SDK by creating a PR on GitHub:

Updated Sep 18, 2025
Version 3.0
No CommentsBe the first to comment