The power of MEAI is that this code works identically across all providers:
1 2 3 4 5 6 7 8 910111213
usingMicrosoft.Extensions.AI;IChatClientclient=/* any provider */;// Simple text completionvarresponse=awaitclient.GetResponseAsync("Explain quantum computing briefly.");Console.WriteLine(response);// Streamingawaitforeach(varupdateinclient.GetStreamingResponseAsync("Tell me a story.")){Console.Write(update.Text);}
// Note: namespace conflict — use Meai aliasusingMeai=Microsoft.Extensions.AI;Meai.IChatClientclient=newMistralClient(apiKey).AsChatClient("mistral-large-latest");
Tool calling
All IChatClient implementations support function/tool calling via MEAI's AIFunction abstraction:
1 2 3 4 5 6 7 8 91011121314151617
usingMicrosoft.Extensions.AI;// Define tools using CSharpToJsonSchema[GenerateJsonSchema]publicinterfaceIMyTools{[Description("Gets the current weather for a location")]stringGetWeather(stringcity);}// Use with any IChatClientvartools=newMyToolsService().AsTools();varoptions=newChatOptions{Tools=tools};varresponse=awaitclient.GetResponseAsync("What's the weather in Tokyo?",options);
Per-SDK documentation
Each SDK has a detailed MEAI guide with provider-specific examples: