3.5 KiB
billing-service API and interfaces
This document describes the current billing-service task API plus the
upstream and downstream interfaces it depends on.
Service endpoints
GET /healthz
Returns service health derived from the most recent collect-and-rate execution.
Example response:
{
"status": "ok",
"message": ""
}
GET /v1/status
Returns the latest in-memory job result snapshot.
Key fields:
jobstarted_atfinished_atprocessed_sampleswritten_minutesreplayed_minutesstatuserror
POST /v1/jobs/collect-and-rate
Triggers an immediate snapshot pull from xray-exporter, computes minute
deltas, rates chargeable bytes, and writes replay-safe facts into PostgreSQL.
Behavior:
- method must be
POST - returns
200when the run completes without a fatal service error - returns
503when upstream fetch or persistence fails hard enough to mark the run unavailable
POST /v1/jobs/reconcile
Triggers the same execution path as collect-and-rate, but records the job name
as reconcile for operational visibility.
Upstream dependency
xray-exporter
billing-service currently depends on a single exporter base URL and fetches:
GET /v1/snapshots/latest
Minimum payload shape:
{
"collected_at": "2026-04-08T12:00:00Z",
"node_id": "jp-xhttp-contabo.svc.plus",
"env": "prod",
"samples": [
{
"uuid": "uuid-1",
"email": "user@example.com",
"inbound_tag": "xhttp-premium",
"uplink_bytes_total": 1024,
"downlink_bytes_total": 2048
}
]
}
Required fields:
collected_atnode_idenvsamples[].uuidsamples[].emailsamples[].inbound_tagsamples[].uplink_bytes_totalsamples[].downlink_bytes_total
Target upstream contract
Current production behavior remains GET /v1/snapshots/latest, but the target
multi-node design should evolve to:
- HTTPS transport for remote exporter pulls
- source-specific authentication
- a windowed pull API that supports catch-up and pagination
Recommended target path:
GET /v1/snapshots/window?since=<RFC3339>&until=<RFC3339>&limit=<n>&cursor=<token>
Target-state expectations:
- remote pulls use
https://exporter base URLs - TLS verification stays enabled
- each source can be authenticated independently
- responses can be replayed safely from source checkpoints without duplicate billing writes
Downstream reads
User-facing reads do not go through billing-service. The read model is
accounts.svc.plus, backed by PostgreSQL.
Relevant downstream APIs:
GET /api/account/usage/summaryGET /api/account/usage/bucketsGET /api/account/billing/summary
Read-path rules:
billing-servicedoes not expose user-facing usage or billing query APIsaccounts.svc.plusreads PostgreSQL-backed usage and billing factsconsole.svc.plusqueriesaccounts.svc.plus, notbilling-service
Configuration inputs
Runtime environment variables used by the current implementation:
EXPORTER_BASE_URLDATABASE_URLLISTEN_ADDRCOLLECT_INTERVALDEFAULT_REGIONSOURCE_REVISIONPRICE_PER_BYTEINITIAL_INCLUDED_QUOTA_BYTESINITIAL_BALANCE
DATABASE_URL rule:
- it must point to the same
accountdatabase thataccounts.svc.plususes - on
jp-xhttp-contabo.svc.plus, the current accounts containers useDB_HOST=stunnel-client,DB_PORT=15432, andDB_NAME=account billing-serviceshould follow that same target so user-facing reads inaccounts.svc.plussee the exact facts written bybilling-service