vercel/ai · error
The Amazon Bedrock model function cannot be called with the
Error message
The Amazon Bedrock model function cannot be called with the new keyword.
What it means
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.
Source
Thrown at packages/amazon-bedrock/src/amazon-bedrock-provider.ts:320
`https://bedrock-agent-runtime.${loadSetting({
settingValue: options.region,
settingName: 'region',
environmentVariableName: 'AWS_REGION',
description: 'AWS region',
})}.amazonaws.com`,
) ?? `https://bedrock-agent-runtime.us-west-2.amazonaws.com`;
const createChatModel = (modelId: AmazonBedrockChatModelId) =>
new AmazonBedrockChatLanguageModel(modelId, {
baseUrl: getAmazonBedrockRuntimeBaseUrl,
headers: getHeaders,
fetch: fetchFunction,
generateId,
});
const provider = function (modelId: AmazonBedrockChatModelId) {
if (new.target) {
throw new Error(
'The Amazon Bedrock model function cannot be called with the new keyword.',
);
}
return createChatModel(modelId);
};
const createEmbeddingModel = (
modelId: AmazonBedrockEmbeddingModelId,
settings: AmazonBedrockEmbeddingModelSettings = {},
) =>
new AmazonBedrockEmbeddingModel(modelId, {
baseUrl: getAmazonBedrockRuntimeBaseUrl,
headers: getHeaders,
fetch: fetchFunction,
modelFamily: settings.modelFamily,
});
View on GitHub (pinned to 69428b1f8b)
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.
Example fix
// before
const model = new bedrock('anthropic.claude-3-sonnet-20240229-v1:0');
// after
const model = bedrock('anthropic.claude-3-sonnet-20240229-v1:0'); Defensive patterns
Strategy: validation
Validate before calling
if (typeof bedrock !== 'function') throw new Error('Import createAmazonBedrock and call it as a factory function, not with new.'); Type guard
function isProviderFunction(x: unknown): x is (modelId: string) => unknown {
return typeof x === 'function';
} Try / catch
try {
const model = (bedrock as any)(modelId); // never `new bedrock(...)`
} catch (error) {
if (error instanceof Error && error.message.includes('new keyword')) {
throw new Error('Call the provider as a plain function: bedrock(modelId), not new bedrock(modelId).');
}
throw error;
} Prevention
- 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.
When it happens
Trigger: Writing `new bedrock('anthropic.claude-3-sonnet-20240229-v1:0')` or `new amazonBedrock(modelId)` — invoking the provider function with the new operator.
Common situations: Confusing the provider function with a model class from other SDKs; copy-paste from code using classes; accidental capitalization style suggesting a constructor.
Related errors
- The Bedrock Anthropic model function cannot be called with t
- The Alibaba model function cannot be called with the new key
- The Azure OpenAI model function cannot be called with the ne
- Unsupported model version ${options.version} for provider "$
- The provider does not support file uploads. Make sure it exp
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/db85d1227208ca42.
Report an issue: GitHub.