vercel/ai · error · Error
The Google Generative AI model function cannot be called wit
Error message
The Google Generative AI model function cannot be called with the new keyword.
What it means
The Google provider's default export is a plain function that creates chat models; calling it with `new` is not supported and throws this error immediately. This guards against JS/TS users mistakenly treating the factory as a class constructor.
Source
Thrown at packages/google/src/google-provider.ts:401
modelIdOrAgent:
| GoogleInteractionsModelId
| { agent: GoogleInteractionsAgentName }
| { managedAgent: string },
) =>
new GoogleInteractionsLanguageModel(
modelIdOrAgent as GoogleInteractionsModelInput,
{
provider: `${providerName}.interactions`,
baseURL,
headers: getHeaders,
generateId: options.generateId ?? generateId,
fetch: options.fetch,
},
);
const provider = function (modelId: GoogleModelId) {
if (new.target) {
throw new Error(
'The Google Generative AI model function cannot be called with the new keyword.',
);
}
return createChatModel(modelId);
};
provider.specificationVersion = 'v4' as const;
provider.languageModel = createChatModel;
provider.chat = createChatModel;
provider.generativeAI = createChatModel;
provider.embedding = createEmbeddingModel;
provider.embeddingModel = createEmbeddingModel;
provider.textEmbedding = createEmbeddingModel;
provider.textEmbeddingModel = createEmbeddingModel;
provider.image = createImageModel;
provider.imageModel = createImageModel;
provider.video = createVideoModel;View on GitHub (pinned to 69428b1f8b)
Solutions
- Call the provider function without `new`: `const model = google('gemini-2.0-flash')`
- If constructing a custom provider instance, also call createGoogleGenerativeAI without `new`
- Fix any code (or transpilation setting) that emits `new` for this factory
Example fix
// before
const model = new google('gemini-2.0-flash');
// after
const model = google('gemini-2.0-flash'); Defensive patterns
Strategy: type-guard
Validate before calling
if (typeof google !== 'function') {
throw new Error('google provider must be a callable factory');
} Try / catch
let model;
try {
model = google('gemini-2.0-flash');
} catch (error) {
if (error instanceof Error && error.message.includes('new keyword')) {
model = google('gemini-2.0-flash'); // call without new
} else throw error;
} Prevention
- Never use `new` with AI SDK provider factories
- Rely on TypeScript types — the provider is typed as a function, so `new` fails type-checking
- Enable strict TS settings so misuse is caught at compile time
When it happens
Trigger: Writing `new google('gemini-2.0-flash')` or `new createGoogleGenerativeAI(...)('...')` — i.e., invoking the provider function or returned model factory with the `new` keyword.
Common situations: Copy-pasting older provider patterns that used classes; TypeScript code where the provider was assumed to be a constructor; transpiled code emitting `new` calls.
Related errors
- Unsupported model version ${options.version} for provider "$
- The provider does not support file uploads. Make sure it exp
- The provider does not support skills. Make sure it exposes a
- The Alibaba model function cannot be called with the new key
- Unsupported role: ${_exhaustiveCheck}
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/e0baa883477e27d8.
Report an issue: GitHub.