# ModelProviderSettings

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.modelprovidersettings/
> Summary: ModelProviderSettings: Helpers that read and validate a provider settings dictionary: the ModelBinding.ProviderSettings of a model binding, and the ProviderSettings of a speech request.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Abstractions.dll</code></div>

Helpers that read and validate a provider settings dictionary: the
[ModelBinding.ProviderSettings](/api/tracon.modelbinding/#Tracon_ModelBinding_ProviderSettings) of a model binding, and the
`ProviderSettings` of a speech request.

```csharp
public static class ModelProviderSettings
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.modelprovidersettings/">ModelProviderSettings</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone">object.MemberwiseClone()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Remarks

Each provider package knows its own key prefix (`anthropic`, `google`,
`elevenlabs`) and carries the list of keys it supports. This type applies that
list, so the validation logic is not written again in every new provider package.

**An unknown key is not ignored silently.** A setting that is ignored
makes the user miss the behaviour they expect without seeing why — the same decision
as the one taken for [ModelBinding.ReasoningEffort](/api/tracon.modelbinding/#Tracon_ModelBinding_ReasoningEffort).

**A refusal names the key, never the value.** A value can be text a user
wrote or a credential pasted into the wrong field, and the message reaches logs and
run records. A value of the wrong type is described by its JSON kind.

Keys are compared case insensitively. When the dictionary is read back from a
`jsonb` column it arrives with the default (ordinal) comparer; the lookup is
therefore not left to the comparer of the dictionary itself.

## Methods

### <a id="Tracon_ModelProviderSettings_ReadBoolean_Tracon_ModelBinding_System_String_"></a> ReadBoolean\(ModelBinding, string\)

Reads a setting as a boolean value.

```csharp
public static bool? ReadBoolean(ModelBinding binding, string key)
```

#### Parameters

`binding` [ModelBinding](/api/tracon.modelbinding/)

The model binding.

`key` [string](https://learn.microsoft.com/dotnet/api/system.string)

The full key, for example `anthropic.promptCaching`.

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)?

[null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) when the setting is not defined.

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

`binding` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

 [TraconException](/api/tracon.traconexception/)

The value is not a boolean value.

### <a id="Tracon_ModelProviderSettings_ReadInt32_Tracon_ModelBinding_System_String_"></a> ReadInt32\(ModelBinding, string\)

Reads a setting as an integer.

```csharp
public static int? ReadInt32(ModelBinding binding, string key)
```

#### Parameters

`binding` [ModelBinding](/api/tracon.modelbinding/)

The model binding.

`key` [string](https://learn.microsoft.com/dotnet/api/system.string)

The full key, for example `anthropic.thinking.budgetTokens`.

#### Returns

 [int](https://learn.microsoft.com/dotnet/api/system.int32)?

[null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) when the setting is not defined.

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

`binding` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

 [TraconException](/api/tracon.traconexception/)

The value is not an integer.

### <a id="Tracon_ModelProviderSettings_ReadString_Tracon_ModelBinding_System_String_"></a> ReadString\(ModelBinding, string\)

Reads a setting as text.

```csharp
public static string? ReadString(ModelBinding binding, string key)
```

#### Parameters

`binding` [ModelBinding](/api/tracon.modelbinding/)

The model binding.

`key` [string](https://learn.microsoft.com/dotnet/api/system.string)

The full key, for example `google.safety.harassment`.

#### Returns

 [string](https://learn.microsoft.com/dotnet/api/system.string)?

[null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) when the setting is not defined or is empty.

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

`binding` is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

 [TraconException](/api/tracon.traconexception/)

The value is not text.

### <a id="Tracon_ModelProviderSettings_Validate_Tracon_ModelBinding_System_String_System_Collections_Generic_IReadOnlyCollection_System_String__"></a> Validate\(ModelBinding, string, IReadOnlyCollection<string\>\)

Validates that every provider setting in the binding belongs to the given prefix
and is supported.

```csharp
public static void Validate(ModelBinding binding, string providerPrefix, IReadOnlyCollection<string> supportedKeys)
```

#### Parameters

`binding` [ModelBinding](/api/tracon.modelbinding/)

The model binding to check.

`providerPrefix` [string](https://learn.microsoft.com/dotnet/api/system.string)

The key prefix of the provider, for example `anthropic`.

`supportedKeys` [IReadOnlyCollection](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlycollection\-1)<[string](https://learn.microsoft.com/dotnet/api/system.string)\>

The full keys the provider supports, prefix included, for example
`anthropic.promptCaching`.

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

One of the parameters is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

`providerPrefix` is empty.

 [TraconException](/api/tracon.traconexception/)

The dictionary holds a key that belongs to another provider or that is not
recognized. The message lists the supported keys.

### <a id="Tracon_ModelProviderSettings_Validate_System_Collections_Generic_IReadOnlyDictionary_System_String_System_Text_Json_JsonElement__System_String_System_Collections_Generic_IReadOnlyCollection_System_String__"></a> Validate\(IReadOnlyDictionary<string, JsonElement\>, string, IReadOnlyCollection<string\>\)

Validates that every key of a provider settings dictionary belongs to the given
prefix and is supported.

```csharp
public static void Validate(IReadOnlyDictionary<string, JsonElement> settings, string providerPrefix, IReadOnlyCollection<string> supportedKeys)
```

#### Parameters

`settings` [IReadOnlyDictionary](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlydictionary\-2)<[string](https://learn.microsoft.com/dotnet/api/system.string), [JsonElement](https://learn.microsoft.com/dotnet/api/system.text.json.jsonelement)\>

The settings to check, for example `SpeechRequest.ProviderSettings`.

`providerPrefix` [string](https://learn.microsoft.com/dotnet/api/system.string)

The key prefix of the provider, for example `elevenlabs`.

`supportedKeys` [IReadOnlyCollection](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlycollection\-1)<[string](https://learn.microsoft.com/dotnet/api/system.string)\>

The full keys the provider supports, prefix included, for example
`elevenlabs.stability`. Pass an empty list when the provider supports none.

#### Remarks

The same rule as the [ModelBinding](/api/tracon.modelbinding/) overload, which runs the same code:
keys are compared case-insensitively, a key of another provider is told apart from
an unrecognized one, and nothing is ignored silently.

A speech provider that supports one setting checks a request before it calls its
service:

```csharp
ModelProviderSettings.Validate(
    request.ProviderSettings,
    "contoso",
    ["contoso.pitch"]);
```

#### Exceptions

 [ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)

One of the parameters is [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

 [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception)

`providerPrefix` is empty.

 [TraconException](/api/tracon.traconexception/)

The dictionary holds a key that belongs to another provider or that is not
recognized. The message names those keys and lists the supported ones; it never
carries a value.
