vercel/ai · error

The Bedrock Mantle model function cannot be called with the

Error message

The Bedrock Mantle model function cannot be called with the new keyword.

What it means

The Bedrock Mantle provider is a plain factory function, not a class constructor. This library throws this error when the returned provider is invoked with `new`, which would otherwise silently produce a broken object instead of a chat model.

Source

Thrown at packages/amazon-bedrock/src/mantle/bedrock-mantle-provider.ts:256

  const createChatModel = (modelId: BedrockMantleChatModelId) =>
    new OpenAIChatLanguageModel(modelId, {
      provider: 'bedrock-mantle.chat',
      url,
      headers: getHeaders,
      fetch: fetchFunction,
    });

  const createResponsesModel = (modelId: BedrockMantleResponsesModelId) =>
    new OpenAIResponsesLanguageModel(modelId, {
      provider: 'bedrock-mantle.responses',
      url,
      headers: getHeaders,
      fetch: fetchFunction,
    });

  const provider = function (modelId: BedrockMantleChatModelId) {
    if (new.target) {
      throw new Error(
        'The Bedrock Mantle model function cannot be called with the new keyword.',
      );
    }

    return createChatModel(modelId);
  };

  provider.specificationVersion = 'v4' as const;
  provider.languageModel = createChatModel;
  provider.chat = createChatModel;
  provider.responses = createResponsesModel;

  provider.embeddingModel = (modelId: string) => {
    throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });
  };
  provider.textEmbeddingModel = provider.embeddingModel;
  provider.imageModel = (modelId: string) => {
    throw new NoSuchModelError({ modelId, modelType: 'imageModel' });

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Remove the `new` keyword and call the provider as a plain function: `bedrockMantle('model-id')`.
  2. Check that you are using the provider factory exported by `@ai-sdk/amazon-bedrock` (mantle entry) per current docs.
  3. Wrap the call in a helper if you need lazy model creation, but never instantiate it.

Example fix

// before
const model = new bedrockMantle('anthropic.claude-...');
// after
const model = bedrockMantle('anthropic.claude-...');
Defensive patterns

Strategy: validation

Validate before calling

function createModel(provider: Function, id: string) {
  if (/^class\s/.test(String(provider))) throw new TypeError('Provider is not constructable; call it without `new`.');
  return provider(id);
}

Type guard

function isProviderFunction(v: unknown): v is (modelId: string) => unknown {
  return typeof v === 'function' && !/^class\s/.test(String(v));
}

Try / catch

try {
  const model = bedrockMantle('model-id');
} catch (e) {
  if (e instanceof Error && e.message.includes('cannot be called with the new keyword')) {
    // remove `new` at the call site
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling the provider returned by `createBedrockMantle()` with the `new` keyword, e.g. `new bedrockMantle('model-id')`, detected via `new.target` inside the provider function.

Common situations: Copy-pasting OpenAI SDK v3 style code (`new OpenAI(...)`) or assuming the provider is a class; mixing constructor-style instantiation from older AI SDK patterns.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/db11b184c0062447. Report an issue: GitHub.