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

  1. Remove the `new` keyword and call the provider function directly.
  2. 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

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


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