{"record":{"id":"db11b184c0062447","repo":"vercel/ai","slug":"the-bedrock-mantle-model-function-cannot-be-called","errorCode":null,"errorMessage":"The Bedrock Mantle model function cannot be called with the new keyword.","messagePattern":"The Bedrock Mantle model function cannot be called with the new keyword\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/amazon-bedrock/src/mantle/bedrock-mantle-provider.ts","lineNumber":256,"sourceCode":"  const createChatModel = (modelId: BedrockMantleChatModelId) =>\n    new OpenAIChatLanguageModel(modelId, {\n      provider: 'bedrock-mantle.chat',\n      url,\n      headers: getHeaders,\n      fetch: fetchFunction,\n    });\n\n  const createResponsesModel = (modelId: BedrockMantleResponsesModelId) =>\n    new OpenAIResponsesLanguageModel(modelId, {\n      provider: 'bedrock-mantle.responses',\n      url,\n      headers: getHeaders,\n      fetch: fetchFunction,\n    });\n\n  const provider = function (modelId: BedrockMantleChatModelId) {\n    if (new.target) {\n      throw new Error(\n        'The Bedrock Mantle model function cannot be called with the new keyword.',\n      );\n    }\n\n    return createChatModel(modelId);\n  };\n\n  provider.specificationVersion = 'v4' as const;\n  provider.languageModel = createChatModel;\n  provider.chat = createChatModel;\n  provider.responses = createResponsesModel;\n\n  provider.embeddingModel = (modelId: string) => {\n    throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n  };\n  provider.textEmbeddingModel = provider.embeddingModel;\n  provider.imageModel = (modelId: string) => {\n    throw new NoSuchModelError({ modelId, modelType: 'imageModel' });","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/amazon-bedrock/src/mantle/bedrock-mantle-provider.ts#L238-L274","documentation":"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.","triggerScenarios":"Calling the provider returned by `createBedrockMantle()` with the `new` keyword, e.g. `new bedrockMantle('model-id')`, detected via `new.target` inside the provider function.","commonSituations":"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.","solutions":["Remove the `new` keyword and call the provider as a plain function: `bedrockMantle('model-id')`.","Check that you are using the provider factory exported by `@ai-sdk/amazon-bedrock` (mantle entry) per current docs.","Wrap the call in a helper if you need lazy model creation, but never instantiate it."],"exampleFix":"// before\nconst model = new bedrockMantle('anthropic.claude-...');\n// after\nconst model = bedrockMantle('anthropic.claude-...');","handlingStrategy":"validation","validationCode":"function createModel(provider: Function, id: string) {\n  if (/^class\\s/.test(String(provider))) throw new TypeError('Provider is not constructable; call it without `new`.');\n  return provider(id);\n}","typeGuard":"function isProviderFunction(v: unknown): v is (modelId: string) => unknown {\n  return typeof v === 'function' && !/^class\\s/.test(String(v));\n}","tryCatchPattern":"try {\n  const model = bedrockMantle('model-id');\n} catch (e) {\n  if (e instanceof Error && e.message.includes('cannot be called with the new keyword')) {\n    // remove `new` at the call site\n  }\n  throw e;\n}","preventionTips":["Never use `new` with AI SDK provider factories.","Enable TypeScript and avoid patterns copied from class-based OpenAI v3 clients.","Search your codebase for `new bedrockMantle` / `new provider(` in lint rules."],"tags":["api-misuse","typescript","provider"],"backgroundTag":"illegal-new-invocation","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}