vercel/ai · error
The Anthropic AWS model function cannot be called with the n
Error message
The Anthropic AWS model function cannot be called with the new keyword.
What it means
The Anthropic AWS provider returned by `createAnthropicAws()` is a factory function, not a constructor. Calling it with `new` is detected via `new.target` and rejected with this error so users get a clear message instead of a silently broken model object.
Source
Thrown at packages/anthropic-aws/src/anthropic-aws-provider.ts:245
...options.headers,
});
const createChatModel = (modelId: AnthropicModelId) =>
new AnthropicLanguageModel(modelId, {
provider: 'anthropic-aws.messages',
baseURL: getBaseURL(),
headers: getHeaders,
fetch: fetchFunction,
generateId: options.generateId,
supportedUrls: () => ({
'image/*': [/^https?:\/\/.*$/],
'application/pdf': [/^https?:\/\/.*$/],
}),
});
const provider = function (modelId: AnthropicModelId) {
if (new.target) {
throw new Error(
'The Anthropic AWS 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
- Call the provider as a plain function: `anthropicAws('claude-sonnet-4-...')`.
- Remove `new` wherever the provider is invoked, including inside helpers that construct models.
- Consult current @ai-sdk/anthropic-aws docs for the factory-call pattern.
Example fix
// before
const model = new anthropicAws('claude-sonnet-4-20250514');
// after
const model = anthropicAws('claude-sonnet-4-20250514'); Defensive patterns
Strategy: validation
Validate before calling
if (typeof anthropicAws !== 'function') throw new Error('anthropicAws must be called as a function, not constructed');
const model = anthropicAws('claude-sonnet-4-20250514'); Type guard
function isProviderFactory(v: unknown): v is (modelId: string, settings?: unknown) => unknown {
return typeof v === 'function' && !/^class\s/.test(String(v));
} Try / catch
try {
const model = anthropicAws('claude-sonnet-4-20250514');
} catch (e) {
if (e instanceof Error && e.message.includes('cannot be called with the new keyword')) {
// drop the `new` keyword at the call site
}
throw e;
} Prevention
- Never instantiate AI SDK providers with `new`.
- Add a lint/grep rule against `new anthropicAws`.
- Follow current provider docs instead of class-based examples.
When it happens
Trigger: Writing `new anthropicAws('claude-...')` or `new anthropic('model-id', {...})` with the AWS provider, typically copying old constructor-style provider code.
Common situations: Migrating from older SDKs where providers were classes; IDE auto-completing with `new`; LLM-generated boilerplate using `new` on provider factories.
Related errors
- The Bedrock Mantle model function cannot be called with the
- Unsupported role: ${_exhaustiveCheck}
- The Google Vertex xAI model function cannot be called with t
- 'element streams in no-schema mode' functionality not suppor
- 'element streams in object mode' functionality not supported
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/0d91611515b471a7.
Report an issue: GitHub.