Skip to main content

Billing API Reference

All Billing endpoints are served under the /api/v1/billing prefix via the gateway. Amounts are in cents (integer).

Endpoints

Items

MethodPathDescription
GET/api/v1/billing/itemsList items (filters below)
POST/api/v1/billing/itemsCreate item
GET/api/v1/billing/items/:idGet item by ID
PUT/api/v1/billing/items/:idUpdate item
DELETE/api/v1/billing/items/:idDelete item
GET/api/v1/billing/items/by-provider-refFind by provider reference (?provider=, ?providerRef=)

Item Filters: ?category=, ?provider=, ?service=, ?from=, ?to=, ?recurring=, ?tags=, ?limit=, ?stageApp=, ?author=

Categories

MethodPathDescription
GET/api/v1/billing/categoriesList all categories
POST/api/v1/billing/categoriesCreate category
GET/api/v1/billing/categories/:idOrNameGet category by ID or name
PUT/api/v1/billing/categories/:idUpdate category
DELETE/api/v1/billing/categories/:idDelete category

Reports

MethodPathDescription
GET/api/v1/billing/reports/summaryTotal spend and item count
GET/api/v1/billing/reports/breakdownGrouped spending (?by=provider|category|service|recurring|tag)
GET/api/v1/billing/reports/trendSpending over time (?interval=day|week|month)

Report Filters: ?category=, ?provider=, ?service=, ?from=, ?to=

Status

MethodPathDescription
GET/api/v1/billing/statusService status with storage stats
MethodPathDescription
GET/api/v1/billing/search?q=<term>Full-text search across items (?limit=)

Sync

MethodPathDescription
POST/api/v1/billing/syncTrigger manual sync from a provider
GET/api/v1/billing/sync/jobsList sync job history (?provider=)
GET/api/v1/billing/sync/jobs/:idGet sync job details
GET/api/v1/billing/sync/adaptersList registered sync adapters

Examples

Create a Billing Item

curl -X POST http://localhost:3000/api/v1/billing/items \
-H "Content-Type: application/json" \
-d '{
"name": "GCP Compute Engine",
"amount": 1050,
"currency": "USD",
"provider": "gcp",
"providerRef": "gcp-inv-2026-03",
"tags": ["compute", "production"],
"description": "March compute costs",
"recurring": true,
"period": "monthly"
}'

Response:

{
"success": true,
"data": {
"id": "abc123def456",
"name": "GCP Compute Engine",
"amount": 1050,
"currency": "USD",
"provider": "gcp",
"providerRef": "gcp-inv-2026-03",
"tags": ["compute", "production"],
"description": "March compute costs",
"recurring": true,
"period": "monthly",
"date": "2026-03-05T12:00:00.000Z",
"createdAt": "2026-03-05T12:00:00.000Z",
"updatedAt": "2026-03-05T12:00:00.000Z"
}
}

List Items with Filters

curl "http://localhost:3000/api/v1/billing/items?provider=gcp&from=2026-03-01&to=2026-03-31&limit=20"

Create a Category

curl -X POST http://localhost:3000/api/v1/billing/categories \
-H "Content-Type: application/json" \
-d '{
"name": "Infrastructure",
"description": "Cloud infrastructure costs",
"color": "#4A90D9"
}'

Get Spending Summary

curl "http://localhost:3000/api/v1/billing/reports/summary?from=2026-03-01&to=2026-03-31"

Response:

{
"success": true,
"data": {
"totalAmount": 52500,
"itemCount": 15,
"currency": "USD",
"from": "2026-03-01",
"to": "2026-03-31"
}
}

Get Spending Breakdown

curl "http://localhost:3000/api/v1/billing/reports/breakdown?by=provider"

Response:

{
"success": true,
"data": [
{ "key": "gcp", "amount": 35000, "count": 8, "percentage": 66.7 },
{ "key": "openai", "amount": 17500, "count": 7, "percentage": 33.3 }
]
}

Get Spending Trend

curl "http://localhost:3000/api/v1/billing/reports/trend?interval=month&from=2026-01-01"

Response:

{
"success": true,
"data": [
{ "date": "2026-01", "amount": 45000, "count": 12 },
{ "date": "2026-02", "amount": 48000, "count": 14 },
{ "date": "2026-03", "amount": 52500, "count": 15 }
]
}

Search Items

curl "http://localhost:3000/api/v1/billing/search?q=compute&limit=10"

Trigger a Sync

curl -X POST http://localhost:3000/api/v1/billing/sync \
-H "Content-Type: application/json" \
-d '{
"provider": "gcp",
"token": "<gcp-access-token>",
"from": "2026-03-01",
"to": "2026-03-31",
"projectId": "my-gcp-project"
}'

Response:

{
"success": true,
"data": {
"id": "xyz789ghi012",
"provider": "gcp",
"status": "completed",
"itemsCreated": 5,
"itemsUpdated": 2,
"startedAt": "2026-03-05T12:00:00.000Z",
"completedAt": "2026-03-05T12:00:05.000Z"
}
}

Get Service Status

curl http://localhost:3000/api/v1/billing/status

Response:

{
"success": true,
"data": {
"initialized": true,
"config": { "version": 1, "currency": "USD" },
"totalItems": 42,
"totalCategories": 5,
"totalSyncJobs": 3,
"totalAmount": 150000,
"currency": "USD",
"storageType": "file"
}
}

Response Envelope

All responses follow the standard envelope format:

Success:

{
"success": true,
"data": { ... }
}

Error:

{
"success": false,
"error": {
"code": "NOT_FOUND",
"message": "Item not found: abc123def456"
}
}