# Manage Multiple Chat Clients | WPF Controls | DevExpress Documentation

The [WPF AI Chat Control](/WPF/405434/ai-powered-extensions/ai-chat-control) supports multiple AI services in a single application, which enables you to compare AI providers, separate conversation contexts, and provide specialized AI assistants for different user tasks.

## Register Multiple AI Services

Register multiple AI services/service providers and associate them with unique keys.

```
using Azure.AI.OpenAI;
using DevExpress.AIIntegration;
using DevExpress.AIIntegration.Chat;
using DevExpress.Xpf.Core;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.DependencyInjection;
using OllamaSharp;
using System;
using System.ClientModel;
using System.Windows;

namespace DXWPFMultipleChatClients {
    public partial class App : Application {
        static App() {
            CompatibilitySettings.UseLightweightThemes = true;

            // Create an Azure OpenAI chat client
            var azureOpenAiClient = new AzureOpenAIClient(AzureOpenAIEndpoint, AzureOpenAIKey)
                .GetChatClient(ModelId)
                .AsIChatClient();

            // Create an Ollama API client.
            IChatClient ollamaClient = new OllamaApiClient(
                new Uri("http://localhost:11434/"),
                "gemma3:4b"
            );

            // Create a service collection to register AI chat clients.
            var serviceCollection = new ServiceCollection();

            // Register a keyed IChatResponseProvider for Azure OpenAI.
            // This provider is resolved when "azureAiProviderServiceKey" is specified.
            serviceCollection.AddKeyedScoped<IChatResponseProvider>(
                "azureAiProviderServiceKey",
                (serviceProvider, _) => azureOpenAiClient.AsIChatResponseProvider()
            );

            // Register the Azure OpenAI chat client as a keyed IChatClient.
            serviceCollection.AddKeyedScoped<IChatClient>(
                "azureAiClient",
                (serviceProvider, _) => azureOpenAiClient
            );

            // Register a keyed IChatResponseProvider for the Ollama client.
            // This provider is resolved when "ollamaAiProviderServiceKey" is specified.
            serviceCollection.AddKeyedScoped<IChatResponseProvider>(
                "ollamaAiProviderServiceKey",
                (serviceProvider, _) => ollamaClient.AsIChatResponseProvider()
            );

            // Register the Ollama chat client as a keyed IChatClient.
            serviceCollection.AddKeyedScoped<IChatClient>(
                "ollamaAiClient",
                (serviceProvider, _) => ollamaClient
            );

            // Register a default (non-keyed) IChatResponseProvider.
            // This provider is used when no ChatResponseProviderServiceKey is specified.
            serviceCollection.AddScoped<IChatResponseProvider>(
                (serviceProvider) => azureOpenAiClient.AsIChatResponseProvider()
            );

            // Add DevExpress AI Desktop services (required for AIChatControl).
            serviceCollection.AddDevExpressAIDesktop();
        }

        private static Uri AzureOpenAIEndpoint = new Uri("YOUR_AZURE_END_POINT");
        private static ApiKeyCredential AzureOpenAIKey = new ApiKeyCredential("YOUR_OPENAI_API_KEY");
        static string ModelId = "MODEL_NAME";   // For example, gpt-4o-mini
    }
}
```

## Run Independent AI Chats Side by Side

Place multiple `AIChatControl` instances within a window and specify a different [ChatResponseProviderServiceKey](/WPF/DevExpress.AIIntegration.Wpf.Chat.AIChatControl.ChatResponseProviderServiceKey) for each chat control to use to interact with different AI services.

- XAML

