Deploy elizaOS agents as serverless GCP Cloud Run services. This example shows how to run an AI agent as a containerized worker that processes chat messages via HTTP.
┌──────────────┐ ┌─────────────────┐ ┌────────────────┐
│ Test Client │────▶│ Cloud Run │────▶│ elizaOS │
│ (curl/node) │◀────│ (HTTP) │◀────│ Worker │
└──────────────┘ └─────────────────┘ └────────────────┘
│
▼
┌────────────────┐
│ OpenAI API │
└────────────────┘
- Google Cloud SDK installed and configured
- Docker installed
- GCP project with Cloud Run API enabled
- OpenAI API key
export PROJECT_ID="your-gcp-project-id"
export REGION="us-central1"
export OPENAI_API_KEY="your-openai-api-key"gcloud config set project $PROJECT_ID
gcloud services enable run.googleapis.com
gcloud services enable cloudbuild.googleapis.com
gcloud services enable artifactregistry.googleapis.comcd packages/examples/gcp
npm install
npm run build
# Build and deploy
gcloud run deploy eliza-worker-ts \
--source . \
--region $REGION \
--allow-unauthenticated \
--set-env-vars "OPENAI_API_KEY=$OPENAI_API_KEY"After deployment, Cloud Run provides a URL. Test it:
# Get service URL
SERVICE_URL=$(gcloud run services describe eliza-worker-ts --region $REGION --format 'value(status.url)')
# Health check
curl $SERVICE_URL/health
# Chat
curl -X POST $SERVICE_URL/chat \
-H "Content-Type: application/json" \
-d '{"message": "Hello, Eliza!"}'
# Using the test client
cd packages/examples/gcp
bun run test-client.ts --url $SERVICE_URLcd packages/examples/gcp
npm install
npm run dev
# Server runs at http://localhost:8080bun run test
bun run typecheckbun run test performs a non-interactive worker availability check. If no local
or deployed worker URL is configured, it skips cleanly and prints the setup
hint.
packages/examples/gcp/
├── README.md # This file
├── Dockerfile # Cloud Run container image
├── handler.ts # Cloud Run handler
├── test-client.ts # Interactive test client
├── package.json # Test client dependencies
├── cloudbuild.yaml # Cloud Build configuration
├── deploy.sh # Deployment helper
├── env.example # Environment template
└── terraform/ # Optional infrastructure template
Send a message to the elizaOS agent.
Request:
{
"message": "Hello, how are you?",
"userId": "optional-user-id",
"conversationId": "optional-conversation-id"
}Response:
{
"response": "I'm doing well, thank you for asking!",
"conversationId": "uuid-for-conversation-tracking",
"timestamp": "2025-01-10T12:00:00.000Z"
}Health check endpoint.
Response:
{
"status": "healthy",
"runtime": "typescript",
"version": "2.0.0-beta.0"
}Service info endpoint.
Response:
{
"name": "Eliza",
"bio": "A helpful AI assistant.",
"version": "2.0.0-beta.0",
"powered_by": "elizaOS"
}# Deploy from source (builds automatically)
gcloud run deploy eliza-worker \
--source . \
--region $REGION \
--allow-unauthenticated \
--set-env-vars "OPENAI_API_KEY=$OPENAI_API_KEY"# Submit build and deploy
gcloud builds submit --config=cloudbuild.yaml \
--substitutions=_REGION=$REGION,_OPENAI_API_KEY=$OPENAI_API_KEYSee the Terraform example for infrastructure-as-code deployment.
| Variable | Required | Default | Description |
|---|---|---|---|
OPENAI_API_KEY |
Yes | - | Your OpenAI API key |
OPENAI_MODEL |
No | gpt-5-mini |
Model to use |
OPENAI_BASE_URL |
No | OpenAI default | Custom API endpoint |
CHARACTER_NAME |
No | Eliza |
Agent's name |
CHARACTER_BIO |
No | A helpful AI assistant. |
Agent's bio |
CHARACTER_SYSTEM |
No | Default system prompt | Custom system prompt |
PORT |
No | 8080 |
Server port (set by Cloud Run) |
LOG_LEVEL |
No | INFO |
Logging level |
Customize the agent's personality via environment variables:
gcloud run deploy eliza-worker \
--set-env-vars "OPENAI_API_KEY=$OPENAI_API_KEY" \
--set-env-vars "CHARACTER_NAME=Ada" \
--set-env-vars "CHARACTER_BIO=A brilliant mathematician and programmer" \
--set-env-vars "CHARACTER_SYSTEM=You are Ada Lovelace, speaking from the 19th century..."Cloud Run cold starts are typically 1-3 seconds. To minimize:
-
Minimum Instances: Keep at least one instance warm
gcloud run deploy eliza-worker --min-instances 1
-
Smaller Container: Use multi-stage Docker builds
-
Startup CPU Boost: Enable for faster cold starts
gcloud run deploy eliza-worker --cpu-boost
Recommended settings:
| Runtime | Memory | CPU | Timeout |
|---|---|---|---|
| TypeScript | 512 Mi | 1 | 60s |
gcloud run deploy eliza-worker \
--memory 512Mi \
--cpu 1 \
--timeout 60sgcloud run logs read eliza-worker --region $REGION --limit 100gcloud run logs tail eliza-worker --region $REGIONCloud Run automatically provides metrics:
- Request count
- Request latencies
- Container instance count
- Billable container instance time
- CPU and memory utilization
Cloud Run pricing (as of 2025):
- CPU: $0.000024 per vCPU-second
- Memory: $0.0000025 per GiB-second
- Requests: $0.40 per million requests
Example (1 vCPU, 512 MiB, 2s avg duration, 10K requests/month):
- CPU: 10,000 × 2s × $0.000024 = $0.48
- Memory: 10,000 × 2s × 0.5 × $0.0000025 = $0.025
- Requests: 10,000 × $0.0000004 = $0.004
- Total: ~$0.51/month
Note: Free tier includes 2 million requests/month
gcloud run deploy eliza-worker --allow-unauthenticatedgcloud run deploy eliza-worker --no-allow-unauthenticated
# Invoke with authentication
curl -H "Authorization: Bearer $(gcloud auth print-identity-token)" \
$SERVICE_URL/chatgcloud run domain-mappings create \
--service eliza-worker \
--domain eliza.yourdomain.com \
--region $REGIONCheck logs for startup errors:
gcloud run logs read eliza-worker --region $REGION --limit 50Ensure the service account has required permissions:
gcloud run services add-iam-policy-binding eliza-worker \
--member="allUsers" \
--role="roles/run.invoker" \
--region $REGIONVerify environment variables are set:
gcloud run services describe eliza-worker \
--region $REGION \
--format 'yaml(spec.template.spec.containers[0].env)'Increase request timeout:
gcloud run deploy eliza-worker --timeout 300sRemove all deployed resources:
# Delete Cloud Run service
gcloud run services delete eliza-worker --region $REGION --quiet
# Delete container images (optional)
gcloud artifacts docker images delete \
$REGION-docker.pkg.dev/$PROJECT_ID/eliza/eliza-worker --quiet-
Use Secret Manager for API keys:
echo -n "$OPENAI_API_KEY" | gcloud secrets create openai-api-key --data-file=- gcloud run deploy eliza-worker \ --set-secrets "OPENAI_API_KEY=openai-api-key:latest"
-
Enable VPC Connector for private networking
-
Set up Cloud Armor for DDoS protection
-
Use IAM for authentication when possible