You can deploy Firebase Genkit flows as web services using any service that can host a Go binary. This page, as an example, walks you through the general process of deploying the default sample flow, and points out where you must take provider-specific actions.
Create a directory for the Genkit sample project:
mkdir -p ~/tmp/genkit-cloud-project
cd ~/tmp/genkit-cloud-project
If you're going to use an IDE, open it to this directory.
Initialize a Go module in your project directory:
go mod init example/cloudrun
Initialize Genkit in your project:
genkit init
Select the model provider you want to use.
Accept the defaults for the remaining prompts. The
genkit
tool will create a sample source file to get you started developing your own AI flows. For the rest of this tutorial, however, you'll just deploy the sample flow.Edit the sample file (
main.go
orgenkit.go
) to explicitly specify the port the flow server should listen on:if err := genkit.Init(ctx, &genkit.Options{FlowAddr: ":3400"}, // Add this parameter. ); err != nil { log.Fatal(err) }
If your provider requires you to listen on a specific port, be sure to configure Genkit accordingly.
Implement some form of authentication and authorization to gate access to the flows you plan to deploy.
Because most generative AI services are metered, you most likely do not want to allow open access to any endpoints that call them. Some hosting services provide an authentication layer as a frontend to apps deployed on them, which you can use for this purpose.
Make API credentials available to your deployed function. Do one of the following, depending on the model provider you chose:
Gemini (Google AI)
Make sure Google AI is available in your region.
Generate an API key for the Gemini API using Google AI Studio.
Make the API key available in the deployed environment.
Most app hosts provide some system for securely handling secrets such as API keys. Often, these secrets are available to your app in the form of environment variables. If you can assign your API key to the
GOOGLE_GENAI_API_KEY
variable, Genkit will use it automatically. Otherwise, you need to modify thegoogleai.Init()
call to explicitly set the key. (But don't embed the key directly in code! Use the secret management facilities provided by your hosting provider.)
Gemini (Vertex AI)
In the Cloud console, Enable the Vertex AI API for your project.
On the IAM page, create a service account for accessing the Vertex AI API if you don't alreacy have one.
Grant the account the Vertex AI User role.
Set up Application Default Credentials in your hosting environment.
Configure the plugin with your Google Cloud project ID and the Vertex AI API location you want to use. You can do so either by setting the
GCLOUD_PROJECT
andGCLOUD_LOCATION
environment variables in your hosting environment, or in yourvertexai.Init()
call.
The only secret you need to set up for this tutorial is for the model provider, but in general, you must do something similar for each service your flow uses.
Optional: Try your flow in the developer UI:
Set up your local environment for the model provider you chose:
Gemini (Google AI)
export GOOGLE_GENAI_API_KEY=<your API key>
Gemini (Vertex AI)
export GCLOUD_PROJECT=<your project ID>
export GCLOUD_LOCATION=us-central1
gcloud auth application-default login
Start the UI:
genkit start
In the developer UI (http://localhost:4000/), run the flow:
Click menuSuggestionFlow.
On the Input JSON tab, provide a subject for the model:
"banana"
Click Run.
If everything's working as expected so far, you can build and deploy the flow using your provider's tools.