vercel/ai · error · InvalidArgumentError

ElevenLabs only supports audio/pcmu at 8000 Hz

Error message

ElevenLabs only supports audio/pcmu at 8000 Hz

What it means

InvalidArgumentError thrown by getElevenLabsRealtimeAudioFormat when an audio/pcmu input format declares a sample rate other than 8000 Hz (or omits it, which is accepted). ElevenLabs realtime transcription only accepts PCMU (u-law) at exactly 8000 Hz, mapping to 'ulaw_8000'.

Source

Thrown at packages/elevenlabs/src/elevenlabs-transcription-model.ts:337

        previousText: streamingOptions?.previousText ?? undefined,
        sampleRate: inputFormat.sampleRate,
        url,
        warnings,
        webSocket: this.config.webSocket,
      }),
    };
  }
}

function getElevenLabsRealtimeAudioFormat(
  inputAudioFormat: TranscriptionModelV4StreamOptions['inputAudioFormat'],
): { audioFormat: string; sampleRate: number } {
  const type = inputAudioFormat.type.toLowerCase();
  const rate = inputAudioFormat.rate;

  if (type === 'audio/pcmu') {
    if (rate != null && rate !== 8000) {
      throw new InvalidArgumentError({
        argument: 'inputAudioFormat',
        message: 'ElevenLabs only supports audio/pcmu at 8000 Hz',
      });
    }
    return { audioFormat: 'ulaw_8000', sampleRate: 8000 };
  }

  const supportedPcmRates = [8000, 16000, 22050, 24000, 44100, 48000];
  const pcmRate = rate ?? 16000;
  if (type !== 'audio/pcm' || !supportedPcmRates.includes(pcmRate)) {
    throw new InvalidArgumentError({
      argument: 'inputAudioFormat',
      message:
        'ElevenLabs realtime transcription supports audio/pcm at 8000, 16000, 22050, 24000, 44100, or 48000 Hz, and audio/pcmu at 8000 Hz',
    });
  }

  return { audioFormat: `pcm_${pcmRate}`, sampleRate: pcmRate };

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Set the sample rate to 8000 for audio/pcmu input.
  2. Omit the rate field entirely; PCMU defaults to 8000 Hz.
  3. If your source audio is at a different rate, transcode it to 8 kHz u-law before streaming.

Example fix

// before
{ type: 'audio/pcmu', rate: 16000 }
// after
{ type: 'audio/pcmu', rate: 8000 }
Defensive patterns

Strategy: validation

Validate before calling

function assertPcmuFormat(f: { type: string; rate?: number }) {
  if (f.type.toLowerCase() === 'audio/pcmu' && f.rate != null && f.rate !== 8000) {
    throw new Error('audio/pcmu must be 8000 Hz for ElevenLabs realtime');
  }
}

Type guard

function isPcmu8k(f: { type: string; rate?: number }): boolean {
  return f.type.toLowerCase() === 'audio/pcmu' && (f.rate ?? 8000) === 8000;
}

Prevention

When it happens

Trigger: Providing inputAudioFormat { type: 'audio/pcmu', rate: 16000 } (or any rate != 8000) when constructing the realtime input format via inputFormat.

Common situations: Telephony integrations that resample or misconfigure PCMU streams, or developers assuming PCMU can run at higher rates like PCM can.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/fb266cb5e19e1558. Report an issue: GitHub.