langgenius/dify · warning · UnsupportedAudioTypeError

unsupported_audio_type

unsupported_audio_type

Error message

Audio type not allowed.

What it means

HTTP 415 UnsupportedAudioTypeError, raised by the STT endpoint POST /installed-apps/{id}/audio-to-text. The uploaded file's MIME type is not in the allowed audio set. The service (_invoke_speech_to_text in services/audio_service.py:133-135) compares file.mimetype against audio/{ext} for ext in AUDIO_EXTENSIONS (mp3, m4a, wav, amr, mpga, case-insensitive). If the Content-Type does not match one of those, the controller re-raises the service error as this HTTP error.

Source

Thrown at api/controllers/console/explore/audio.py:77

        try:
            response = AudioService.transcript_asr(
                app_model=app_model,
                file=file,
                session=db.session(),
                end_user=None,
            )

            return response
        except services.errors.app_model_config.AppModelConfigBrokenError:
            logger.exception("App model config broken.")
            raise AppUnavailableError()
        except NoAudioUploadedServiceError:
            raise NoAudioUploadedError()
        except AudioTooLargeServiceError as e:
            raise AudioTooLargeError(str(e))
        except UnsupportedAudioTypeServiceError:
            raise UnsupportedAudioTypeError()
        except ProviderNotSupportSpeechToTextServiceError:
            raise ProviderNotSupportSpeechToTextError()
        except SpeechToTextDisabledServiceError:
            raise SpeechToTextDisabledError()
        except ProviderTokenNotInitError as ex:
            raise ProviderNotInitializeError(ex.description)
        except QuotaExceededError:
            raise ProviderQuotaExceededError()
        except ModelCurrentlyNotSupportError:
            raise ProviderModelCurrentlyNotSupportError()
        except InvokeError as e:
            raise CompletionRequestError(e.description)
        except ValueError as e:
            raise e
        except Exception as e:
            logger.exception("internal server error.")
            raise InternalServerError()

View on GitHub (pinned to ef8544b173)

Solutions

  1. Transcode/re-encode the upload to mp3, m4a, wav, amr, or mpga before sending.
  2. Set the multipart Content-Type header explicitly to one of the allowed audio/* MIME values matching the real bytes.
  3. If you control the client SDK, restrict the recorder/encoder output to mp3 or wav.
  4. If a new format is genuinely required, extend AUDIO_EXTENSIONS in api/constants/__init__.py and confirm the speech2text provider model accepts it.

Example fix

// before: recorder produces audio/webm
form.append('file', blob); // Content-Type: audio/webm -> 415
// after: transcode to mp3 first
const mp3Blob = await transcodeToMp3(blob);
form.append('file', mp3Blob, 'audio.mp3'); // Content-Type: audio/mp3 -> ok
Defensive patterns

Strategy: validation

Validate before calling

ALLOWED = {"mp3", "m4a", "wav", "amr", "mpga"}
function allowedAudio(file: File): boolean {
  const ext = (file.name.split(".").pop() || "").toLowerCase()
  return ALLOWED.has(ext)
}
// before upload:
if (!allowedAudio(file)) throw new Error("Convert to mp3/m4a/wav/amr/mpga first")

Type guard

function isAllowedAudioMime(mime: string): boolean {
  return ["audio/mp3","audio/m4a","audio/wav","audio/amr","audio/mpga"].includes(mime.toLowerCase())
}

Try / catch

// Fetch is the 415 body and surface 'unsupported_audio_type' to the user with a re-encode prompt.
try { await postAudio(file) }
catch (e) { if (e.code === 415 && e.error_code === 'unsupported_audio_type') promptReencode() else throw e }

Prevention

When it happens

Trigger: POST /console/explore/installed-apps/{installed_app_id}/audio-to-text with a multipart 'file' whose Content-Type is e.g. audio/ogg, audio/aac, video/mp4, application/octet-stream, or any value outside audio/mp3|m4a|wav|amr|mpga. Also fires if the client omits a Content-Type and Werkzeug infersences a non-whitelisted type.

Common situations: Client records audio in a browser format (audio/webm, audio/ogg) not in the allowlist; mobile SDK ships .aac/.opus; file renamed to .mp3 but actual Content-Type header is generic; proxy/CDN rewrites Content-Type to application/octet-stream.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/3cf125e7932163df. Report an issue: GitHub.