Use this file to discover all available pages before exploring further.
Cloud Run is a fully managed container platform that scales to zero and supports all three Genkit runtimes. It is a good choice when you need more control over the runtime than Firebase Cloud Functions provides — custom base images, background processes, Python or Go flows, or longer request timeouts.
startFlowServer from @genkit-ai/express starts an Express server on the port Cloud Run expects ($PORT, defaulting to 8080).
// src/index.tsimport { genkit } from 'genkit';import { vertexAI } from '@genkit-ai/google-genai';import { startFlowServer } from '@genkit-ai/express';// On Cloud Run, Application Default Credentials are provided automatically.// Using Vertex AI means no GOOGLE_GENAI_API_KEY is needed.const ai = genkit({ plugins: [vertexAI({ location: 'us-central1' })],});const menuFlow = ai.defineFlow('menuSuggestion', async (theme: string) => { const { text } = await ai.generate( `Suggest a concise menu for a ${theme} restaurant.` ); return text;});startFlowServer({ flows: [menuFlow], // port defaults to process.env.PORT || 3400});
For a custom Express app (e.g. to add health-check routes or middleware):
import { expressHandler } from '@genkit-ai/express';import express from 'express';const app = express();app.use(express.json());app.get('/health', (_req, res) => res.send('ok'));app.post('/menuSuggestion', expressHandler(menuFlow));const port = Number(process.env.PORT) || 8080;app.listen(port, () => console.log(`Listening on :${port}`));
2
Write the Dockerfile
FROM node:20-slimWORKDIR /appCOPY package*.json ./RUN npm ci --omit=devCOPY dist/ ./dist/ENV NODE_ENV=productionENV GENKIT_ENV=productionEXPOSE 8080CMD ["node", "dist/index.js"]
Build TypeScript before building the image:
npm run builddocker build -t gcr.io/MY_PROJECT/genkit-app .
Cloud Run injects the PORT environment variable automatically. The service account attached to the revision provides Application Default Credentials, so Vertex AI works without any additional configuration.
When you use Vertex AI (rather than the Gemini API key) on Cloud Run, no API key is required. The Cloud Run service account provides Application Default Credentials (ADC) automatically. Grant the service account the roles/aiplatform.user role:
Using Vertex AI with Workload Identity is the recommended approach for production Cloud Run services. It avoids storing long-lived API keys and automatically rotates credentials.
Do not deploy with GENKIT_ENV=dev. The Genkit reflection server exposes an unauthenticated API for invoking all registered flows. Remove GENKIT_ENV from your environment or set it to production.
Set it in your Dockerfile or as a Cloud Run environment variable:
gcloud run services update genkit-app \ --update-env-vars GENKIT_ENV=production