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

  1. Remove the `new` keyword and call the provider directly: alibaba('qwen-max')
  2. For instance-style usage, use createAlibaba({ apiKey, baseURL }) as a plain function
  3. 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

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


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