{"record":{"id":"826d31a03be75269","repo":"mastra-ai/mastra","slug":"agent-generate-v1-model-not-supported","errorCode":"AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED","errorMessage":"Agent \"${this.name}\" is using AI SDK v4 model (${provider}:${modelId}) which is not compatible with generate(). Please use AI SDK v5+ models or call the generateLegacy() method instead. See https://mastra.ai/en/docs/streaming/overview for more information.","messagePattern":"Agent \"(.+?)\" is using AI SDK v4 model \\((.+?):(.+?)\\) which is not compatible with generate\\(\\)\\. Please use AI SDK v5\\+ models or call the generateLegacy\\(\\) method instead\\. See https://mastra\\.ai/en/docs/streaming/overview for more information\\.","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/agent.ts","lineNumber":7997,"sourceCode":"      requestContext: mergedOptions.requestContext,\n      memory: mergedOptions.memory,\n      runId: mergedOptions.runId,\n      actor,\n    });\n\n    const llm = await this.getLLM({\n      requestContext: mergedOptions.requestContext,\n      model: mergedOptions.model as DynamicArgument<MastraModelConfig, TRequestContext> | undefined,\n    });\n\n    const modelInfo = llm.getModel();\n\n    if (!isSupportedLanguageModel(modelInfo)) {\n      const modelId = modelInfo.modelId || 'unknown';\n      const provider = modelInfo.provider || 'unknown';\n      const specVersion = modelInfo.specificationVersion;\n\n      throw new MastraError({\n        id: 'AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED',\n        domain: ErrorDomain.AGENT,\n        category: ErrorCategory.USER,\n        text:\n          specVersion === 'v1'\n            ? `Agent \"${this.name}\" is using AI SDK v4 model (${provider}:${modelId}) which is not compatible with generate(). Please use AI SDK v5+ models or call the generateLegacy() method instead. See https://mastra.ai/en/docs/streaming/overview for more information.`\n            : `Agent \"${this.name}\" has a model (${provider}:${modelId}) with unrecognized specificationVersion \"${specVersion}\". Supported versions: v1 (legacy), v2 (AI SDK v5), v3 (AI SDK v6). Please ensure your AI SDK provider is compatible with this version of Mastra.`,\n        details: {\n          agentName: this.name,\n          modelId,\n          provider,\n          specificationVersion: specVersion,\n        },\n      });\n    }\n\n    const executeOptions = {\n      ...loopOptions,","sourceCodeStart":7979,"sourceCodeEnd":8015,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/agent.ts#L7979-L8015","documentation":"Agent.generate() only supports AI SDK v5 (LanguageModelV2) models. When the resolved model's specificationVersion is 'v1' (an AI SDK v4 model), Mastra refuses to run it through generate() because the v5 execution pipeline cannot consume v1-spec models. The library directs you to either swap the model or use the legacy generateLegacy() API.","triggerScenarios":"Calling agent.generate() (or .generateLegacy-adjacent paths) where the resolved modelInfo from isSupportedLanguageModel() fails, specifically when modelInfo.specificationVersion === 'v1'.","commonSituations":"Mixing AI SDK v4 model packages (e.g. @ai-sdk/openai@0.x with openai(...) returning a v1 model) with a Mastra version that requires AI SDK v5; upgrading Mastra but not the provider packages; passing a wrapped/custom provider that implements the old v1 spec.","solutions":["Upgrade AI SDK provider packages to v5-compatible versions (e.g. @ai-sdk/openai@1+/2.x) so the model reports specificationVersion 'v2'.","If you must keep the v4 model, call agent.generateLegacy() instead of agent.generate().","Check for custom model wrappers/proxies that hard-pin the v1 spec and update them to the v2 spec."],"exampleFix":"// before\nimport { openai } from '@ai-sdk/openai@0.x'; // v1-spec model\nawait agent.generate('hi');\n// after\nimport { openai } from '@ai-sdk/openai'; // v5, v2-spec model\nawait agent.generate('hi');","handlingStrategy":"validation","validationCode":"const modelInfo = await resolveModelInfo(model); // or check model.specificationVersion\nif (modelInfo?.specificationVersion === 'v1') {\n  throw new Error('Use agent.generateLegacy() for AI SDK v4 models');\n}","typeGuard":"function isV2Model(m: unknown): m is LanguageModelV2 {\n  return typeof m === 'object' && m !== null && (m as any).specificationVersion === 'v2';\n}","tryCatchPattern":"try {\n  await agent.generate(prompt);\n} catch (e) {\n  if (e instanceof MastraError && e.id === 'AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED') {\n    return agent.generateLegacy(prompt);\n  }\n  throw e;\n}","preventionTips":["Pin AI SDK provider packages to v5-compatible majors in package.json.","Add a startup check asserting model.specificationVersion === 'v2'.","Centralize model construction in one factory so spec version is enforced once."],"tags":["ai-sdk","version-mismatch","agent","generate"],"backgroundTag":"incompatible-model-specification-version","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}