{"record":{"id":"f047535a6ebaa679","repo":"mastra-ai/mastra","slug":"unsupported-model-version-model-as-any-specif","errorCode":null,"errorMessage":"Unsupported model version: ${(model as any).specificationVersion}. Model must implement doStream.${hint}","messagePattern":"Unsupported model version: (.+?)\\. Model must implement doStream\\.(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/durable/workflows/steps/llm-execution.ts","lineNumber":336,"sourceCode":"      for (let modelIndex = 0; modelIndex < modelList.length; modelIndex++) {\n        const modelEntry = modelList[modelIndex]!;\n        const maxRetries = modelEntry.maxRetries || 0;\n\n        for (let attempt = 0; attempt <= maxRetries; attempt++) {\n          try {\n            // Resolve the model - for single model case (no modelList), use resolved model\n            // For model list case, try registry first (works with mock models), then config resolution (for Inngest)\n            const model = !hasModelList\n              ? resolvedModel\n              : (resolvedModelList?.find(m => m.id === modelEntry.id)?.model ??\n                (await resolveModelFromListEntry(modelEntry, mastra as Mastra)));\n\n            // Check if model is supported\n            if (!isSupportedLanguageModel(model)) {\n              const hint = (model as any).__metadataOnly\n                ? ' The model could not be resolved from the run registry or Mastra instance.'\n                : '';\n              throw new Error(\n                `Unsupported model version: ${(model as any).specificationVersion}. Model must implement doStream.${hint}`,\n              );\n            }\n\n            // 5. Prepare tools - cast through unknown as CoreTool and ToolSet are structurally compatible at runtime\n            let currentModel = model;\n            let currentTools = tools as unknown as ToolSet;\n            let currentToolChoice = execOptions.toolChoice as ToolChoice<ToolSet> | undefined;\n            let currentActiveTools = execOptions.activeTools;\n            let currentModelSettings: Record<string, unknown> = { ...(execOptions.modelSettings ?? {}) };\n            let currentProviderOptions: SharedProviderOptions | undefined = mergeProviderOptions(\n              execOptions.providerOptions,\n              modelEntry.config.providerOptions,\n            ) as SharedProviderOptions | undefined;\n\n            // 6. Rebuild MODEL_GENERATION span from passed data\n            // For durable execution, ONE model_generation span is created BEFORE the workflow starts\n            // and passed through each iteration. This ensures all steps are children of the same span.","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/durable/workflows/steps/llm-execution.ts#L318-L354","documentation":"The durable LLM execution step checks isSupportedLanguageModel(model) before streaming. If the check fails, it throws reporting the object's specificationVersion and requires the model to implement doStream. When the object is the `__metadataOnly` stub (error 1073), the message appends a hint that the model could not be resolved from the run registry or Mastra instance.","triggerScenarios":"Passing a v1-style/legacy model object (no doStream/specificationVersion mismatch) into a durable agent run, or the resolveModel fallback stub being used because the real model wasn't found.","commonSituations":"Mixing AI SDK v4 models with a v5/doStream-based core, custom model wrappers missing specificationVersion, or resuming runs whose models can't be re-hydrated after a deploy.","solutions":["If the hint mentions the run registry, fix model resolution first (pass mastra / re-register the model — see error 1073).","Use a LanguageModelV2-compatible model that implements doStream.","Upgrade custom model wrappers to the current specificationVersion.","Verify you're not importing a stale v4 model factory in the durable path."],"exampleFix":"// before\nimport { openai } from '@ai-sdk/openai'; // v4 factory producing non-doStream model\nconst agent = new Agent({ model: openai('gpt-4o') });\n// after\nimport { createOpenAI } from '@ai-sdk/openai'; // current major aligned with core\nconst openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY });\nconst agent = new Agent({ model: openai('gpt-4o') });","handlingStrategy":"type-guard","validationCode":"if (!isSupportedLanguageModel(model)) {\n  throw new Error('Configured model does not implement doStream (LanguageModelV2 required)');\n}","typeGuard":"function isStreamableModel(m: unknown): m is MastraLanguageModel {\n  return (\n    !!m && typeof m === 'object' &&\n    (m as any).specificationVersion === 'v2' &&\n    typeof (m as any).doStream === 'function'\n  );\n}","tryCatchPattern":"try {\n  await durableAgent.generate({ messages });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Unsupported model version')) {\n    logger.error('Replace model with a doStream-compatible (LanguageModelV2) instance');\n  }\n  throw e;\n}","preventionTips":["Pin AI SDK provider packages to majors compatible with @mastra/core's doStream contract","Add a boot-time isSupportedLanguageModel check for every agent model","For custom models, implement doStream and set specificationVersion correctly","Never reuse v4-era model factories in durable execution paths"],"tags":["model","compatibility","durable-agent","ai-sdk"],"backgroundTag":"unsupported-model-version","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}