Vertex AI plugin
The Vertex AI plugin provides access to Google Cloud’s enterprise-grade AI platform, offering advanced features beyond basic model access. Use this for enterprise applications that need grounding, Vector Search, Model Garden, or evaluation capabilities.
Accessing Google GenAI Models via Vertex AI
Section titled “Accessing Google GenAI Models via Vertex AI”All languages support accessing Google’s generative AI models (Gemini, Imagen, etc.) through Vertex AI with enterprise authentication and features.
The Google Generative AI plugin provides access to Google’s Gemini models through Vertex AI using Google Cloud authentication.
Configuration
Section titled “Configuration”To use this plugin, import the googlegenai package and pass googlegenai.VertexAI to WithPlugins() in the Genkit initializer:
import "github.com/firebase/genkit/go/plugins/googlegenai"g := genkit.Init(context.Background(), genkit.WithPlugins(&googlegenai.VertexAI{}))The plugin requires you to specify your Google Cloud project ID, the region to which you want to make Vertex API requests, and your Google Cloud project credentials.
-
By default,
googlegenai.VertexAIgets your Google Cloud project ID from theGOOGLE_CLOUD_PROJECTenvironment variable.You can also pass this value directly:
genkit.WithPlugins(&googlegenai.VertexAI{ProjectID: "my-project-id"})-
By default,
googlegenai.VertexAIgets the Vertex AI API location from theGOOGLE_CLOUD_LOCATIONenvironment variable.You can also pass this value directly:
genkit.WithPlugins(&googlegenai.VertexAI{Location: "us-central1"})-
To provide API credentials, you need to set up Google Cloud Application Default Credentials.
-
To specify your credentials:
-
If you’re running your flow from a Google Cloud environment (Cloud Functions, Cloud Run, and so on), this is set automatically.
-
On your local dev environment, do this by running:
-
-
gcloud auth application-default login- For other environments, see the Application Default Credentials docs.
- In addition, make sure the account is granted the Vertex AI User IAM role (
roles/aiplatform.user). See the Vertex AI access control docs.
Generative models
Section titled “Generative models”To get a reference to a supported model, specify its identifier to googlegenai.VertexAIModel:
model := googlegenai.VertexAIModel(g, "gemini-2.5-flash")Alternatively, you may create a ModelRef which pairs the model name with its config:
modelRef := googlegenai.VertexAIModelRef("gemini-2.5-flash", &genai.GenerateContentConfig{ Temperature: genai.Ptr[float32](0.5), MaxOutputTokens: genai.Ptr[int32](500), // Other configuration...})The following models are supported: gemini-1.5-pro, gemini-1.5-flash, gemini-2.0-pro, gemini-2.5-flash, and other experimental models.
Model references have a Generate() method that calls the Vertex AI API:
resp, err := genkit.Generate(ctx, g, ai.WithModel(modelRef), ai.WithPrompt("Tell me a joke."))if err != nil { return err}
log.Println(resp.Text())See Generating content with AI models for more information.
Embedding models
Section titled “Embedding models”To get a reference to a supported embedding model, specify its identifier to googlegenai.VertexAIEmbedder:
embeddingModel := googlegenai.VertexAIEmbedder(g, "text-embedding-004")The following models are supported:
textembedding-gecko@003,textembedding-gecko@002,textembedding-gecko@001,text-embedding-004,textembedding-gecko-multilingual@001,text-multilingual-embedding-002, andmultimodalembedding
Embedder references have an Embed() method that calls the Vertex AI API:
resp, err := genkit.Embed(ctx, g, ai.WithEmbedder(embeddingModel), ai.WithTextDocs(userInput))if err != nil { return err}You can retrieve docs by passing in an input to a Retriever’s Retrieve() method:
resp, err := genkit.Retrieve(ctx, g, ai.WithRetriever(myRetriever), ai.WithTextDocs(userInput))if err != nil { return err}See Retrieval-augmented generation (RAG) for more information.
Advanced Features
Section titled “Advanced Features”Advanced Vertex AI features like Vector Search, Model Garden, and evaluation metrics require custom implementation using the Google Cloud SDK directly. See the Vertex AI documentation for implementation details.
Next Steps
Section titled “Next Steps”- Learn about generating content to understand how to use these models effectively
- Explore evaluation to leverage Vertex AI’s evaluation metrics
- See RAG to implement retrieval-augmented generation with Vector Search
- Check out creating flows to build structured AI workflows
- For simple API key access, see the Google AI plugin