vercel/ai · error · Error
The Google Vertex xAI model function cannot be called with t
Error message
The Google Vertex xAI model function cannot be called with the new keyword.
What it means
The Google Vertex xAI provider export is a callable function, not a class. Calling it with `new` (e.g. `new googleVertex.xai(...)`) is explicitly rejected because the factory creates model instances via closure state and is not designed as a constructor. This guard gives a clear message instead of a confusing runtime failure inside the factory.
Source
Thrown at packages/google-vertex/src/xai/google-vertex-xai-provider.ts:191
(cachedProvider ??= createOpenAICompatible({
name: 'googleVertex.xai',
baseURL: loadBaseURL(),
fetch: options.fetch,
includeUsage: true,
supportsStructuredOutputs: true,
supportedUrls: () => ({
'image/*': [/^https?:\/\/.*$/],
}),
transformRequestBody: transformGoogleVertexXaiRequestBody,
convertUsage: convertGoogleVertexXaiUsage,
}));
const createChatModel = (modelId: GoogleVertexXaiModelId) =>
getProvider().languageModel(modelId);
const provider = function (modelId: GoogleVertexXaiModelId) {
if (new.target) {
throw new Error(
'The Google Vertex xAI model function cannot be called with the new keyword.',
);
}
return createChatModel(modelId);
};
provider.specificationVersion = 'v4' as const;
provider.languageModel = createChatModel;
provider.chatModel = (modelId: GoogleVertexXaiModelId) =>
getProvider().chatModel(modelId);
provider.embeddingModel = (modelId: string): never => {
throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });
};
provider.textEmbeddingModel = provider.embeddingModel;
provider.imageModel = (modelId: string): never => {
throw new NoSuchModelError({ modelId, modelType: 'imageModel' });
};View on GitHub (pinned to 69428b1f8b)
Solutions
- Remove the `new` keyword and call the provider directly: `const model = googleVertex.xai('grok-3')`.
- If constructing the provider itself, use the factory `createGoogleVertexXAI({ ... })` or `createGoogleVertex({ ... })` without `new`.
- Update older class-based provider examples/snippets to the current function-call style.
Example fix
// before
const model = new googleVertex.xai('grok-3-pro');
// after
const model = googleVertex.xai('grok-3-pro'); Defensive patterns
Strategy: validation
Validate before calling
function isProviderFunction(fn) { return typeof fn === 'function' && !fn.prototype; }
// always call without new:
const model = googleVertex.xai('grok-3-pro'); Type guard
function isCallableProvider(v) { return typeof v === 'function' && !(v.prototype && Object.getOwnPropertyNames(v.prototype).length > 0); } Try / catch
try {
const model = googleVertex.xai(modelId);
} catch (e) {
if (e instanceof Error && e.message.includes('cannot be called with the new keyword')) {
const model = googleVertex.xai(modelId); // retry without new
} else throw e;
} Prevention
- Treat all AI SDK providers as factory functions, never classes.
- Enable lint rule 'no-new' for provider modules.
- Update legacy `new Provider()` snippets when upgrading SDK versions.
When it happens
Trigger: Writing `new googleVertex('model-id')` or `new googleVertex.xai('grok-...')` where googleVertex.xai is the provider function defined at packages/google-vertex/src/xai/google-vertex-xai-provider.ts:191. Detected via `new.target` inside the provider function.
Common situations: Migrating code that used a class-style provider (`new Vertex(...)`) to the current function-style factory API; copying provider examples from older blog posts; TypeScript users treating the provider as a constructor type.
Related errors
- The Bedrock Mantle model function cannot be called with the
- The Anthropic AWS model function cannot be called with the n
- The Google Vertex AI model function cannot be called with th
- 'element streams in no-schema mode' functionality not suppor
- 'element streams in object mode' functionality not supported
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/42de257451e4b4c9.
Report an issue: GitHub.