vercel/ai · error · InvalidArgumentError
targetLanguage is required for translation model '${this.mod
Error message
targetLanguage is required for translation model '${this.modelId}'. What it means
The speech-translation model's doStream requires options.targetLanguage because a translation model must know which language to translate into; Gemini Live translation cannot infer it. When targetLanguage is null or undefined it throws an InvalidArgumentError naming the model. This is a pre-flight argument validation thrown before any network or WebSocket connection is made.
Source
Thrown at packages/google/src/speech-translation/google-speech-translation-model.ts:121
}
get provider(): string {
return this.config.provider;
}
constructor(
modelId: GoogleSpeechTranslationModelId,
config: GoogleSpeechTranslationModelConfig,
) {
this.modelId = modelId;
this.config = config;
}
async doStream(
options: SpeechTranslationModelV4StreamOptions,
): Promise<Awaited<ReturnType<SpeechTranslationModelV4['doStream']>>> {
if (options.targetLanguage == null) {
throw new InvalidArgumentError({
argument: 'targetLanguage',
message: `targetLanguage is required for translation model '${this.modelId}'.`,
});
}
const currentDate = this.config._internal?.currentDate?.() ?? new Date();
const googleOptions = await parseProviderOptions({
provider: 'google',
providerOptions: options.providerOptions,
schema: googleSpeechTranslationModelOptions,
});
const warnings: SharedV4Warning[] = [];
validateGoogleSpeechTranslationInputAudioFormat(options.inputAudioFormat);
if (options.sourceLanguage != null) {
warnings.push({
type: 'unsupported',View on GitHub (pinned to 69428b1f8b)
Solutions
- Pass targetLanguage (e.g. 'es', 'fr-FR') in the stream options.
- If you only need a transcript, use a transcription model instead of a translation model so no target language is needed.
- Validate options.targetLanguage before calling when model choice is dynamic.
Example fix
// before
await model.doStream({ audio: pcmStream });
// after
await model.doStream({ audio: pcmStream, targetLanguage: 'es' }); Defensive patterns
Strategy: validation
Validate before calling
if (options.targetLanguage == null) {
throw new Error('targetLanguage must be provided for translation models');
}
await model.doStream({ ...options, targetLanguage: options.targetLanguage }); Type guard
function hasTargetLanguage(
o: SpeechTranslationModelV4StreamOptions,
): o is SpeechTranslationModelV4StreamOptions & { targetLanguage: string } {
return o.targetLanguage != null;
} Prevention
- Always pass targetLanguage when the model is a translation model.
- Use a transcription model instead if you only need a transcript.
- Centralize stream-option construction so targetLanguage is never forgotten.
- Catch InvalidArgumentError early to fail fast with a clear message.
When it happens
Trigger: Calling experimental_streamTranscribe (or the speech-translation doStream path) on a translation model (e.g. a gemini live translation model id) without passing targetLanguage in the stream options.
Common situations: Reusing transcription code (which has no targetLanguage) against a translation model; switching model IDs from a transcribe model to a translation model without updating options; TypeScript not flagging it because targetLanguage is optional in the shared options type.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- The Gemini Live translation API only supports 16kHz 16-bit P
- Google batch input files must not exceed 2 GB.
- Google Generative AI API key is required for streaming trans
- maxEmbeddingsPerCall must be greater than 0
- maxInputBytesPerCall must be greater than 0
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/dfc33dc3148129da.
Report an issue: GitHub.