langgenius/dify · warning · AudioTooLargeError

audio_too_large

audio_too_large

Error message

Audio size exceeded. {message}

What it means

Raised as AudioTooLargeError (error_code audio_too_large, HTTP 413) at audio.py:75 when AudioService.transcript_asr raises AudioTooLargeServiceError. The description template 'Audio size exceeded. {message}' is filled with the service's detail, typically the size limit and the received size. The file exceeded the configured maximum audio size.

Source

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

        file = request.files["file"]

        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.")

View on GitHub (pinned to ef8544b173)

Solutions

  1. Compress or downsample the audio (e.g., export as 64-128 kbps mp3/m4a) before uploading.
  2. Trim the recording to a shorter duration.
  3. Read the interpolated message to learn the exact limit, then size the file under it.
  4. If you operate the platform and the limit is too low for legitimate use, raise the configured max audio size.

Example fix

// before
POST /installed-apps/<id>/audio-to-text  file=recording.wav (60MB)   // -> 413 audio_too_large
// after
// re-encode to 96 kbps mp3, trim to < limit
POST /installed-apps/<id>/audio-to-text  file=recording.mp3 (4MB)
Defensive patterns

Strategy: validation

Validate before calling

const MAX_AUDIO_BYTES = 15 * 1024 * 1024; // align with platform limit
function ensureAudioUnderLimit(file) {
  if (file.size > MAX_AUDIO_BYTES) throw new Error(`audio_too_large: ${file.size} > ${MAX_AUDIO_BYTES}`);
  return file;
}

Type guard

function isAudioWithinLimit(file, limit) { return !!file && typeof file.size === 'number' && file.size <= limit; }

Try / catch

try { ensureAudioUnderLimit(file); await upload(file); } catch (e) { if (/audio_too_large|413/.test(e.message ?? e.code)) { await recompressAudio(file); } else throw e; }

Prevention

When it happens

Trigger: POST /installed-apps/<id>/audio-to-text with an audio file larger than the platform's max audio size limit. transcript_asr measures the upload and throws AudioTooLargeServiceError, mapped to AudioTooLargeError (413).

Common situations: Long recordings exported at high bitrate; WAV instead of compressed mp3/m4a; per-environment size cap lowered; mobile recording with no duration cap.

Related errors


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