{"record":{"id":"65c7795f8764cf32","repo":"vercel/ai","slug":"targetlanguage-is-required-for-translation-model-65c779","errorCode":null,"errorMessage":"targetLanguage is required for translation model '${this.modelId}'.","messagePattern":"targetLanguage is required for translation model '(.+?)'\\.","errorType":"exception","errorClass":"InvalidArgumentError","httpStatus":null,"severity":"error","filePath":"packages/openai/src/speech-translation/openai-speech-translation-model.ts","lineNumber":70,"sourceCode":"    config: OpenAISpeechTranslationModelConfig;\n  }) {\n    return new OpenAISpeechTranslationModel(options.modelId, options.config);\n  }\n\n  get provider(): string {\n    return this.config.provider;\n  }\n\n  constructor(\n    readonly modelId: OpenAISpeechTranslationModelId,\n    private readonly config: OpenAISpeechTranslationModelConfig,\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    await parseProviderOptions({\n      provider: 'openai',\n      providerOptions: options.providerOptions,\n      schema: openAISpeechTranslationModelOptions,\n    });\n    const warnings: SharedV4Warning[] = [];\n\n    validateOpenAISpeechTranslationInputAudioFormat(options.inputAudioFormat);\n\n    if (options.sourceLanguage != null) {\n      warnings.push({\n        type: 'unsupported',","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/openai/src/speech-translation/openai-speech-translation-model.ts#L52-L88","documentation":"OpenAI speech translation requires an explicit target language; unlike transcription, the API does not infer it. doStream of OpenAISpeechTranslationModel validates options.targetLanguage up front and throws InvalidArgumentError if it is null/undefined, since the underlying realtime translation call cannot proceed without it.","triggerScenarios":"Invoking a translation model (openai.translation(...) / SpeechTranslationModelV4 doStream) without providing targetLanguage in the call options, e.g. omitting it or passing null after conditional construction of options.","commonSituations":"Reusing code written for transcription (which needs no target language) for translation; building options dynamically where targetLanguage depends on optional user input; type loosening via `as any` hiding the missing property.","solutions":["Pass targetLanguage (e.g. 'es', 'fr') in the doStream/call options","Default the language in your app before invoking the model","Validate the options object at the boundary of your application"],"exampleFix":"// before\nmodel.doStream({ audio: input })\n// after\nmodel.doStream({ audio: input, targetLanguage: 'es' })","handlingStrategy":"validation","validationCode":"if (options.targetLanguage == null) {\n  throw new Error('targetLanguage must be provided for translation models');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await translationModel.doStream({ ...options, targetLanguage });\n} catch (e) {\n  if (InvalidArgumentError.isInstance(e) && e.argument === 'targetLanguage') {\n    // prompt user for a language or apply a default before retrying\n  } else throw e;\n}","preventionTips":["Always set targetLanguage when using translation models (they differ from transcription models)","Use TypeScript's required-property typing instead of optional fields in your options builders","Apply a sensible default language at the application boundary"],"tags":["openai","speech-translation","invalid-argument","missing-parameter"],"backgroundTag":"missing-required-parameter","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}