{"record":{"id":"ae2a82a5193cb01a","repo":"vercel/ai","slug":"the-alibaba-model-function-cannot-be-called-with-t","errorCode":null,"errorMessage":"The Alibaba model function cannot be called with the new keyword.","messagePattern":"The Alibaba model function cannot be called with the new keyword\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/alibaba/src/alibaba-provider.ts","lineNumber":164,"sourceCode":"  const createEmbeddingModel = (modelId: AlibabaEmbeddingModelId) =>\n    new AlibabaEmbeddingModel(modelId, {\n      provider: 'alibaba.embedding',\n      baseURL: embeddingBaseURL,\n      headers: getHeaders,\n      fetch: options.fetch,\n    });\n\n  const createVideoModel = (modelId: AlibabaVideoModelId) =>\n    new AlibabaVideoModel(modelId, {\n      provider: 'alibaba.video',\n      baseURL: videoBaseURL,\n      headers: getHeaders,\n      fetch: options.fetch,\n    });\n\n  const provider = function (modelId: AlibabaChatModelId) {\n    if (new.target) {\n      throw new Error(\n        'The Alibaba model function cannot be called with the new keyword.',\n      );\n    }\n\n    return createLanguageModel(modelId);\n  };\n\n  provider.specificationVersion = 'v4' as const;\n  provider.languageModel = createLanguageModel;\n  provider.chatModel = createLanguageModel;\n  provider.embedding = createEmbeddingModel;\n  provider.embeddingModel = createEmbeddingModel;\n  provider.video = createVideoModel;\n  provider.videoModel = createVideoModel;\n\n  provider.imageModel = (modelId: string) => {\n    throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n  };","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/alibaba/src/alibaba-provider.ts#L146-L182","documentation":"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.","triggerScenarios":"Writing new alibaba('qwen-max') or class Foo extends alibaba — any call where the function is invoked via `new`.","commonSituations":"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.","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')"],"exampleFix":"// before\nconst model = new alibaba('qwen-max');\n// after\nconst model = alibaba('qwen-max');","handlingStrategy":"type-guard","validationCode":"// call-time guard not applicable; check call syntax before running","typeGuard":"// not applicable — the library itself detects new.target at runtime","tryCatchPattern":"try {\n  const model = alibaba('qwen-max');\n} catch (e) {\n  if (e instanceof Error && e.message.includes('cannot be called with the new keyword')) {\n    // remove `new` and retry\n  }\n}","preventionTips":["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)"],"tags":["typescript","api-usage","constructor"],"backgroundTag":"provider-called-with-new","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}