Vertex AI is a fully-managed, unified AI development platform for building and using generative AI. This example shows how to use Vertex AI with a Next.js project hosted on Vercel.
Before using Vertex AI, GCP lists additional setup requirements in the Vertex AI documentation.
Make sure you have installed the Vercel integration as described in the Installation guide. You can install it directly from the integration page.
You'll need the Vertex AI node.js client library (@google-cloud/vertex-ai
). First, install it:
npm install @google-cloud/vertexai
After installing the Google Cloud Platform integration on Vercel, you can access the credentials using our helper function getGCPCredentials
. See the Usage section for more information.
import { VertexAI } from '@google-cloud/vertexai'; const vertexAI = new VertexAI({ project: process.env.GCP_PROJECT_ID, location: process.env.GCP_REGION, googleAuthOptions: getGCPCredentials() }); const generativeModel = vertexAI.getGenerativeModel({ model: 'gemini-1.5-flash-001', }); const prompt = "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?"; const resp = await generativeModel.generateContent(prompt); const contentResponse = await resp.response; console.log(JSON.stringify(contentResponse));
Text Generation: Use Vertex AI to generate text for your Vercel application. This can be used for chatbots, customer support, or any other text-based application.
Image Generation: Use Vertex AI to generate images for your Vercel application. This can be used for product images, marketing materials, or any other image-based application.
Translation: Use Vertex AI to translate text for your Vercel application. This can be used for multilingual websites, customer support, or any other translation-based application.
Classification: Use Vertex AI to classify text for your Vercel application. This can be used for sentiment analysis, spam detection, or any other classification-based application.