An AI-powered FinOps agent that detects cloud cost anomalies, recommends optimizations, and automatically creates GitLab issues for engineering follow-up.
- Reads mock GCP billing data at SKU/project/day level
- Detects unusual cloud cost spikes
- Suggests optimization actions
- Creates GitLab issues automatically
- Provides a deployed API that Gemini can call as an agent tool
Gemini Agent
↓
Cloud Run FastAPI backend
↓
Mock GCP billing CSV
↓
Anomaly detection + recommendations
↓
GitLab issue creation
- Python
- FastAPI
- Google Cloud Run
- Google Secret Manager
- GitLab API
- Gemini API
- Pandas
.
├── main.py
├── raw_gitlab.py
├── agent.py
├── gcp_mock_billing_data.csv
├── requirements.txt
├── Dockerfile
├── .gitignore
└── README.md
GET /GET /full_finops_reportPOST /create_ticketExample body:
{
"title": "FinOps Test Ticket",
"description": "Created from Cloud Run API",
"priority": "high"
}GET /run_finops_agentThis runs:
analyze costs → detect anomalies → create GitLab issues
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uvicorn main:app --reload --port 8080Open:
http://localhost:8080/docs
Enable:
- Cloud Run Admin API
- Cloud Build API
- Artifact Registry API
- Secret Manager API
Create a GCP secret named:
gitlab-token
The Cloud Run service account needs:
Secret Manager Secret Accessor
Deploy:
gcloud run deploy finops-agent \
--source . \
--region europe-west1 \
--allow-unauthenticatedBefore running the application, update the GCP project ID in raw_gitlab.py:
project_id = "YOUR_GCP_PROJECT_ID"Replace this value with your Google Cloud project ID.
The application uses this project to retrieve the GitLab token from Google Secret Manager.
Create a GitLab personal access token with api scope.
The app currently uses this project ID:
GITLAB_PROJECT_ID = "YOUR_GITLAB_PROJECT_ID"Update it in main.py if you use another repo.
The Gemini agent is implemented in agent.py.
Before running the agent, update the following configuration values:
# Gemini API key from Google AI Studio
GEMINI_API_KEY = "YOUR_GEMINI_API_KEY"
# Deployed Cloud Run API URL
FINOPS_API = "https://YOUR_CLOUD_RUN_URL"- Open Google AI Studio.
- Generate a Gemini API key.
- Replace:
GEMINI_API_KEY = "YOUR_GEMINI_API_KEY"with your own API key.
Deploy the FastAPI backend to Google Cloud Run.
After deployment, Cloud Run will provide a service URL similar to:
https://finops-agent-xxxxxxxxxx-ew.a.run.app
Replace:
FINOPS_API = "https://YOUR_CLOUD_RUN_URL"with your deployed endpoint.
python agent.pyThe agent will:
- Retrieve cloud cost analysis from the FinOps API.
- Analyze anomalies using Gemini.
- Generate recommendations.
- Create actionable GitLab remediation tickets through the deployed API.
Gemini Agent
↓
Cloud Run FinOps API
↓
Analyze Billing Data
↓
Detect Anomalies
↓
Generate Recommendations
↓
Create GitLab Issue
Autonomous FinOps Agent closes the loop between cloud cost visibility and engineering action. Instead of only reporting spend anomalies, it detects issues, explains business impact, and creates actionable GitLab tickets for teams to fix them.
(Configurations to replace with your parameters: YOUR_GCP_PROJECT_ID, YOUR_GITLAB_PROJECT_ID, YOUR_GEMINI_API_KEY, YOUR_CLOUD_RUN_URL)
This project uses mock GCP billing data for hackathon demonstration purposes.