This SDK has a generated IChatClient interface that conflicts with Microsoft.Extensions.AI.IChatClient. Use the Meai alias pattern shown below.
Supported Interfaces
Interface
Support Level
IChatClient
Full (text, streaming, tool calling, images)
IChatClient
Installation
1
dotnetaddpackagetryAGI.Mistral
Basic Usage
Because the SDK generates its own IChatClient interface, you must use a namespace alias to reference the MEAI interface explicitly:
1 2 3 4 5 6 7 8 91011121314
usingMistral;usingMeai=Microsoft.Extensions.AI;usingvarclient=newMistralClient(apiKey);Meai.IChatClientchatClient=client;varresponse=awaitchatClient.GetResponseAsync("What is the capital of France?",newMeai.ChatOptions{ModelId="mistral-large-latest",});Console.WriteLine(response.Text);
Streaming
1 2 3 4 5 6 7 8 910111213
usingMeai=Microsoft.Extensions.AI;Meai.IChatClientchatClient=client;awaitforeach(varupdateinchatClient.GetStreamingResponseAsync("Write a short poem about coding.",newMeai.ChatOptions{ModelId="mistral-large-latest",})){Console.Write(update.Text);}
Tool Calling
1 2 3 4 5 6 7 8 9101112131415161718192021
usingCSharpToJsonSchema;usingMeai=Microsoft.Extensions.AI;[GenerateJsonSchema]publicinterfaceIWeatherTools{[Description("Gets the current weather for a location.")]stringGetWeather([Description("The city name")]stringcity);}Meai.IChatClientchatClient=client;varservice=newWeatherToolsService();varresponse=awaitchatClient.GetResponseAsync("What's the weather in Paris?",newMeai.ChatOptions{ModelId="mistral-large-latest",Tools=service.AsTools().AsAITools(),});
Image Input
1 2 3 4 5 6 7 8 910111213141516
usingMeai=Microsoft.Extensions.AI;Meai.IChatClientchatClient=client;varresponse=awaitchatClient.GetResponseAsync([ new Meai.ChatMessage(Meai.ChatRole.User, [ new Meai.ImageContent(imageBytes, "image/png"), new Meai.TextContent("Describe this image."), ]),],newMeai.ChatOptions{ModelId="mistral-large-latest",});
Accessing Client Metadata
When using the Meai alias, call extension methods explicitly: