{"record":{"id":"fdccac5da48f5ee0","repo":"vercel/ai","slug":"the-azure-openai-model-function-cannot-be-called-w","errorCode":null,"errorMessage":"The Azure OpenAI model function cannot be called with the new keyword.","messagePattern":"The Azure OpenAI model function cannot be called with the new keyword\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/azure/src/azure-openai-provider.ts","lineNumber":322,"sourceCode":"  const createTranscriptionModel = (modelId: string) =>\n    new OpenAITranscriptionModel(modelId, {\n      provider: 'azure.transcription',\n      url,\n      headers: getHeaders,\n      fetch,\n    });\n\n  const createSpeechModel = (modelId: string) =>\n    new OpenAISpeechModel(modelId, {\n      provider: 'azure.speech',\n      url,\n      headers: getHeaders,\n      fetch,\n    });\n\n  const provider = function (deploymentId: string) {\n    if (new.target) {\n      throw new Error(\n        'The Azure OpenAI model function cannot be called with the new keyword.',\n      );\n    }\n\n    return createResponsesModel(deploymentId);\n  };\n\n  provider.specificationVersion = 'v4' as const;\n  provider.languageModel = createResponsesModel;\n  provider.chat = createChatModel;\n  provider.deepseek = createDeepSeekModel;\n  provider.completion = createCompletionModel;\n  provider.embedding = createEmbeddingModel;\n  provider.embeddingModel = createEmbeddingModel;\n  provider.textEmbedding = createEmbeddingModel;\n  provider.textEmbeddingModel = createEmbeddingModel;\n  provider.image = createImageModel;\n  provider.imageModel = createImageModel;","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/azure/src/azure-openai-provider.ts#L304-L340","documentation":"The Azure provider object is a plain function (deploymentId) => model. JavaScript allows calling plain functions with `new`, which would break the intended return value, so the provider checks new.target and throws. Call the function normally, without `new`.","triggerScenarios":"Writing `new azure('my-deployment')` or `const M = azure; new M('gpt-4o')` — invoking the provider function as a constructor.","commonSituations":"Copy-pasting class-style provider usage from other SDKs; confusion between factory functions and model classes.","solutions":["Remove the `new` keyword and call azure(deploymentId) directly.","For named model kinds, use azure.chat(deploymentId), azure.responses(deploymentId), azure.completion(deploymentId), or azure.embedding(deploymentId)."],"exampleFix":"// before\nconst model = new azure('gpt-4o');\n// after\nconst model = azure('gpt-4o'); // or azure.chat('gpt-4o')","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call the provider as a plain function: azure('deployment-id').","Avoid patterns like `new provider(...)` copied from class-based SDKs.","Prefer explicit accessors like azure.chat(id) for clarity."],"tags":["javascript","api-usage","azure"],"backgroundTag":"constructor-misuse","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}