microsoft/semantic-kernel · error · NotSupportedException
Unsupported audio format '{mimeType}'. Supported formats are
Error message
Unsupported audio format '{mimeType}'. Supported formats are 'audio/wav' and 'audio/mp3'. What it means
Thrown by GetChatInputAudioFormat. For input audio the connector maps the mime-type to OpenAI's ChatInputAudioFormat, accepting only 'audio/wav' and 'audio/mp3'. Any other mime-type (ogg, flac, m4a, etc.) is not representable as an input-audio format and is rejected with an explicit list of allowed values.
Source
Thrown at dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs:936
{
return ChatMessageContentPart.CreateFilePart(BinaryData.FromBytes(data), binaryContent.MimeType, Guid.NewGuid().ToString());
}
throw new ArgumentException($"{nameof(BinaryContent)} must have Data bytes.");
}
private static ChatInputAudioFormat GetChatInputAudioFormat(string? mimeType)
{
if (string.IsNullOrWhiteSpace(mimeType))
{
return ChatInputAudioFormat.Mp3;
}
return mimeType.ToUpperInvariant() switch
{
"AUDIO/WAV" => ChatInputAudioFormat.Wav,
"AUDIO/MP3" => ChatInputAudioFormat.Mp3,
_ => throw new NotSupportedException($"Unsupported audio format '{mimeType}'. Supported formats are 'audio/wav' and 'audio/mp3'.")
};
}
private static ChatImageDetailLevel? GetChatImageDetailLevel(ImageContent imageContent)
{
const string DetailLevelProperty = "ChatImageDetailLevel";
if (imageContent.Metadata is not null &&
imageContent.Metadata.TryGetValue(DetailLevelProperty, out object? detailLevel) &&
detailLevel is not null)
{
if (detailLevel is string detailLevelString && !string.IsNullOrWhiteSpace(detailLevelString))
{
return detailLevelString.ToUpperInvariant() switch
{
"AUTO" => ChatImageDetailLevel.Auto,
"LOW" => ChatImageDetailLevel.Low,
"HIGH" => ChatImageDetailLevel.High,View on GitHub (pinned to c028a0c7dc)
Solutions
- Transcode the source to WAV or MP3 and set MimeType to 'audio/wav' or 'audio/mp3'.
- If MimeType is missing, the connector defaults to Mp3 — supply bytes that are actually MP3 in that case.
- Validate the mime-type against the allowed set before constructing AudioContent.
Example fix
// before var audio = new AudioContent(bytes, "audio/ogg"); // after var audio = new AudioContent(wavBytes, "audio/wav");
Defensive patterns
Strategy: validation
Validate before calling
static readonly HashSet<string> ValidInputAudioMime = new(StringComparer.OrdinalIgnoreCase) { "audio/wav", "audio/mp3" };
static string NormalizeInputAudioMime(string? m) => string.IsNullOrWhiteSpace(m) ? "audio/mp3" : ValidInputAudioMime.Contains(m) ? m.ToLowerInvariant() : throw new ArgumentException($"Transcode to WAV/MP3; got {m}"); Type guard
static bool IsValidInputAudioMime(string? m) => string.IsNullOrWhiteSpace(m) || ValidInputAudioMime.Contains(m);
Try / catch
try { await client.GetChatCompletionAsync(history); }
catch (NotSupportedException ex) when (ex.Message.Contains("audio format")) { /* transcode to wav/mp3 and retry */ } Prevention
- Transcode sources to WAV or MP3 at capture time.
- Set MimeType explicitly to audio/wav or audio/mp3.
When it happens
Trigger: Building an AudioContent for chat input with a MimeType other than audio/wav or audio/mp3 (e.g. 'audio/ogg', 'audio/m4a', or a null/whitespace handled separately that still resolves elsewhere).
Common situations: Recording in a container format the model's realtime/audio input does not accept; mismatched file extension vs actual codec; passing a generic 'application/octet-stream'.
Related errors
- AudioContent must have Data bytes.
- Unsupported audio output format '{audioOptions.OutputAudioFo
- OPENAI_API_KEY is not set.
- OPENAI_API_KEY is not set.
- OPENAI_API_KEY is not set.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/199b4ba1cab0c4ed.
Report an issue: GitHub.