<section id="tabpanel_VtIFVwl3-K_tabid-xaml" role="tabpanel" data-tab="tabid-xaml">
<pre><code data-highlight-lines="[[6],[15],[22]]" class="lang-xaml">&lt;dx:ThemedWindow 
    x:Class=&quot;DXWPFMultipleChatClients.MainWindow&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:dx=&quot;http://schemas.devexpress.com/winfx/2008/xaml/core&quot;
    xmlns:dxaichat=&quot;http://schemas.devexpress.com/winfx/2008/xaml/aichat&quot;
    Title=&quot;MainWindow&quot; Height=&quot;800&quot; Width=&quot;1000&quot;&gt;
    &lt;Grid&gt;
        &lt;Grid.ColumnDefinitions&gt;
            &lt;ColumnDefinition Width=&quot;*&quot;/&gt;
            &lt;ColumnDefinition Width=&quot;*&quot;/&gt;
        &lt;/Grid.ColumnDefinitions&gt;
        &lt;dxaichat:AIChatControl
            x:Name=&quot;azureChat&quot;
            ChatResponseProviderServiceKey=&quot;azureAiProviderServiceKey&quot;
            HorizontalAlignment=&quot;Stretch&quot; 
            VerticalAlignment=&quot;Stretch&quot; 
            Margin=&quot;10&quot;/&gt;

        &lt;dxaichat:AIChatControl
            x:Name=&quot;ollamaChat&quot;
            ChatResponseProviderServiceKey=&quot;ollamaAiProviderServiceKey&quot;
            HorizontalAlignment=&quot;Stretch&quot; 
            VerticalAlignment=&quot;Stretch&quot; 
            Margin=&quot;10&quot;
            Grid.Column=&quot;1&quot;/&gt;   
    &lt;/Grid&gt;
&lt;/dx:ThemedWindow&gt;
</code></pre></section>

The following animation illustrates the result:

![Manage Multiple Chat Clients - WPF AI Chat Control, DevExpress](/WPF/images/manage-multiple-chat-clients.gif)

## Switch Between AI Services or AI Agents

Use a single `AIChatControl` and modify its [ChatResponseProviderServiceKey](/WPF/DevExpress.AIIntegration.Wpf.Chat.AIChatControl.ChatResponseProviderServiceKey) property to switch between AI services or AI agents.

## Troubleshooting

### The IChatResponseProvider service is not registered

Add `IChatResponseProvider` to the service collection at application startup:

```
// Create an Azure OpenAI chat client
var azureOpenAiClient = new AzureOpenAIClient(AzureOpenAIEndpoint, AzureOpenAIKey)
    .GetChatClient(ModelId)
    .AsIChatClient();
// Register a keyed IChatResponseProvider.
serviceCollection.AddKeyedScoped<IChatResponseProvider>(
    "azureAiProviderServiceKey",
    (serviceProvider, _) => azureOpenAiClient.AsIChatResponseProvider()
);
// Register the Azure OpenAI chat client as a keyed IChatClient.
serviceCollection.AddKeyedScoped<IChatClient>(
    "azureAiClient",
    (serviceProvider, _) => azureOpenAiClient
);
```

### There is no registered service of type Microsoft.Extensions.AI.IChatClient

This error occurs when the `AIChatControl` cannot find a registered chat client that matches its configuration.

Do one of the following:

- Check ChatResponseProviderServiceKey

    - Ensure that the [AIChatControl.ChatResponseProviderServiceKey](/WPF/DevExpress.AIIntegration.Wpf.Chat.AIChatControl.ChatResponseProviderServiceKey) property matches the key of one of the chat client providers you registered in the service collection.

- Register a Default Chat Client

    - If you do not assign a [ChatResponseProviderServiceKey](/WPF/DevExpress.AIIntegration.Wpf.Chat.AIChatControl.ChatResponseProviderServiceKey) to the chat control, register a default chat client in the desktop container to ensure that the chat control can automatically resolve the AI service:

```
AIExtensionsContainerDesktop.Default.RegisterChatClient(chatClient);
```

See the following help topic for more information: [Register AI Client](/WindowsForms/405218/ai-powered-extensions/ai-chat-control#register-ai-client).

See Also

[AI Chat Control](/WPF/405434/ai-powered-extensions/ai-chat-control)