- π Full walkthrough: MAI-Thinking-1 Is Now in Foundry β Hereβs What It Means If You Write C#
- β If this sample helps you, star the repo so other .NET developers can find it.
- π Related: MAI-Image-2.5-Pro C# Sample and MAI-Voice-2 Flash C# Samples
- For more C# samples using other AI models, see AI models for C# developers
- For my free ebook on prompt engineering, see Prompt Engineering for .NET Developers
A minimal .NET 10 console sample for MAI-Thinking-1, Microsoft's reasoning model on Microsoft Foundry. It calls the model's Azure OpenAI endpoint through the Microsoft.Extensions.AI IChatClient abstraction, authenticated with DefaultAzureCredential. It includes two independent samples:
- Program.cs β the main project. Sends a contract excerpt to the model for step-by-step risk analysis using
IChatClient. - FunctionSample.cs β a standalone, file-based app (no project needed) that also uses
IChatClientand demonstrates automatic tool/function calling (GetTicketStatus) viaUseFunctionInvocation().
git clone https://github.com/taswar/MaiThinkingDemo.git
cd MaiThinkingDemo
dotnet user-secrets set "AZURE_AI_ENDPOINT" "https://<your-resource>.openai.azure.com/"
az login
dotnet run- .NET 10 SDK
- An Azure OpenAI or Microsoft Foundry resource with a MAI-Thinking-1 deployment
- Azure credentials available to
DefaultAzureCredential(e.g. runaz login, or use a Managed Identity / environment variables β see DefaultAzureCredential docs)
Both samples read the same two settings:
| Setting | Description | Default |
|---|---|---|
AZURE_AI_ENDPOINT |
Your Azure OpenAI endpoint URL (required) | β |
AZURE_OPENAI_DEPLOYMENT |
The chat model deployment name | mai-thinking-1 |
Configuration is loaded from user secrets first, then environment variables.
Set the endpoint via user secrets (recommended for local dev):
dotnet user-secrets set "AZURE_AI_ENDPOINT" "https://<your-resource>.openai.azure.com/"
dotnet user-secrets set "AZURE_OPENAI_DEPLOYMENT" "<your-deployment-name>"Or via environment variables:
$env:AZURE_AI_ENDPOINT = "https://<your-resource>.openai.azure.com/"
$env:AZURE_OPENAI_DEPLOYMENT = "<your-deployment-name>"From the repository root:
dotnet runThis builds and runs the MaiThinkingDemo project, which only compiles Program.cs (FunctionSample.cs is excluded from the project via <Compile Remove="FunctionSample.cs" /> in MaiThinkingDemo.csproj).
FunctionSample.cs is a .NET 10 file-based app β it declares its own NuGet package references via #:package directives at the top of the file, so it can run independently of the .csproj.
Because a .csproj also exists in this directory, you must pass --file explicitly so dotnet run treats it as a file-based app instead of an argument to the project:
dotnet run --file FunctionSample.csThis demonstrates giving the model a callable tool (GetTicketStatus) via Microsoft.Extensions.AI's IChatClient, with UseFunctionInvocation() enabling automatic tool-call-and-continue behavior.
Note:
dotnet build FunctionSample.csordotnet run FunctionSample.cs(without--file) will not work as expected here β the first ignores the file's#:packagedirectives, and the second gets treated as a command-line argument to the project instead of the file itself.
The main project (MaiThinkingDemo.csproj) references:
| Package | Version | Purpose |
|---|---|---|
Azure.AI.OpenAI |
2.9.0-beta.1 |
Azure OpenAI client (AzureOpenAIClient, GetChatClient) |
Azure.Identity |
1.21.0 |
DefaultAzureCredential authentication |
Microsoft.Extensions.AI |
10.9.0 |
IChatClient, ChatMessage, ChatOptions, AIFunctionFactory abstractions |
Microsoft.Extensions.AI.OpenAI |
10.3.0 |
AsIChatClient() extension for the OpenAI ChatClient |
Microsoft.Extensions.Configuration |
10.0.0 |
Configuration builder |
Microsoft.Extensions.Configuration.EnvironmentVariables |
10.0.0 |
Environment variable configuration source |
Microsoft.Extensions.Configuration.UserSecrets |
10.0.0 |
User secrets configuration source |
Microsoft.Extensions.AI.AzureAIInferenceis also present in the.csprojbut is not currently used by either sample.
Restore them with:
dotnet restoreFunctionSample.cs declares the same packages itself via #:package directives at the top of the file (see Running the standalone sample), so it resolves its own dependencies when run with --file and does not need dotnet restore run against it separately.
Azure.AI.OpenAI@2.1.0 (the latest stable release) is compiled against OpenAI@2.1.0 and breaks at runtime (MissingMethodException) if a newer transitive OpenAI package version is resolved β which happens when Microsoft.Extensions.AI.OpenAI pulls in a newer OpenAI version. Use Azure.AI.OpenAI@2.9.0-beta.1 (or newer versions verified compatible with your Microsoft.Extensions.AI.OpenAI version) to avoid this.
Program.cs # Main project entry point (contract risk analysis)
FunctionSample.cs # Standalone file-based app (IChatClient + tool calling)
MaiThinkingDemo.csproj
CONTRIBUTING.md # How to contribute
.github/workflows/dotnet.yml # Build workflow
LICENSE # MIT license
This project is licensed under the MIT License. See LICENSE.
