langgenius/dify · warning · AudioTooLargeError

audio_too_large

audio_too_large

Error message

Audio size exceeded. {message}

What it means

HTTP 413 with error_code `audio_too_large`, raised by AudioTooLargeError(str(e)) when AudioService raises AudioTooLargeServiceError. The uploaded audio exceeds the configured max size; the service message is interpolated into 'Audio size exceeded. {message}'. This is enforced server-side before the provider STT call to avoid wasted upstream cost.

Source

Thrown at api/controllers/console/explore/trial.py:686

            # Get IDs before they might be detached from session
            app_id = app_model.id
            user_id = current_user.id

            response = AudioService.transcript_asr(
                app_model=app_model,
                file=file,
                session=db.session(),
                end_user=None,
            )
            RecommendedAppService.add_trial_app_record(app_id, user_id, session=db.session())
            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 trim the audio before upload (convert to a lower-bitrate mp3/opus, cut silence).
  2. Check the deployment's configured audio size limit and, if you operate the server, raise AUDIO_MAX_SIZE in config if appropriate.
  3. On the client, enforce the size cap before POSTing so the user gets immediate feedback.

Example fix

// before - upload raw recording
fd.append('file', hugeWavBlob)

// after - enforce client cap and compress
const MAX = 15 * 1024 * 1024
if (blob.size > MAX) { blob = await compressAudio(blob) }
if (blob.size > MAX) { toast('Audio too large'); return }
fd.append('file', blob)
Defensive patterns

Strategy: validation

Validate before calling

const MAX_AUDIO_BYTES = 15 * 1024 * 1024 // match deployment cap
if (file.size > MAX_AUDIO_BYTES) {
  file = await compressOrTrimAudio(file)
}
if (file.size > MAX_AUDIO_BYTES) throw new Error('audio too large even after compression')

Try / catch

try {
  const r = await fetch(audioUrl, { method: 'POST', body: fd })
  if (r.status === 413) showAudioTooLargeMessage()
} catch (e) { reportToUser(e) }

Prevention

When it happens

Trigger: POST TrialChatAudioApi with an audio file whose byte size exceeds the limit configured for the deployment (e.g. the AUDIO_MAX_SIZE / dify_config setting). The service measures the upload and raises before transcription.

Common situations: Long recording not trimmed; lossless format (wav) producing large files; operator lowered the size cap; mobile client recorded at high bitrate.

Related errors


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