{"record":{"id":"21f328fc86f46e13","repo":"vercel/ai","slug":"model-could-not-be-resolved","errorCode":null,"errorMessage":"Model could not be resolved","messagePattern":"Model could not be resolved","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ai/src/generate-speech/generate-speech.ts","lineNumber":121,"sourceCode":"   *\n   * @default 2\n   */\n  maxRetries?: number;\n\n  /**\n   * Abort signal.\n   */\n  abortSignal?: AbortSignal;\n\n  /**\n   * Additional headers to include in the request.\n   * Only applicable for HTTP-based providers.\n   */\n  headers?: Record<string, string>;\n}): Promise<SpeechResult> {\n  const resolvedModel = resolveSpeechModel(model);\n  if (!resolvedModel) {\n    throw new Error('Model could not be resolved');\n  }\n\n  const headersWithUserAgent = withUserAgentSuffix(\n    headers ?? {},\n    `ai/${VERSION}`,\n  );\n\n  const { retry } = prepareRetries({\n    maxRetries: maxRetriesArg,\n    abortSignal,\n  });\n\n  const result = await retry(() =>\n    resolvedModel.doGenerate({\n      text,\n      voice,\n      outputFormat,\n      instructions,","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/ai/src/generate-speech/generate-speech.ts#L103-L139","documentation":"generateSpeech resolves the provided model via resolveSpeechModel; if the value cannot be resolved to a speech-capable model (e.g. a string id that no provider registry maps to a SpeechModelV*), a plain Error('Model could not be resolved') is thrown before any network request. It guards against calling the speech API with an unusable model value.","triggerScenarios":"Passing null/undefined as `model`; passing a plain string model id with no default speech provider configured; passing a language/embedding/image model object instead of a SpeechModel; passing an object that fails resolveSpeechModel's shape checks.","commonSituations":"Reading the model id from env/config and forgetting to call provider(modelId); refactors after provider upgrades where the speech model factory moved; typos in provider instantiation like openai('tts-1') assigned to the wrong variable.","solutions":["Pass an explicit speech model instance, e.g. openai.speech('tts-1') or openai('tts-1') from the provider's speech factory","Check that the variable passed as `model` is actually a speech model, not another model type","If passing a string, ensure a default speech model/provider is configured for resolution","Log/inspect the model value just before the call to catch null/undefined"],"exampleFix":"// before\nawait generateSpeech({ model: 'tts-1', text });\n// after\nimport { createOpenAI } from '@ai-sdk/openai';\nconst openai = createOpenAI();\nawait generateSpeech({ model: openai.speech('tts-1'), text });","handlingStrategy":"validation","validationCode":"import { isSpeechModel } from 'ai'; // or check provider shape\nif (model == null || typeof model !== 'object' || !('modelId' in model)) {\n  throw new Error('A speech model instance is required');\n}","typeGuard":"function isSpeechModel(m: unknown): m is SpeechModel {\n  return m != null && typeof m === 'object' && 'doGenerate' in m && 'modelId' in m;\n}","tryCatchPattern":"try {\n  return await generateSpeech({ model, text });\n} catch (e) {\n  if (e instanceof Error && e.message === 'Model could not be resolved') {\n    throw new Error('Pass a provider speech model, e.g. openai.speech(\"tts-1\")');\n  }\n  throw e;\n}","preventionTips":["Always pass provider-created speech models (provider.speech(id))","Do not pass raw string ids unless a default provider is configured","Double-check imports so language models are not passed to generateSpeech"],"tags":["model-resolution","configuration","speech"],"backgroundTag":"model-not-found","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}