awaitforeach(varupdateinchatClient.GetStreamingResponseAsync("Count from 1 to 10.",newChatOptions{ModelId="gpt-4o-mini"})){Console.Write(string.Concat(update.Contents.OfType<TextContent>().Select(c=>c.Text)));}
System Messages
123456789
varmessages=newList<ChatMessage>{new(ChatRole.System,"You are a pirate. Always respond with 'Arrr!'."),new(ChatRole.User,"Hello!"),};varresponse=awaitchatClient.GetResponseAsync(messages,newChatOptions{ModelId="gpt-4o-mini"});
Tool Calling
1 2 3 4 5 6 7 8 91011121314151617
varweatherTool=AIFunctionFactory.Create((stringcity)=>cityswitch{"Paris"=>"22C, sunny","London"=>"15C, cloudy",_=>"Unknown",},name:"GetWeather",description:"Gets the current weather for a city");varresponse=awaitchatClient.GetResponseAsync("What's the weather in Paris?",newChatOptions{ModelId="gpt-4o-mini",Tools=[weatherTool],});
Structured Output (JSON Schema)
1 2 3 4 5 6 7 8 910111213141516171819
varschema=System.Text.Json.JsonDocument.Parse("""{"type":"object","properties":{"name":{"type":"string"},"age":{"type":"integer"}},"required":["name","age"],"additionalProperties":false}""").RootElement;varresponse=awaitchatClient.GetResponseAsync("Return info about Alice who is 30.",newChatOptions{ModelId="gpt-4o-mini",ResponseFormat=newChatResponseFormatJson(schema,"person","A person object"),});
Image Content
123456789
varmessage=newChatMessage(ChatRole.User,[]);message.Contents.Add(newTextContent("What is in this image?"));message.Contents.Add(newUriContent(newUri("https://example.com/photo.png"),mediaType:"image/png"));varresponse=awaitchatClient.GetResponseAsync([message],newChatOptions{ModelId="gpt-4o-mini"});
Temperature, TopP, and Stop Sequences
123456789
varresponse=awaitchatClient.GetResponseAsync("What is 2+2?",newChatOptions{ModelId="gpt-4o-mini",Temperature=0f,TopP=1f,StopSequences=["5"],});
Additional Properties
Pass provider-specific parameters via AdditionalProperties:
All 15+ custom providers support the same MEAI interfaces:
1 2 3 4 5 6 7 8 9101112131415
usingOpenAI;usingMicrosoft.Extensions.AI;// Any CustomProvider works as IChatClient and IEmbeddingGeneratorusingvarclient=CustomProviders.Groq("API_KEY");// or: CustomProviders.DeepInfra("API_KEY")// or: CustomProviders.Together("API_KEY")// or: CustomProviders.Azure("API_KEY", "ENDPOINT")// or: CustomProviders.DeepSeek("API_KEY")// or: any other CustomProviderIChatClientchatClient=client;varresponse=awaitchatClient.GetResponseAsync("Hello!",newChatOptions{ModelId="llama-3.3-70b-versatile"});