# Custom Providers

Providers are plugins that connect Umbraco.AI to AI services. Create a custom provider to add support for AI services not included out of the box.

## Provider Architecture

A provider consists of:

1. **Provider class** - Main class with `[AIProvider]` attribute
2. **Settings class** - Configuration properties with `[AIField]` attributes
3. **Capability classes** - Implementations for Chat, Embedding, and so on

```
MyProvider/
├── MyProvider.cs              # Main provider class
├── MyProviderSettings.cs      # Settings with [AIField] attributes
├── MyChatCapability.cs        # Chat capability implementation
└── MyEmbeddingCapability.cs   # Embedding capability (optional)
```

## Quick Start

### 1. Create a Settings Class

{% code title="MyProviderSettings.cs" %}

```csharp
using Umbraco.AI.Core.EditableModels;

public class MyProviderSettings
{
    [AIField(Label = "API Key", Description = "Your API key", IsSensitive = true)]
    public string? ApiKey { get; set; }

    [AIField(Label = "Endpoint", Description = "API endpoint URL")]
    public string? Endpoint { get; set; }
}
```

{% endcode %}

### 2. Create a Chat Capability

{% code title="MyChatCapability.cs" %}

```csharp
using Microsoft.Extensions.AI;
using Umbraco.AI.Core.Models;
using Umbraco.AI.Core.Providers;

public class MyChatCapability : AIChatCapabilityBase<MyProviderSettings>
{
    public MyChatCapability(IAIProvider provider) : base(provider) { }

    protected override IChatClient CreateClient(MyProviderSettings settings, string? modelId)
    {
        // Create and return your IChatClient implementation
        return new MyChatClient(settings.ApiKey, settings.Endpoint, modelId);
    }

    protected override Task<IReadOnlyList<AIModelDescriptor>> GetModelsAsync(
        MyProviderSettings settings,
        CancellationToken cancellationToken = default)
    {
        // Return available models
        var models = new List<AIModelDescriptor>
        {
            new(new AIModelRef(Provider.Id, "my-model-1"), "My Model 1"),
            new(new AIModelRef(Provider.Id, "my-model-2"), "My Model 2")
        };
        return Task.FromResult<IReadOnlyList<AIModelDescriptor>>(models);
    }
}
```

{% endcode %}

### 3. Create the Provider Class

{% code title="MyProvider.cs" %}

```csharp
using Umbraco.AI.Core.Providers;

[AIProvider("myprovider", "My AI Provider")]
public class MyProvider : AIProviderBase<MyProviderSettings>
{
    public MyProvider(IAIProviderInfrastructure infrastructure)
        : base(infrastructure)
    {
        WithCapability<MyChatCapability>();
    }
}
```

{% endcode %}

## How It Works

1. Providers are discovered automatically via assembly scanning
2. The `[AIProvider]` attribute registers the provider with an ID and name
3. Settings are rendered in the backoffice using `[AIField]` metadata
4. Capabilities are registered in the constructor with `WithCapability<T>()`

## In This Section

{% content-ref url="/pages/Kv4m6U6lIwwHoehoG4nb" %}
[Creating a Provider](/ai-in-umbraco/extending/providers/creating-a-provider.md)
{% endcontent-ref %}

{% content-ref url="/pages/s9sNhd6aUmTATKI2E290" %}
[Provider Settings](/ai-in-umbraco/extending/providers/provider-settings.md)
{% endcontent-ref %}

{% content-ref url="/pages/iyaRNINhiDnWDkkR3EZo" %}
[Chat Capability](/ai-in-umbraco/extending/providers/chat-capability.md)
{% endcontent-ref %}

{% content-ref url="/pages/InlMD72zbaiEjVyQXrUD" %}
[Embedding Capability](/ai-in-umbraco/extending/providers/embedding-capability.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.umbraco.com/ai-in-umbraco/extending/providers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
