{"record":{"id":"dfc33dc3148129da","repo":"vercel/ai","slug":"targetlanguage-is-required-for-translation-model","errorCode":null,"errorMessage":"targetLanguage is required for translation model '${this.modelId}'.","messagePattern":"targetLanguage is required for translation model '(.+?)'\\.","errorType":"validation","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"packages/google/src/speech-translation/google-speech-translation-model.ts","lineNumber":121,"sourceCode":"  }\n\n  get provider(): string {\n    return this.config.provider;\n  }\n\n  constructor(\n    modelId: GoogleSpeechTranslationModelId,\n    config: GoogleSpeechTranslationModelConfig,\n  ) {\n    this.modelId = modelId;\n    this.config = config;\n  }\n\n  async doStream(\n    options: SpeechTranslationModelV4StreamOptions,\n  ): Promise<Awaited<ReturnType<SpeechTranslationModelV4['doStream']>>> {\n    if (options.targetLanguage == null) {\n      throw new InvalidArgumentError({\n        argument: 'targetLanguage',\n        message: `targetLanguage is required for translation model '${this.modelId}'.`,\n      });\n    }\n\n    const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n    const googleOptions = await parseProviderOptions({\n      provider: 'google',\n      providerOptions: options.providerOptions,\n      schema: googleSpeechTranslationModelOptions,\n    });\n    const warnings: SharedV4Warning[] = [];\n\n    validateGoogleSpeechTranslationInputAudioFormat(options.inputAudioFormat);\n\n    if (options.sourceLanguage != null) {\n      warnings.push({\n        type: 'unsupported',","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/google/src/speech-translation/google-speech-translation-model.ts#L103-L139","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait model.doStream({ audio: pcmStream });\n// after\nawait model.doStream({ audio: pcmStream, targetLanguage: 'es' });","handlingStrategy":"validation","validationCode":"if (options.targetLanguage == null) {\n  throw new Error('targetLanguage must be provided for translation models');\n}\nawait model.doStream({ ...options, targetLanguage: options.targetLanguage });","typeGuard":"function hasTargetLanguage(\n  o: SpeechTranslationModelV4StreamOptions,\n): o is SpeechTranslationModelV4StreamOptions & { targetLanguage: string } {\n  return o.targetLanguage != null;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["google","speech-translation","missing-argument","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}