The elmah.io blog walks through Microsoft.Extensions.AI step by step: an IChatClient console chatbot with streaming, typed structured output and 429 rate-limit handling. A practical starting point if you want a provider-agnostic abstraction in .NET.
Key points
- IChatClient is presented as the common abstraction that keeps conversation logic stable across providers.
- The OpenAI SDK client is adapted to Microsoft.Extensions.AI through the AsIChatClient() extension.
- GetStreamingResponseAsync() delivers token updates incrementally, appended to a StringBuilder and the history.
- GetResponseAsync<T>() returns typed results for a record and enum, read back with TryGetResult().
- A ClientResultException with status 429 is caught separately to show a friendly rate-limit message.
- Groq's OpenAI-compatible endpoint is configured through appsettings.json with model, endpoint and API key.
Real-world use
- A console chatbot demo running against a free-tier model
- A structured analysis command that extracts sentiment, summary and keywords from customer reviews
- A chat feature inside a web app or API that stays provider-agnostic
This summary was generated by the agent from the original post on elmah.io Blog. The full text and all rights belong to its author and publisher. Go to original