vercel/ai · error
The Azure OpenAI model function cannot be called with the ne
Error message
The Azure OpenAI model function cannot be called with the new keyword.
What it means
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`.
Source
Thrown at packages/azure/src/azure-openai-provider.ts:322
const createTranscriptionModel = (modelId: string) =>
new OpenAITranscriptionModel(modelId, {
provider: 'azure.transcription',
url,
headers: getHeaders,
fetch,
});
const createSpeechModel = (modelId: string) =>
new OpenAISpeechModel(modelId, {
provider: 'azure.speech',
url,
headers: getHeaders,
fetch,
});
const provider = function (deploymentId: string) {
if (new.target) {
throw new Error(
'The Azure OpenAI model function cannot be called with the new keyword.',
);
}
return createResponsesModel(deploymentId);
};
provider.specificationVersion = 'v4' as const;
provider.languageModel = createResponsesModel;
provider.chat = createChatModel;
provider.deepseek = createDeepSeekModel;
provider.completion = createCompletionModel;
provider.embedding = createEmbeddingModel;
provider.embeddingModel = createEmbeddingModel;
provider.textEmbedding = createEmbeddingModel;
provider.textEmbeddingModel = createEmbeddingModel;
provider.image = createImageModel;
provider.imageModel = createImageModel;View on GitHub (pinned to 69428b1f8b)
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).
Example fix
// before
const model = new azure('gpt-4o');
// after
const model = azure('gpt-4o'); // or azure.chat('gpt-4o') Defensive patterns
Strategy: validation
Prevention
- 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.
When it happens
Trigger: Writing `new azure('my-deployment')` or `const M = azure; new M('gpt-4o')` — invoking the provider function as a constructor.
Common situations: Copy-pasting class-style provider usage from other SDKs; confusion between factory functions and model classes.
Related errors
- The Amazon Bedrock model function cannot be called with the
- The Bedrock Anthropic model function cannot be called with t
- The Alibaba model function cannot be called with the new key
- The Anthropic model function cannot be called with the new k
- Both apiKey and tokenProvider were provided. Please use only
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/fdccac5da48f5ee0.
Report an issue: GitHub.