> For the complete documentation index, see [llms.txt](https://docs.umbraco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.umbraco.com/ai-in-umbraco/17.latest/reference/services/ai-settings-service.md).

# IAISettingsService

Service for reading and updating global AI settings such as default profiles.

## Namespace

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

## Interface

{% code title="IAISettingsService" %}

```csharp
public interface IAISettingsService
{
    Task<AISettings> GetSettingsAsync(CancellationToken cancellationToken = default);

    Task<AISettings> SaveSettingsAsync(AISettings settings, CancellationToken cancellationToken = default);
}
```

{% endcode %}

## Methods

### GetSettingsAsync

Gets the current global AI settings.

| Parameter           | Type                | Description        |
| ------------------- | ------------------- | ------------------ |
| `cancellationToken` | `CancellationToken` | Cancellation token |

**Returns**: The current settings. Creates default settings if none exist.

{% code title="Example" %}

```csharp
var settings = await _settingsService.GetSettingsAsync();

if (settings.DefaultChatProfileId.HasValue)
{
    Console.WriteLine($"Default chat profile: {settings.DefaultChatProfileId}");
}
else
{
    Console.WriteLine("No default chat profile configured");
}
```

{% endcode %}

### SaveSettingsAsync

Updates the global AI settings.

| Parameter           | Type                | Description          |
| ------------------- | ------------------- | -------------------- |
| `settings`          | `AISettings`        | The settings to save |
| `cancellationToken` | `CancellationToken` | Cancellation token   |

**Returns**: The saved settings with audit properties updated.

{% code title="Example" %}

```csharp
var settings = await _settingsService.GetSettingsAsync();
settings.DefaultChatProfileId = chatProfileId;
settings.DefaultEmbeddingProfileId = embeddingProfileId;

var saved = await _settingsService.SaveSettingsAsync(settings);
Console.WriteLine($"Settings updated at {saved.DateModified}");
```

{% endcode %}

## Usage Example

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

```csharp
public class SettingsManager
{
    private readonly IAISettingsService _settingsService;
    private readonly IAIProfileService _profileService;

    public SettingsManager(
        IAISettingsService settingsService,
        IAIProfileService profileService)
    {
        _settingsService = settingsService;
        _profileService = profileService;
    }

    public async Task SetDefaultChatProfileAsync(string profileAlias)
    {
        var profile = await _profileService.GetProfileByAliasAsync(profileAlias);
        if (profile == null)
        {
            throw new ArgumentException($"Profile '{profileAlias}' not found");
        }

        if (profile.Capability != AICapability.Chat)
        {
            throw new ArgumentException($"Profile '{profileAlias}' is not a chat profile");
        }

        var settings = await _settingsService.GetSettingsAsync();
        settings.DefaultChatProfileId = profile.Id;
        await _settingsService.SaveSettingsAsync(settings);
    }

    public async Task ClearDefaultsAsync()
    {
        var settings = await _settingsService.GetSettingsAsync();
        settings.DefaultChatProfileId = null;
        settings.DefaultEmbeddingProfileId = null;
        await _settingsService.SaveSettingsAsync(settings);
    }
}
```

{% endcode %}

## Notes

* Settings use a singleton pattern - there is always exactly one settings record
* Settings are not versionable
* Settings are cached for performance; cache is invalidated on save

## Related

* [AISettings](/ai-in-umbraco/17.latest/reference/models/ai-settings.md) - The settings model
* [Settings Concept](/ai-in-umbraco/17.latest/concepts/settings.md) - Settings concepts


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.umbraco.com/ai-in-umbraco/17.latest/reference/services/ai-settings-service.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
