microsoft/semantic-kernel · error · NotSupportedException

The provided audio options '{executionSettings.Audio?.GetTyp

Error message

The provided audio options '{executionSettings.Audio?.GetType()}' is not supported.

What it means

Terminal throw in the audio-options mapper. After attempting ChatAudioOptions instances and a JSON string (via ModelReaderWriter.Read), any other runtime type for executionSettings.Audio cannot be converted and its GetType() is reported.

Source

Thrown at dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs:1220

        if (executionSettings.Audio is JsonElement audioOptionsElement)
        {
            var result = ModelReaderWriter.Read<ChatAudioOptions>(BinaryData.FromString(audioOptionsElement.GetRawText()));
            if (result != null)
            {
                return result;
            }
        }

        if (executionSettings.Audio is string audioOptionsString)
        {
            var result = ModelReaderWriter.Read<ChatAudioOptions>(BinaryData.FromString(audioOptionsString));
            if (result != null)
            {
                return result;
            }
        }

        throw new NotSupportedException($"The provided audio options '{executionSettings.Audio?.GetType()}' is not supported.");
    }

    /// <summary>
    /// Captures usage details, including token information.
    /// </summary>
    /// <param name="usage">Instance of <see cref="ChatTokenUsage"/> with token usage details.</param>
    private void LogUsage(ChatTokenUsage usage)
    {
        if (usage is null)
        {
            this.Logger!.LogDebug("Token usage information unavailable.");
            return;
        }

        if (this.Logger!.IsEnabled(LogLevel.Information))
        {
            this.Logger.LogInformation(
                "Prompt tokens: {InputTokenCount}. Completion tokens: {OutputTokenCount}. Total tokens: {TotalTokenCount}.",

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass a ChatAudioOptions instance or a JSON string that deserializes into one.
  2. Serialize dictionaries/anonymous objects to a JSON string first.
  3. Avoid JsonElement unless you first stringify it.

Example fix

// before
settings.Audio = new Dictionary<string,object> { ["voice"] = "alloy" };
// after
settings.Audio = "{\"voice\":\"alloy\",\"format\":\"wav\"}";
Defensive patterns

Strategy: type-guard

Validate before calling

static bool IsSupportedAudioOptions(object? o) => o is ChatAudioOptions or string or JsonElement;

Type guard

static bool IsSupportedAudioOptions(object? o) => o is ChatAudioOptions or string or JsonElement;

Try / catch

try { await client.GetChatCompletionAsync(...); }
catch (NotSupportedException ex) when (ex.Message.Contains("audio options")) { settings.Audio = null; }

Prevention

When it happens

Trigger: Setting Audio to a Dictionary<string,object>, an anonymous object, a JsonElement of object kind, or a custom DTO instead of a ChatAudioOptions or a JSON string.

Common situations: Building settings from dynamic JSON; interop with System.Text.Json.Nodes; passing a partial object from another library.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/f82ac262de20e7cb. Report an issue: GitHub.