vercel/ai · error · Error
The Google Vertex AI model function cannot be called with th
Error message
The Google Vertex AI model function cannot be called with the new keyword.
What it means
The Vertex provider is a callable function, not a class constructor. The provider function checks `new.target` and throws this Error if it is invoked with `new`. This guards against JavaScript users treating the factory like a class.
Source
Thrown at packages/google-vertex/src/google-vertex-provider-base.ts:398
fetch: config.fetch,
webSocket: options.webSocket,
project: loadGoogleVertexProject(),
location: loadGoogleVertexLocation(),
});
}
return new GoogleVertexTranscriptionModel(modelId, {
provider: config.provider,
headers: config.headers,
fetch: config.fetch,
project: loadGoogleVertexProject(),
location: loadGoogleVertexLocation(),
});
};
const provider = function (modelId: GoogleVertexModelId) {
if (new.target) {
throw new Error(
'The Google Vertex AI model function cannot be called with the new keyword.',
);
}
return createChatModel(modelId);
};
provider.specificationVersion = 'v4' as const;
provider.languageModel = createChatModel;
provider.interactions = createInteractionsModel;
provider.embeddingModel = createEmbeddingModel;
provider.textEmbeddingModel = createEmbeddingModel;
provider.image = createImageModel;
provider.imageModel = createImageModel;
provider.video = createVideoModel;
provider.videoModel = createVideoModel;
provider.speech = createSpeechModel;
provider.speechModel = createSpeechModel;View on GitHub (pinned to 69428b1f8b)
Solutions
- Remove the `new` keyword and call the provider directly: vertex('model-id').
- Call vertex.chat(modelId) explicitly if you want the chat entry point.
- For provider construction itself, call createGoogleVertex(options) without `new`.
Example fix
// before
const model = new vertex('gemini-2.0-flash');
// after
const model = vertex('gemini-2.0-flash'); Defensive patterns
Strategy: type-guard
Validate before calling
if (typeof vertex !== 'function') throw new Error('vertex provider must be called as a function, not constructed.'); Type guard
function isProviderFunction(v: unknown): v is (modelId: string) => LanguageModel {
return typeof v === 'function';
} Prevention
- Never use `new` with AI SDK provider factories; they are plain callables.
- Enable TypeScript so `new vertex(...)` is caught at compile time.
- When migrating from class-based Google clients, drop constructor patterns for factory calls.
When it happens
Trigger: Writing `new vertex('gemini-2.0-flash')` (or `new createGoogleVertex(...)`) in JS/TS — the `if (new.target)` branch throws instead of silently producing a broken object.
Common situations: Plain JavaScript callers mirroring class-style provider code from other libraries; refactoring from an older class-based client (e.g. VertexAI from @google-cloud/vertexai) where `new` was required; accidental `new` added by autocomplete or codemods.
Related errors
- The Anthropic model function cannot be called with the new k
- The Google Vertex xAI model function cannot be called with t
- 'element streams in no-schema mode' functionality not suppor
- 'element streams in object mode' functionality not supported
- 'element streams in enum mode' functionality not supported.
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/191a2ae9258681ea.
Report an issue: GitHub.