PrefectHQ/fastmcp · error · ValueError
Unsupported audio MIME type for OpenAI: {content.mime_type!r
Error message
Unsupported audio MIME type for OpenAI: {content.mime_type!r}. Supported types: {', '.join(sorted(_OPENAI_AUDIO_FORMATS))} What it means
OpenAI audio input accepts only wav and mp3 (see _OPENAI_AUDIO_FORMATS). When converting MCP AudioContent with any other MIME type, the handler raises ValueError enumerating the supported formats.
Source
Thrown at fastmcp_slim/fastmcp/client/sampling/handlers/openai.py:86
if content.mime_type not in _OPENAI_IMAGE_MEDIA_TYPES:
raise ValueError(
f"Unsupported image MIME type for OpenAI: {content.mime_type!r}. "
f"Supported types: {', '.join(sorted(_OPENAI_IMAGE_MEDIA_TYPES))}"
)
data_url = f"data:{content.mime_type};base64,{content.data}"
return ChatCompletionContentPartImageParam(
type="image_url",
image_url={"url": data_url},
)
def _audio_content_to_openai_part(
content: AudioContent,
) -> ChatCompletionContentPartInputAudioParam:
"""Convert MCP AudioContent to OpenAI input_audio content part."""
audio_format = _OPENAI_AUDIO_FORMATS.get(content.mime_type)
if audio_format is None:
raise ValueError(
f"Unsupported audio MIME type for OpenAI: {content.mime_type!r}. "
f"Supported types: {', '.join(sorted(_OPENAI_AUDIO_FORMATS))}"
)
return ChatCompletionContentPartInputAudioParam(
type="input_audio",
input_audio={"data": content.data, "format": audio_format},
)
class OpenAISamplingHandler:
"""Sampling handler that uses the OpenAI API."""
def __init__(
self,
default_model: ChatModel,
client: AsyncOpenAI | None = None,
) -> None:
self.client: AsyncOpenAI = client or AsyncOpenAI()View on GitHub (pinned to 1f02114297)
Solutions
- Transcode the audio to WAV or MP3 and update mime_type to 'audio/wav' or 'audio/mp3'.
- Route sampling to a handler supporting the format (e.g. google-genai).
- Set the mime_type explicitly if it was omitted.
- Skip/replace the AudioContent if audio isn't essential to the request.
Example fix
// before AudioContent(type='audio', data=ogg_b64, mime_type='audio/ogg') // after AudioContent(type='audio', data=wav_b64, mime_type='audio/wav')
Defensive patterns
Strategy: validation
Validate before calling
for m in messages:
for c in getattr(m, 'content', []):
if getattr(c, 'type', None) == 'audio' and c.mime_type not in ('audio/wav', 'audio/mp3'):
raise ValueError(f"Transcode {c.mime_type} to wav/mp3 before OpenAI sampling") Type guard
def is_openai_supported_audio(c) -> bool:
return getattr(c, 'type', None) == 'audio' and c.mime_type in ('audio/wav', 'audio/mp3') Try / catch
try:
result = await client.sample(...)
except ValueError as e:
if 'Unsupported audio MIME type for OpenAI' in str(e):
messages = transcode_audio_to_wav(messages)
result = await client.sample(messages=messages, ...)
else:
raise Prevention
- Transcode browser recordings (ogg/webm) to wav/mp3 before sampling.
- Always set mime_type explicitly on AudioContent.
- Route unsupported audio formats to a different provider handler.
When it happens
Trigger: Client.sample() with AudioContent whose mime_type maps to nothing in _OPENAI_AUDIO_FORMATS (e.g. 'audio/ogg', 'audio/webm', 'audio/flac', or missing mime_type), routed through _convert_to_openai_messages -> _audio_content_to_openai_part.
Common situations: Recordings captured as ogg/webm (common from browsers) passed to OpenAI sampling; transcription pipelines using flac; AudioContent constructed without mime_type.
Related errors
- Unsupported image MIME type for OpenAI: {content.mime_type!r
- AudioContent is only supported in user messages for OpenAI
- Unsupported image MIME type for Anthropic: {content.mime_typ
- AudioContent is not supported by the Anthropic API
- Unsupported content type for OpenAI: {type(item).__name__}
AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29).
Data as JSON: /api/errors/967e242a61105d59.
Report an issue: GitHub.