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

  1. Remove the `new` keyword and call azure(deploymentId) directly.
  2. 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

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


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