vercel/ai · error · Error
The Alibaba model function cannot be called with the new key
Error message
The Alibaba model function cannot be called with the new keyword.
What it means
The default export of @ai-sdk/alibaba is a plain callable function that creates chat models (alibaba('qwen-...')). JavaScript's new.target detection is used to throw a helpful error when a developer accidentally invokes it as a constructor, which would otherwise silently break.
Source
Thrown at packages/alibaba/src/alibaba-provider.ts:164
const createEmbeddingModel = (modelId: AlibabaEmbeddingModelId) =>
new AlibabaEmbeddingModel(modelId, {
provider: 'alibaba.embedding',
baseURL: embeddingBaseURL,
headers: getHeaders,
fetch: options.fetch,
});
const createVideoModel = (modelId: AlibabaVideoModelId) =>
new AlibabaVideoModel(modelId, {
provider: 'alibaba.video',
baseURL: videoBaseURL,
headers: getHeaders,
fetch: options.fetch,
});
const provider = function (modelId: AlibabaChatModelId) {
if (new.target) {
throw new Error(
'The Alibaba model function cannot be called with the new keyword.',
);
}
return createLanguageModel(modelId);
};
provider.specificationVersion = 'v4' as const;
provider.languageModel = createLanguageModel;
provider.chatModel = createLanguageModel;
provider.embedding = createEmbeddingModel;
provider.embeddingModel = createEmbeddingModel;
provider.video = createVideoModel;
provider.videoModel = createVideoModel;
provider.imageModel = (modelId: string) => {
throw new NoSuchModelError({ modelId, modelType: 'imageModel' });
};View on GitHub (pinned to 69428b1f8b)
Solutions
- Remove the `new` keyword and call the provider directly: alibaba('qwen-max')
- For instance-style usage, use createAlibaba({ apiKey, baseURL }) as a plain function
- Create models via alibaba.chat('qwen-max') or alibaba.languageModel('qwen-max')
Example fix
// before
const model = new alibaba('qwen-max');
// after
const model = alibaba('qwen-max'); Defensive patterns
Strategy: type-guard
Validate before calling
// call-time guard not applicable; check call syntax before running
Type guard
// not applicable — the library itself detects new.target at runtime
Try / catch
try {
const model = alibaba('qwen-max');
} catch (e) {
if (e instanceof Error && e.message.includes('cannot be called with the new keyword')) {
// remove `new` and retry
}
} Prevention
- Treat AI SDK providers as factory functions, never constructors
- Use createAlibaba() for custom config instead of instantiating
- Follow current AI SDK docs (v5+ removed constructor-style providers)
When it happens
Trigger: Writing new alibaba('qwen-max') or class Foo extends alibaba — any call where the function is invoked via `new`.
Common situations: Habit from other provider SDKs where provider classes are instantiated (e.g. `new OpenAI()`), or code migrated from older AI SDK versions with constructor-style providers.
Related errors
- The Amazon Bedrock model function cannot be called with the
- The Bedrock Anthropic model function cannot be called with t
- Unsupported model version ${options.version} for provider "$
- The provider does not support file uploads. Make sure it exp
- The provider does not support skills. Make sure it exposes a
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/ae2a82a5193cb01a.
Report an issue: GitHub.