feat(CG4-credits): GET /billing/credits + docstring CG4 + GOOGLE_CREDIT_TOTAL_USD støtte
This commit is contained in:
parent
6804080482
commit
af1d546c9b
33
main.py
33
main.py
|
|
@ -13,6 +13,8 @@ CG5-onboard: GET /onboard + POST /onboard/complete — klient-onboarding wizard.
|
|||
DOCS: GET /docs/{path} — proxy til privat GitHub-repo via ADC/PAT.
|
||||
OQ-29: GET /notify/channels — list delivery-kanaler per gcp_project.
|
||||
OQ-31: GET /opax/build-status — ekte Cloud Build-status.
|
||||
CG4-credits: GET /billing/credits — kreditt-saldo, burn rate og tom-dato.
|
||||
Krever GOOGLE_CREDIT_TOTAL_USD i Cloud Run env for runway-beregning.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
|
@ -653,6 +655,37 @@ async def authenticated_billing_anomalies(request: Request):
|
|||
app.add_api_route("/billing/anomalies", endpoint=require_auth(authenticated_billing_anomalies), methods=["GET"])
|
||||
|
||||
|
||||
# ── CG4-credits: GET /billing/credits ────────────────────────────────────────
|
||||
async def authenticated_billing_credits(request: Request, days: int = 90):
|
||||
"""
|
||||
CG4-credits — Kreditt-saldo, burn rate og estimert tom-dato.
|
||||
|
||||
Query params:
|
||||
days (int, default 90): Analyseperiode i dager.
|
||||
|
||||
Krever env-var GOOGLE_CREDIT_TOTAL_USD satt i Cloud Run for
|
||||
nøyaktig runway-beregning. Uten denne vises kun burn rate.
|
||||
|
||||
Eksempel-respons:
|
||||
{
|
||||
"credits_used_total_usd": 994.66,
|
||||
"credits_remaining_usd": 305.34,
|
||||
"credit_total_usd": 1300.0,
|
||||
"daily_credit_burn_usd": 14.2,
|
||||
"credit_runway_days": 21,
|
||||
"credit_exhaustion_date": "2026-07-04",
|
||||
"warning": "⚠️ Kreditter estimert tom om 21 dager (2026-07-04).",
|
||||
...
|
||||
}
|
||||
"""
|
||||
try:
|
||||
return JSONResponse(BillingAgent().get_credits_status(days=days))
|
||||
except Exception as exc:
|
||||
return JSONResponse(status_code=500, content={"error": str(exc)})
|
||||
|
||||
app.add_api_route("/billing/credits", endpoint=require_auth(authenticated_billing_credits), methods=["GET"])
|
||||
|
||||
|
||||
@app.get("/billing-dashboard")
|
||||
def billing_dashboard_view(request: Request):
|
||||
return RedirectResponse(url='/static/billing-dashboard.html')
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user