vercel/ai · error

The Bedrock Anthropic model function cannot be called with t

Error message

The Bedrock Anthropic model function cannot be called with the new keyword.

What it means

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.

Source

Thrown at packages/amazon-bedrock/src/anthropic/amazon-bedrock-anthropic-provider.ts:355

          ...(transformedToolChoice != null
            ? { tool_choice: transformedToolChoice }
            : {}),
          ...(requiredBetas.size > 0
            ? { anthropic_beta: Array.from(requiredBetas) }
            : {}),
          anthropic_version: 'bedrock-2023-05-31',
        };
      },

      // Bedrock Anthropic doesn't support URL sources, force download and base64 conversion
      supportedUrls: () => ({}),
      supportsNativeStructuredOutput: supportsNativeStructuredOutput(modelId),
      supportsStrictTools: supportsStrictTools(modelId),
    });

  const provider = function (modelId: AmazonBedrockAnthropicModelId) {
    if (new.target) {
      throw new Error(
        'The Bedrock Anthropic model function cannot be called with the new keyword.',
      );
    }

    return createChatModel(modelId);
  };

  provider.specificationVersion = 'v4' as const;
  provider.languageModel = createChatModel;
  provider.chat = createChatModel;
  provider.messages = createChatModel;

  provider.embeddingModel = (modelId: string) => {
    throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });
  };
  provider.textEmbeddingModel = provider.embeddingModel;
  provider.imageModel = (modelId: string) => {
    throw new NoSuchModelError({ modelId, modelType: 'imageModel' });

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Call the provider as a plain function without `new`.
  2. Store it in a lowercase-named variable to reinforce that it is a factory function.

Example fix

// before
const model = new amazonBedrockAnthropic('anthropic.claude-3-5-sonnet-20240620-v1:0');
// after
const model = amazonBedrockAnthropic('anthropic.claude-3-5-sonnet-20240620-v1:0');
Defensive patterns

Strategy: validation

Validate before calling

if (typeof amazonBedrockAnthropic !== 'function') {
  throw new Error('amazonBedrockAnthropic is a factory function; call it without new.');
}

Type guard

function isFactory(x: unknown): x is (modelId: string) => unknown {
  return typeof x === 'function';
}

Try / catch

try {
  const model = (amazonBedrockAnthropic as any)(modelId);
} catch (error) {
  if (error instanceof Error && error.message.includes('new keyword')) {
    throw new Error('Use amazonBedrockAnthropic(modelId) without new.');
  }
  throw error;
}

Prevention

When it happens

Trigger: Writing `new amazonBedrockAnthropic('anthropic.claude-v2')` or `new provider(modelId)` for the Bedrock Anthropic provider function.

Common situations: Assuming the export is a class from another SDK; IDE auto-complete suggesting constructor style; migrating code that wrapped model creation in a class.

Related errors


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