{"record":{"id":"191a2ae9258681ea","repo":"vercel/ai","slug":"the-google-vertex-ai-model-function-cannot-be-call","errorCode":null,"errorMessage":"The Google Vertex AI model function cannot be called with the new keyword.","messagePattern":"The Google Vertex AI model function cannot be called with the new keyword\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/google-vertex/src/google-vertex-provider-base.ts","lineNumber":398,"sourceCode":"        fetch: config.fetch,\n        webSocket: options.webSocket,\n        project: loadGoogleVertexProject(),\n        location: loadGoogleVertexLocation(),\n      });\n    }\n\n    return new GoogleVertexTranscriptionModel(modelId, {\n      provider: config.provider,\n      headers: config.headers,\n      fetch: config.fetch,\n      project: loadGoogleVertexProject(),\n      location: loadGoogleVertexLocation(),\n    });\n  };\n\n  const provider = function (modelId: GoogleVertexModelId) {\n    if (new.target) {\n      throw new Error(\n        'The Google Vertex AI model function cannot be called with the new keyword.',\n      );\n    }\n\n    return createChatModel(modelId);\n  };\n\n  provider.specificationVersion = 'v4' as const;\n  provider.languageModel = createChatModel;\n  provider.interactions = createInteractionsModel;\n  provider.embeddingModel = createEmbeddingModel;\n  provider.textEmbeddingModel = createEmbeddingModel;\n  provider.image = createImageModel;\n  provider.imageModel = createImageModel;\n  provider.video = createVideoModel;\n  provider.videoModel = createVideoModel;\n  provider.speech = createSpeechModel;\n  provider.speechModel = createSpeechModel;","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/google-vertex/src/google-vertex-provider-base.ts#L380-L416","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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`."],"exampleFix":"// before\nconst model = new vertex('gemini-2.0-flash');\n// after\nconst model = vertex('gemini-2.0-flash');","handlingStrategy":"type-guard","validationCode":"if (typeof vertex !== 'function') throw new Error('vertex provider must be called as a function, not constructed.');","typeGuard":"function isProviderFunction(v: unknown): v is (modelId: string) => LanguageModel {\n  return typeof v === 'function';\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["javascript","api-misuse","google-vertex"],"backgroundTag":"class-called-without-new","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}