packages/docs/examples-gallery/gcp.mdx
Deploy AI agents to Google Cloud Platform.
cd examples/gcp
# Deploy Cloud Function
gcloud functions deploy eliza-chat \
--runtime nodejs20 \
--trigger-http \
--allow-unauthenticated \
--set-env-vars OPENAI_API_KEY=$OPENAI_API_KEY
| Language | Directory | Runtime |
|---|---|---|
| TypeScript | examples/gcp/ | Node.js 20 |
import { HttpFunction } from "@google-cloud/functions-framework";
import { AgentRuntime } from "@elizaos/core";
import { openaiPlugin } from "@elizaos/plugin-openai";
let runtime: AgentRuntime | null = null;
export const elizaChat: HttpFunction = async (req, res) => {
if (!runtime) {
runtime = new AgentRuntime({
character: { name: "Eliza", bio: "A helpful AI." },
plugins: [openaiPlugin],
});
await runtime.initialize();
}
const { message } = req.body;
const response = await runtime.useModel("TEXT_LARGE", { prompt: message });
res.json({ response: String(response) });
};
cd examples/gcp
bun install
bun run dev
curl -X POST http://localhost:8080 \
-H "Content-Type: application/json" \
-d '{"message": "Hello!"}'
The sample Dockerfile in examples/gcp/ builds the TypeScript worker:
cd examples/gcp
docker build -t gcr.io/PROJECT/eliza-worker-typescript .
docker push gcr.io/PROJECT/eliza-worker-typescript
gcloud run deploy eliza-worker-typescript \
--image gcr.io/PROJECT/eliza-worker-typescript \
--set-env-vars OPENAI_API_KEY=$OPENAI_API_KEY
Infrastructure as code is available in examples/gcp/terraform/:
resource "google_cloudfunctions_function" "eliza" {
name = "eliza-chat"
runtime = "nodejs20"
entry_point = "elizaChat"
environment_variables = {
OPENAI_API_KEY = var.openai_api_key
}
}