mastra-ai/mastra · error · MastraError

AGENT_STREAM_V1_MODEL_NOT_SUPPORTED

AGENT_STREAM_V1_MODEL_NOT_SUPPORTED

Error message

Agent "${this.name}" is using AI SDK v4 model (${provider}:${modelId}) which is not compatible with stream(). Please use AI SDK v5+ models or call the streamLegacy() method instead. See https://mastra.ai/en/docs/streaming/overview for more information.

What it means

Agent.stream() only supports AI SDK v5 (LanguageModelV2) models. When the resolved model has specificationVersion 'v1' (AI SDK v4), Mastra throws AGENT_STREAM_V1_MODEL_NOT_SUPPORTED and points you to AI SDK v5 models or the streamLegacy() method. This mirrors the generate() check but for the streaming path.

Source

Thrown at packages/core/src/agent/agent.ts:8642

      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_STREAM_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 stream(). Please use AI SDK v5+ models or call the streamLegacy() 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 threadStreamPubSub = this.getPubSub();
    mergedOptions.runId ??=

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Upgrade the AI SDK provider package so the model reports specificationVersion 'v2'.
  2. Switch the call to agent.streamLegacy() if you must keep the v4 model.
  3. Audit custom model wrappers to ensure they emit the v2 spec.

Example fix

// before
import { openai } from '@ai-sdk/openai@0.x';
await agent.stream('hi');
// after
import { openai } from '@ai-sdk/openai';
await agent.stream('hi'); // or agent.streamLegacy('hi') with the v4 model
Defensive patterns

Strategy: validation

Validate before calling

const modelInfo = await resolveModelInfo(model);
if (modelInfo?.specificationVersion === 'v1') {
  throw new Error('Use agent.streamLegacy() 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.stream(prompt);
} catch (e) {
  if (e instanceof MastraError && e.id === 'AGENT_STREAM_V1_MODEL_NOT_SUPPORTED') {
    return agent.streamLegacy(prompt);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling agent.stream() where isSupportedLanguageModel(modelInfo) fails with specificationVersion === 'v1' — i.e. an AI SDK v4 model instance was passed or resolved from the model config.

Common situations: Using @ai-sdk/openai@0.x (v1 spec) with current Mastra; custom LangChain-bridged or wrapped providers pinned to v1; partial upgrades where generate was migrated to v5 models but stream still resolves an old model.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/8345bc91bdfe4633. Report an issue: GitHub.