mastra-ai/mastra · error · MastraError
AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED
AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED
Error message
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. What it means
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.
Source
Thrown at packages/core/src/agent/agent.ts:7997
requestContext: mergedOptions.requestContext,
memory: mergedOptions.memory,
runId: mergedOptions.runId,
actor,
});
const llm = await this.getLLM({
requestContext: mergedOptions.requestContext,
model: mergedOptions.model as DynamicArgument<MastraModelConfig, TRequestContext> | undefined,
});
const modelInfo = llm.getModel();
if (!isSupportedLanguageModel(modelInfo)) {
const modelId = modelInfo.modelId || 'unknown';
const provider = modelInfo.provider || 'unknown';
const specVersion = modelInfo.specificationVersion;
throw new MastraError({
id: 'AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED',
domain: ErrorDomain.AGENT,
category: ErrorCategory.USER,
text:
specVersion === 'v1'
? `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.`
: `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.`,
details: {
agentName: this.name,
modelId,
provider,
specificationVersion: specVersion,
},
});
}
const executeOptions = {
...loopOptions,View on GitHub (pinned to 75dd419e61)
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.
Example fix
// before
import { openai } from '@ai-sdk/openai@0.x'; // v1-spec model
await agent.generate('hi');
// after
import { openai } from '@ai-sdk/openai'; // v5, v2-spec model
await agent.generate('hi'); Defensive patterns
Strategy: validation
Validate before calling
const modelInfo = await resolveModelInfo(model); // or check model.specificationVersion
if (modelInfo?.specificationVersion === 'v1') {
throw new Error('Use agent.generateLegacy() for AI SDK v4 models');
} Type guard
function isV2Model(m: unknown): m is LanguageModelV2 {
return typeof m === 'object' && m !== null && (m as any).specificationVersion === 'v2';
} Try / catch
try {
await agent.generate(prompt);
} catch (e) {
if (e instanceof MastraError && e.id === 'AGENT_GENERATE_V1_MODEL_NOT_SUPPORTED') {
return agent.generateLegacy(prompt);
}
throw e;
} Prevention
- 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.
When it happens
Trigger: Calling agent.generate() (or .generateLegacy-adjacent paths) where the resolved modelInfo from isSupportedLanguageModel() fails, specifically when modelInfo.specificationVersion === 'v1'.
Common situations: 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.
Related errors
- AGENT_STREAM_V1_MODEL_NOT_SUPPORTED
- AGENT_GENERATE_FAILED
- AGENT_GENERATE_UNKNOWN_ERROR
- AGENT_GENERATE_MALFORMED_RESULT
- PROCESSOR_RETURNED_UNSUPPORTED_MODEL
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/826d31a03be75269.
Report an issue: GitHub.