{"record":{"id":"496bdeeef28da966","repo":"open-webui/open-webui","slug":"audio-conversion-failed-chat-completions-api-requ","errorCode":null,"errorMessage":"Audio conversion failed. Chat completions API requires mp3 or wav format.","messagePattern":"Audio conversion failed\\. Chat completions API requires mp3 or wav format\\.","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"backend/open_webui/routers/audio.py","lineNumber":957,"sourceCode":"\n    r = None\n    try:\n        model = await Config.get('audio.stt.model') or 'voxtral-mini-latest'\n        log.info(\n            f'Mistral STT - model: {model}, method: {\"chat_completions\" if use_chat_completions else \"transcriptions\"}'\n        )\n\n        session = await get_session()\n        if use_chat_completions:\n            audio_file_to_use = file_path\n            if is_audio_conversion_required(file_path):\n                log.debug('Converting audio to mp3 for chat completions API')\n                converted_path = await asyncio.to_thread(convert_audio_to_mp3, file_path)\n                if converted_path:\n                    audio_file_to_use = converted_path\n                else:\n                    log.error('Audio conversion failed')\n                    raise HTTPException(\n                        status_code=500,\n                        detail='Audio conversion failed. Chat completions API requires mp3 or wav format.',\n                    )\n\n            async with aiofiles.open(audio_file_to_use, 'rb') as audio_file:\n                raw = await audio_file.read()\n                audio_base64 = {\n                    'data': base64.b64encode(raw).decode('utf-8'),\n                    'format': mimetypes.guess_extension(mimetypes.guess_type(audio_file_to_use)[0]).lstrip('.'),\n                }\n\n            language = metadata.get('language', None) if metadata else None\n            text_instruction = (\n                f'Transcribe this audio exactly as spoken in {language}. Do not translate it.'\n                if language\n                else 'Transcribe this audio exactly as spoken in its original language. Do not translate it to another language.'\n            )\n","sourceCodeStart":939,"sourceCodeEnd":975,"githubUrl":"https://github.com/open-webui/open-webui/blob/01f4282f1ffe0d6212f58d3afbeae21fffd0c4be/backend/open_webui/routers/audio.py#L939-L975","documentation":"Raised (500) when Mistral STT runs in chat-completions mode (`audio.stt.mistral.use_chat_completions` true) and the helper `convert_audio_to_mp3(file_path)` returns a falsy value. That helper shells out through pydub/ffmpeg; it returns None when ffmpeg is missing, the binary crashes, or the input audio is unreadable. Since the chat/completions payload embeds base64 audio that Mistral only accepts as mp3 or wav, the handler aborts when conversion fails.","triggerScenarios":"Uploading browser-recorded audio (audio/webm from MediaRecorder) or .ogg/.m4a with use_chat_completions enabled, on a host where ffmpeg is not installed or not on PATH; or uploading a zero-byte/corrupt file that pydub cannot decode.","commonSituations":"Docker images or slim Debian containers without the ffmpeg package; ffmpeg present but an incompatible/old version; a truncated upload (proxy cut the body) producing a non-decodable file; works locally (ffmpeg installed) but fails in CI or production container.","solutions":["Install ffmpeg on the server running Open WebUI (apt-get install -y ffmpeg) and confirm `ffmpeg -version` works as the app user.","If ffmpeg cannot be installed, disable chat-completions mode: set audio.stt.mistral.use_chat_completions to false so the multipart /audio/transcriptions endpoint is used, which accepts other formats.","Verify the uploaded file is playable/complete (ffprobe file.webm) and re-upload; a 0-byte file means the upload itself failed.","Check server logs for the preceding 'Audio conversion failed' log.error line to confirm which input path failed."],"exampleFix":"# before: engine=mistral + use_chat_completions=true, host without ffmpeg\n# -> 500 'Audio conversion failed. Chat completions API requires mp3 or wav format.'\n\n# after (option A): install decoder\n# apt-get update && apt-get install -y ffmpeg\n\n# after (option B): switch to transcriptions mode\nawait Config.save('audio.stt.mistral.use_chat_completions', False)","handlingStrategy":"validation","validationCode":"import shutil, mimetypes\n\ndef can_use_chat_completions_stt(path: str) -> bool:\n    mime = mimetypes.guess_type(path)[0]\n    needs_conversion = mime not in ('audio/mpeg', 'audio/wav', 'audio/x-wav')\n    if needs_conversion and not shutil.which('ffmpeg'):\n        return False  # conversion will fail -> avoid 500\n    return True","typeGuard":null,"tryCatchPattern":"from fastapi import HTTPException\ntry:\n    result = await transcribe(request, path, metadata, user)\nexcept HTTPException as e:\n    if 'conversion failed' in str(e.detail).lower():\n        if not shutil.which('ffmpeg'):\n            raise RuntimeError('ffmpeg missing: disable use_chat_completions or install ffmpeg') from e\n    raise","preventionTips":["Install ffmpeg in the deployment image explicitly (apt-get install -y ffmpeg) and assert shutil.which('ffmpeg') in a startup check.","Record client audio as mp3/wav when chat-completions STT is enabled.","Monitor for the 'Converting audio to mp3 for chat completions API' log line to catch conversion pressure early."],"tags":["open-webui","ffmpeg","pydub","audio-conversion","mistral","stt","http-500"],"backgroundTag":null,"analyzedSha":"01f4282f1ffe0d6212f58d3afbeae21fffd0c4be","analyzedAt":"2026-08-14T18:25:22.715Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}