{"record":{"id":"967e242a61105d59","repo":"PrefectHQ/fastmcp","slug":"unsupported-audio-mime-type-for-openai-content-m","errorCode":null,"errorMessage":"Unsupported audio MIME type for OpenAI: {content.mime_type!r}. Supported types: {', '.join(sorted(_OPENAI_AUDIO_FORMATS))}","messagePattern":"Unsupported audio MIME type for OpenAI: (.+?)\\. Supported types: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/client/sampling/handlers/openai.py","lineNumber":86,"sourceCode":"    if content.mime_type not in _OPENAI_IMAGE_MEDIA_TYPES:\n        raise ValueError(\n            f\"Unsupported image MIME type for OpenAI: {content.mime_type!r}. \"\n            f\"Supported types: {', '.join(sorted(_OPENAI_IMAGE_MEDIA_TYPES))}\"\n        )\n    data_url = f\"data:{content.mime_type};base64,{content.data}\"\n    return ChatCompletionContentPartImageParam(\n        type=\"image_url\",\n        image_url={\"url\": data_url},\n    )\n\n\ndef _audio_content_to_openai_part(\n    content: AudioContent,\n) -> ChatCompletionContentPartInputAudioParam:\n    \"\"\"Convert MCP AudioContent to OpenAI input_audio content part.\"\"\"\n    audio_format = _OPENAI_AUDIO_FORMATS.get(content.mime_type)\n    if audio_format is None:\n        raise ValueError(\n            f\"Unsupported audio MIME type for OpenAI: {content.mime_type!r}. \"\n            f\"Supported types: {', '.join(sorted(_OPENAI_AUDIO_FORMATS))}\"\n        )\n    return ChatCompletionContentPartInputAudioParam(\n        type=\"input_audio\",\n        input_audio={\"data\": content.data, \"format\": audio_format},\n    )\n\n\nclass OpenAISamplingHandler:\n    \"\"\"Sampling handler that uses the OpenAI API.\"\"\"\n\n    def __init__(\n        self,\n        default_model: ChatModel,\n        client: AsyncOpenAI | None = None,\n    ) -> None:\n        self.client: AsyncOpenAI = client or AsyncOpenAI()","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/client/sampling/handlers/openai.py#L68-L104","documentation":"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.","triggerScenarios":"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.","commonSituations":"Recordings captured as ogg/webm (common from browsers) passed to OpenAI sampling; transcription pipelines using flac; AudioContent constructed without mime_type.","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."],"exampleFix":"// before\nAudioContent(type='audio', data=ogg_b64, mime_type='audio/ogg')\n// after\nAudioContent(type='audio', data=wav_b64, mime_type='audio/wav')","handlingStrategy":"validation","validationCode":"for m in messages:\n    for c in getattr(m, 'content', []):\n        if getattr(c, 'type', None) == 'audio' and c.mime_type not in ('audio/wav', 'audio/mp3'):\n            raise ValueError(f\"Transcode {c.mime_type} to wav/mp3 before OpenAI sampling\")","typeGuard":"def is_openai_supported_audio(c) -> bool:\n    return getattr(c, 'type', None) == 'audio' and c.mime_type in ('audio/wav', 'audio/mp3')","tryCatchPattern":"try:\n    result = await client.sample(...)\nexcept ValueError as e:\n    if 'Unsupported audio MIME type for OpenAI' in str(e):\n        messages = transcode_audio_to_wav(messages)\n        result = await client.sample(messages=messages, ...)\n    else:\n        raise","preventionTips":["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."],"tags":["openai","sampling","audio","mime-type"],"backgroundTag":"unsupported-media-type","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}