{"record":{"id":"eea0bad51152725a","repo":"danny-avila/LibreChat","slug":"the-audio-file-size-exceeds-the-limit-of-25mb","errorCode":null,"errorMessage":"The audio file size exceeds the limit of 25MB","messagePattern":"The audio file size exceeds the limit of 25MB","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"api/server/services/Files/Audio/STTService.js","lineNumber":243,"sourceCode":"  /**\n   * Prepares the request for the Azure OpenAI STT provider.\n   * @param {Object} sttSchema - The STT schema for Azure OpenAI.\n   * @param {Buffer} audioBuffer - The audio data to be transcribed.\n   * @param {Object} audioFile - The audio file object containing originalname, mimetype, and size.\n   * @param {string} language - The language code for the transcription.\n   * @returns {Array} An array containing the URL, data, and headers for the request.\n   * @throws {Error} If the audio file size exceeds 25MB or the audio file format is not accepted.\n   */\n  azureOpenAIProvider(sttSchema, audioBuffer, audioFile, language) {\n    const url = `${genAzureEndpoint({\n      azureOpenAIApiInstanceName: extractEnvVariable(sttSchema?.instanceName),\n      azureOpenAIApiDeploymentName: extractEnvVariable(sttSchema?.deploymentName),\n    })}/audio/transcriptions?api-version=${extractEnvVariable(sttSchema?.apiVersion)}`;\n\n    const apiKey = sttSchema.apiKey ? resolveConfigSecret(sttSchema.apiKey) || '' : '';\n\n    if (audioBuffer.byteLength > 25 * 1024 * 1024) {\n      throw new Error('The audio file size exceeds the limit of 25MB');\n    }\n\n    const acceptedFormats = ['flac', 'mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'ogg', 'wav', 'webm'];\n    const [mimePrefix, rawFormat = ''] = audioFile.mimetype.split('/');\n    const isAudioMime = mimePrefix === 'audio' || mimePrefix === 'video';\n    const isKnownMime = audioFile.mimetype in MIME_TO_EXTENSION_MAP;\n    const normalizedFormat = isKnownMime ? MIME_TO_EXTENSION_MAP[audioFile.mimetype] : null;\n    if (\n      !acceptedFormats.includes(normalizedFormat) &&\n      !(isAudioMime && acceptedFormats.includes(rawFormat))\n    ) {\n      throw new Error(`The audio file format ${rawFormat} is not accepted`);\n    }\n\n    const formData = new FormData();\n    formData.append('file', audioBuffer, {\n      filename: audioFile.originalname,\n      contentType: audioFile.mimetype,","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/server/services/Files/Audio/STTService.js#L225-L261","documentation":"azureOpenAIProvider rejects any audio buffer whose byteLength exceeds 25 MiB (25*1024*1024) before constructing the multipart request. This mirrors Azure OpenAI STT's hard 25 MB upload cap; the check is local and synchronous, so no network call is wasted.","triggerScenarios":"POST /api/speech/stt using the azureOpenAI provider with a payload whose buffer is larger than 26,214,400 bytes.","commonSituations":"Long uncompressed WAV recordings; high-bitrate audio; no client-side size guard; user uploads a podcast-length file.","solutions":["Compress or trim the audio below 25 MB before uploading (transcode to mp3/ogg).","Downsample to a lower bitrate / mono channel.","Chunk long audio on the client and send multiple requests if the provider supports it."],"exampleFix":"// before: upload raw buffer\nconst audioBuffer = fs.readFileSync(recordingPath);\n\n// after: enforce a client-side cap\nconst MAX = 25 * 1024 * 1024;\nif (audioBuffer.byteLength > MAX) {\n  throw new Error(`Audio too large: ${audioBuffer.byteLength} > ${MAX}`);\n}","handlingStrategy":"validation","validationCode":"const MAX = 25 * 1024 * 1024;\nif (audioBuffer.byteLength > MAX) {\n  return res.status(413).json({ error: `Audio exceeds 25MB (got ${audioBuffer.byteLength} bytes)` });\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enforce the 25MB cap on the client before upload to avoid wasted bandwidth.","Set multer/body-parser limits to match so oversized uploads never reach the service.","Prefer compressed formats (mp3/ogg) for long recordings."],"tags":["stt","azure-openai","file-size","input-validation"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}