Call AddChatClient with a provider name that matches your local model catalog. The demo needs no API key.
dotnet add package RecursiveAI.OneLlm.Extensions.AIRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using Microsoft.Extensions.AI; using OneLlm; using OneLlm.Catalog; using OneLlm.Extensions.AI; using OneLlm.Testing; using IChatClient client = DemoClient(); var runtime = new Runtime { Catalog = LocalCatalog() }; runtime.Providers.AddChatClient( "local", client); var reply = await runtime.AskAsync( new AskRequest { Model = "demo-chat", Prompt = "Status?" }); Console.WriteLine( $"{reply.Model}: {reply.Text}"); static IChatClient DemoClient() { var script = new ScriptedProvider(); script.EnqueueText("Ready."); return new OneLlmChatClient( script, "demo-chat", TimeProvider.System); } static ModelCatalog LocalCatalog() { var layer = CatalogLayer.FromYaml( CatalogLayer.User, """ name: local models: - name: demo-chat contextWindow: 4096 """); return ModelCatalog.Create([layer]); }
Paste the code above into Program.cs of a new dotnet new console project and dotnet run, or unzip the example and dotnet run.
The Extensions.AI package brings in the IChatClient interface and RecursiveAI.OneLlm, which ships ScriptedProvider in the OneLlm.Testing namespace.
local:demo-chat: Ready.Replace DemoClient() with your own configured client. If the model doesn’t resolve in the catalog, OneLLM throws ModelNotFoundException before calling the chat client.
Variations
Qualify the model with the provider name. Change the model in the request to select local explicitly. Keep the name: demo-chat entry unchanged:
var reply = await runtime.AskAsync(new AskRequest { Model = "local:demo-chat", Prompt = "Status?" }); Console.WriteLine($"{reply.Model}: {reply.Text}");
local:demo-chat: Ready.Related recipes
The short answer
Install the OneLLM Extensions.AI bridge and call runtime.Providers.AddChatClient("local", client). Define the model under name: local in the runtime’s catalog, then ask for that model through runtime.AskAsync. The example prints local:demo-chat before the reply so you can see which model route it used.
How do you use an IChatClient as a provider in .NET?
Use the client you already configured in your application. IChatClient is the Microsoft.Extensions.AI chat interface; the OneLLM bridge translates the prompt and options into a client request and returns the resulting message as a OneLLM answer. The demo uses a OneLlmChatClient with a scripted response only to supply a working IChatClient with no service. Your client doesn’t need a scripted provider or a OneLLM client wrapper.
Register at setup, not once per chat turn. AddChatClient doesn’t take ownership of the client, so keep the client alive while the runtime needs it and let your application dispose of it. If you already have an embedding generator, you can pass it separately; a chat client alone doesn’t supply embeddings. See using a client as a provider.
How does OneLLM find the model for an existing chat client?
The catalog and the registry do different jobs. The catalog resolves demo-chat to the provider called local; it also records information such as the context window. The registry maps local to the client you passed to AddChatClient. Registering a client by itself doesn’t add models to the catalog or query the underlying service for a list. Use the model name your configured client understands, and if two providers advertise the same name, qualify it as provider:model to choose one explicitly.