Skip to content
GreenKube

API Reference

import { Aside } from ‘@astrojs/starlight/components’;

GreenKube exposes a REST API built with FastAPI. Interactive Swagger documentation is available at /api/v1/docs when the server is running.

http://localhost:8000/api/v1

The API supports bearer-token authentication via GREENKUBE_API_KEY (Helm value: secrets.apiKey). When configured, send Authorization: Bearer ${GREENKUBE_API_KEY} on protected API requests. In development, an empty key leaves protected routes open; production requires a non-empty key.

Terminal window
GREENKUBE_API_KEY="your-api-key"
curl -H "Authorization: Bearer ${GREENKUBE_API_KEY}" http://localhost:8000/api/v1/metrics

The health, Swagger UI, and OpenAPI schema endpoints remain public. Do not expose an unauthenticated development instance to untrusted networks.

EndpointMethodDescription
/healthGETLiveness check
/versionGETVersion info
/configGETNon-sensitive configuration
/health/servicesGETAggregated health status for all data sources (Prometheus, OpenCost, Electricity Maps, Wattnet, Boavizta, K8s). Non-selected electricity providers are reported as inactive and excluded from the overall status.
/health/services/{name}GETSingle service health — add ?force=true to bypass 30s cache
/config/servicesPOSTApply service URL/token updates in memory; best-effort persistence to a Kubernetes Secret
/namespacesGETList namespaces with collected metrics
/nodesGETList cluster nodes
EndpointMethodDescription
/metricsGETPer-pod metrics with pagination (?offset=0&limit=1000)
/metrics/summaryGETAggregated cluster/namespace totals
/metrics/timeseriesGETBucketed time-series for charts
/metrics/by-namespaceGETCO₂e, embodied emissions, energy, cost aggregated by namespace
/metrics/top-podsGETTop-N pods by CO₂e over a time window
/metrics/dashboard-summaryGETPre-computed KPI cache — fast, no full-table scan
/metrics/dashboard-timeseries/{window_slug}GETPre-computed timeseries for 1h, 6h, 24h, 7d, 30d, 1y, or ytd
/metrics/dashboard-summary/refreshPOSTTrigger on-demand cache refresh (returns HTTP 202)

Common query parameters: namespace, last (e.g. 24h, 7d, 30d, 1y, ytd), granularity (hour, day, week, month)

Example: Get metrics with Scope 2 + Scope 3

Section titled “Example: Get metrics with Scope 2 + Scope 3”
Terminal window
curl "http://localhost:8000/api/v1/metrics?namespace=production&last=24h"
{
"items": [
{
"pod_name": "api-deployment-7b5f8c9d6-x2k4p",
"namespace": "production",
"timestamp": "2024-02-21T14:00:00Z",
"joules": 1250.5,
"co2e_grams": 0.174,
"embodied_co2e_grams": 0.012,
"total_co2e_all_scopes": 0.186,
"total_cost": 0.0023,
"grid_intensity": 45.2,
"pue": 1.15,
"cpu_usage_millicores": 85.3,
"memory_usage_bytes": 134217728,
"is_estimated": false,
"estimation_reasons": []
}
],
"total": 42,
"offset": 0,
"limit": 1000,
"next_cursor": null
}
EndpointMethodDescription
/report/summaryGETPreview: row count, totals before downloading
/report/yearsGETList calendar years available in stored metrics
/report/exportGETDownloadable file (CSV or JSON) with correct Content-Disposition headers

Report parameters:

  • format — csv or json
  • last — relative window (e.g. 7d, ytd)
  • start / end — ISO 8601 date range
  • years — calendar year, e.g. ?years=2024&years=2025
  • aggregate — set to true to aggregate exported rows
  • granularity — when aggregating: hourly, daily, weekly, monthly, yearly
  • namespace — filter by namespace
  • group_by — when aggregating: pod or namespace
Terminal window
# Annual estimated cost and carbon export
curl -O -J "http://localhost:8000/api/v1/report/export?format=csv&years=2024&aggregate=true&granularity=monthly"
EndpointMethodDescription
/recommendationsGETRead active recommendations; generates records when none exist. ?refresh=true schedules a refresh
/recommendations/activeGETPersisted active recommendations — add ?refresh=true to re-run engine
/recommendations/topGETTop-N ranked active recommendations by projected annual savings — ?limit=5&metric=co2 (or cost), ?refresh=true
/recommendations/ignoredGETRecommendations currently marked ignored
/recommendations/appliedGETApplied recommendations ordered by most recent application
/recommendations/historyGETHistorical records with optional time filtering
/recommendations/savingsGETAggregate savings by recommendation type
/recommendations/{id}GETRecommendation detail with evidence and assessment
/recommendations/{id}/eventsGETRecommendation lifecycle audit trail
/recommendations/{id}/apply-prPOSTPreview a rightsizing patch or enqueue a Git pull request
/recommendations/{id}/pull-requestsGETPull-request attempts for a recommendation
/recommendations/{id}/apply-pr/eligibilityGETCheck GitOps pull-request eligibility
/automation/statusGETGit PR automation readiness
/recommendations/{id}/applyPATCHMark applied with optional actual resource values
/recommendations/{id}/ignorePATCHPermanently ignore a recommendation
/recommendations/{id}/ignoreDELETERestore an ignored recommendation to active
Terminal window
curl "http://localhost:8000/api/v1/recommendations/active"
[
{
"id": 42,
"type": "RIGHTSIZING_CPU",
"status": "active",
"priority": "high",
"scope": "workload",
"pod_name": "api-deployment",
"namespace": "production",
"description": "CPU request (500m) is 6× higher than average usage (85m). Recommended: 105m.",
"potential_savings_co2e_grams": 1250.0,
"potential_savings_cost": 45.60,
"current_cpu_request_millicores": 500,
"recommended_cpu_request_millicores": 105
}
]
Terminal window
curl -X PATCH "http://localhost:8000/api/v1/recommendations/42/apply"

This triggers a savings ledger entry and updates the greenkube_co2e_savings_attributed_grams_total Prometheus gauge.

Example: Restore an ignored recommendation

Section titled “Example: Restore an ignored recommendation”
Terminal window
curl -X DELETE "http://localhost:8000/api/v1/recommendations/42/ignore"
EndpointFormatDescription
/prometheus/metricsPrometheus textScraped by Prometheus

The sustainability score is exposed through Prometheus metrics; see the Grafana guide.

All endpoints return standard HTTP status codes:

StatusDescription
200Success
202Accepted (background operation started)
400Bad request (invalid parameters)
404Resource not found
500Internal server error

When the API is running, visit: