{"record":{"id":"db85d1227208ca42","repo":"vercel/ai","slug":"the-amazon-bedrock-model-function-cannot-be-called","errorCode":null,"errorMessage":"The Amazon Bedrock model function cannot be called with the new keyword.","messagePattern":"The Amazon Bedrock model function cannot be called with the new keyword\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/amazon-bedrock/src/amazon-bedrock-provider.ts","lineNumber":320,"sourceCode":"        `https://bedrock-agent-runtime.${loadSetting({\n          settingValue: options.region,\n          settingName: 'region',\n          environmentVariableName: 'AWS_REGION',\n          description: 'AWS region',\n        })}.amazonaws.com`,\n    ) ?? `https://bedrock-agent-runtime.us-west-2.amazonaws.com`;\n\n  const createChatModel = (modelId: AmazonBedrockChatModelId) =>\n    new AmazonBedrockChatLanguageModel(modelId, {\n      baseUrl: getAmazonBedrockRuntimeBaseUrl,\n      headers: getHeaders,\n      fetch: fetchFunction,\n      generateId,\n    });\n\n  const provider = function (modelId: AmazonBedrockChatModelId) {\n    if (new.target) {\n      throw new Error(\n        'The Amazon Bedrock model function cannot be called with the new keyword.',\n      );\n    }\n\n    return createChatModel(modelId);\n  };\n\n  const createEmbeddingModel = (\n    modelId: AmazonBedrockEmbeddingModelId,\n    settings: AmazonBedrockEmbeddingModelSettings = {},\n  ) =>\n    new AmazonBedrockEmbeddingModel(modelId, {\n      baseUrl: getAmazonBedrockRuntimeBaseUrl,\n      headers: getHeaders,\n      fetch: fetchFunction,\n      modelFamily: settings.modelFamily,\n    });\n","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/amazon-bedrock/src/amazon-bedrock-provider.ts#L302-L338","documentation":"The exported `bedrock` (createAmazonBedrock result) is a plain function that maps a model ID to a chat model instance. JavaScript allows calling plain functions with `new`, which would return a corrupted object, so the provider detects `new.target` and throws immediately. Call it as a normal function instead.","triggerScenarios":"Writing `new bedrock('anthropic.claude-3-sonnet-20240229-v1:0')` or `new amazonBedrock(modelId)` — invoking the provider function with the new operator.","commonSituations":"Confusing the provider function with a model class from other SDKs; copy-paste from code using classes; accidental capitalization style suggesting a constructor.","solutions":["Remove the `new` keyword and call the provider function directly.","Assign the result to a lowercase variable (e.g. `bedrock`) to signal it is a factory, not a class."],"exampleFix":"// before\nconst model = new bedrock('anthropic.claude-3-sonnet-20240229-v1:0');\n// after\nconst model = bedrock('anthropic.claude-3-sonnet-20240229-v1:0');","handlingStrategy":"validation","validationCode":"if (typeof bedrock !== 'function') throw new Error('Import createAmazonBedrock and call it as a factory function, not with new.');","typeGuard":"function isProviderFunction(x: unknown): x is (modelId: string) => unknown {\n  return typeof x === 'function';\n}","tryCatchPattern":"try {\n  const model = (bedrock as any)(modelId); // never `new bedrock(...)`\n} catch (error) {\n  if (error instanceof Error && error.message.includes('new keyword')) {\n    throw new Error('Call the provider as a plain function: bedrock(modelId), not new bedrock(modelId).');\n  }\n  throw error;\n}","preventionTips":["Name provider instances in lowercase (bedrock, not Bedrock) to signal factory usage.","Review imports from other SDKs where providers are classes.","Add a lint/comment note when wrapping provider creation in helper classes."],"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"}