{"record":{"id":"38c33810e7451d9f","repo":"vercel/ai","slug":"the-bedrock-anthropic-model-function-cannot-be-cal","errorCode":null,"errorMessage":"The Bedrock Anthropic model function cannot be called with the new keyword.","messagePattern":"The Bedrock Anthropic model function cannot be called with the new keyword\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/amazon-bedrock/src/anthropic/amazon-bedrock-anthropic-provider.ts","lineNumber":355,"sourceCode":"          ...(transformedToolChoice != null\n            ? { tool_choice: transformedToolChoice }\n            : {}),\n          ...(requiredBetas.size > 0\n            ? { anthropic_beta: Array.from(requiredBetas) }\n            : {}),\n          anthropic_version: 'bedrock-2023-05-31',\n        };\n      },\n\n      // Bedrock Anthropic doesn't support URL sources, force download and base64 conversion\n      supportedUrls: () => ({}),\n      supportsNativeStructuredOutput: supportsNativeStructuredOutput(modelId),\n      supportsStrictTools: supportsStrictTools(modelId),\n    });\n\n  const provider = function (modelId: AmazonBedrockAnthropicModelId) {\n    if (new.target) {\n      throw new Error(\n        'The Bedrock Anthropic 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.messages = createChatModel;\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":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/amazon-bedrock/src/anthropic/amazon-bedrock-anthropic-provider.ts#L337-L373","documentation":"The result of createAmazonBedrockAnthropic is a factory function, not a constructor. Calling it with `new` is detected via `new.target` and rejected with this error so users do not get a subtly broken model object.","triggerScenarios":"Writing `new amazonBedrockAnthropic('anthropic.claude-v2')` or `new provider(modelId)` for the Bedrock Anthropic provider function.","commonSituations":"Assuming the export is a class from another SDK; IDE auto-complete suggesting constructor style; migrating code that wrapped model creation in a class.","solutions":["Call the provider as a plain function without `new`.","Store it in a lowercase-named variable to reinforce that it is a factory function."],"exampleFix":"// before\nconst model = new amazonBedrockAnthropic('anthropic.claude-3-5-sonnet-20240620-v1:0');\n// after\nconst model = amazonBedrockAnthropic('anthropic.claude-3-5-sonnet-20240620-v1:0');","handlingStrategy":"validation","validationCode":"if (typeof amazonBedrockAnthropic !== 'function') {\n  throw new Error('amazonBedrockAnthropic is a factory function; call it without new.');\n}","typeGuard":"function isFactory(x: unknown): x is (modelId: string) => unknown {\n  return typeof x === 'function';\n}","tryCatchPattern":"try {\n  const model = (amazonBedrockAnthropic as any)(modelId);\n} catch (error) {\n  if (error instanceof Error && error.message.includes('new keyword')) {\n    throw new Error('Use amazonBedrockAnthropic(modelId) without new.');\n  }\n  throw error;\n}","preventionTips":["Keep lowercase variable names for provider factory functions.","Search codebase for `new ` before provider identifiers during refactors.","Add a code comment at the provider definition site noting it is not a constructor."],"tags":["typescript","javascript","api-usage"],"backgroundTag":"invalid-constructor-call","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}