Billing API Overview
The billing API serves your billing account: what its orgs cost, its invoices, its spend alert, and the tokens that automate it. It is served fromhttps://billing-ng.cpln.io.
For the unpriced quantities behind these charges, use the usage API.
Billing API Authentication
Send a token as a Bearer token on every request:
Endpoints under
/account/{accountId} check the caller’s billing role on that account:
POST /org/{org}/charges/-query accepts either the readMetrics permission on the org, or billing_admin or billing_viewer on the account that pays for the org. The readUsage permission does not grant access.
A caller without the required role or permission receives 401 with {"code":401,"error":"unauthorized"}. Role changes, token revocations, and token expiry can take up to 5 minutes to apply, because authorization results are cached.
Find Your Account ID
{accountId} is your billing account’s UUID. List the accounts your user belongs to:
id is the account ID to use in the paths below.
To find the account that pays for an org, call GET /org/{org}/account with billing_admin or billing_viewer on that account.
Query Charges
POST https://billing-ng.cpln.io/account/{accountId}/charges/-query
POST https://billing-ng.cpln.io/org/{org}/charges/-query
Returns usage priced with your account’s rate plan. The request body is the usage query body, so filters, aggregation, and grouping work the same way, plus the fields below.
- The account endpoint covers every org on the account. Pass
orgsto narrow it. - The org endpoint covers only the org in the path, priced with the rate plan of the account that pays for it.
Pricing tiers are applied to the rows your query selects, starting from the first of the month. A query filtered to one GVC can therefore show different unit rates than the invoice, which tiers on the whole account.
Charges Response
The response wraps a usage query response inresults. Each row adds:
When no usage matches,
results.periods is [].
Example: Last Month’s Charges per Org and Metric
value is the usage in the metric’s unit, and total is its price.
Detailed Charges
With"detailed": true, the response is detailedResults: one entry for each billing period that overlaps the range. Each entry has the accountState, which carries the period’s ratePlan, and results, an array of usage query responses. Each row also has a details array with one entry per pricing tier:
List Charge Tag Values
POST https://billing-ng.cpln.io/account/{accountId}/tags/values/query
Returns the distinct values a usage tag took across every org on the account. It takes the same body as the usage API’s List Usage Tag Values and returns the same response, plus accountId.
tagValues is in no particular order, so sort it yourself. It contains "" when some matching usage lacks the tag. As on the usage API, the range always includes the month that begins at or after endTime.
List Chargeable Items
GET https://billing-ng.cpln.io/chargeable_items
Lists what Control Plane charges for. Any valid token can call it. Use it to find the tags each item prices on, which the charges query must aggregate by, and the names to pass as chargeableItems.
Invoices
Invoice amounts are integers in the currency’s smallest unit, for example cents. This differs from charge queries, which return decimal amounts in whole units.List Invoices
GET https://billing-ng.cpln.io/account/{accountId}/charges/invoices?start=START&end=END
Returns the invoices that overlap the range, newest first. start and end are required, in RFC 3339 on an hour boundary.
The amount due is
totalCharge plus the (negative) credit charges, and never less than 0.
Credits are applied by Control Plane and appear only on invoices. The billing API has no endpoint to list or add them.
Get Pending Invoices
GET https://billing-ng.cpln.io/account/{accountId}/charges/invoices/pending
Returns {"invoices": [...]}: charges the account has accrued but not yet been billed for, such as the current month so far. The format is the same as List Invoices. Add ?include-surcharges=true to get only the current month’s pending invoice with its surcharges and credits included, which is the full balance building up.
Get or Download an Invoice
GET https://billing-ng.cpln.io/account/{accountId}/charges/invoices/{invoiceId}
Set the Accept header to application/json for the invoice object, or to application/pdf to download the PDF. Any other value, including curl’s default */*, returns 400. A Content-Type request header, if sent, takes precedence over Accept.
invoiceId returns 404.
Get an Invoice’s Payment Page
GET https://billing-ng.cpln.io/account/{accountId}/charges/invoices/{invoiceId}/external-url
For accounts billed by card, returns a link to each invoice period’s hosted payment page:
Spend Alert
/account/{accountId}/alert manages the account’s monthly spend alert. An account has at most one alert. Every endpoint requires billing_admin.
Every 10 minutes, Control Plane compares the account’s charges for the current calendar month (UTC) with amount. The first time they reach it, every billing_admin receives an email. The alert then stays quiet until the next month.
The body wraps the alert in
alert and rejects unknown fields:
lastTriggered and alertedTimes.
Billing Service Account Tokens
A billing service account token lets automation, such as a nightly cost export, call the billing API without a person’s login. It belongs to one billing account and holds one or more billing roles. It works on the endpoints under/account/{accountId} for that account, and on GET /chargeable_items. It is not an org credential and does not work on api.cpln.io, the usage API, the /org/{org} billing endpoints, or GET /account.
Every endpoint requires billing_admin.
Create a Billing Service Account Token
POST https://billing-ng.cpln.io/account/{accountId}/service-account-token
201 response is the only time the secret is returned, in token:
Authorization: Bearer cpln-bsat-....
List and Delete Billing Service Account Tokens
GET /account/{accountId}/service-account-tokenlists the account’s tokens initems, without their secrets. Each includeslastUsedAt, which is approximate.DELETE /account/{accountId}/service-account-token/{tokenId}revokes a token and returns204, or404if the account has no such token. A revoked token can keep working for up to 5 minutes.
Account and Orgs
Get the Account
GET https://billing-ng.cpln.io/account/{accountId} returns the account: fullName, email, address, orgQuota, enabled, tou (whether the Terms of Use are accepted), the card paymentMethods on file with their last4 and brand, and the spend alert if one is set. It needs billing_admin, billing_viewer, or org_creator.
List the Account’s Orgs
GET https://billing-ng.cpln.io/account/{accountId}/org lists the orgs the account pays for. It needs billing_admin, billing_viewer, or org_creator, and works with a billing service account token, which cannot call GET /account. Use the names as orgs in a charges query.
Create an Org
POST https://billing-ng.cpln.io/account/{accountId}/org creates an org that bills to the account. It needs billing_admin or org_creator.
orgQuota; otherwise the request returns 400 naming the problem. A new org returns 201; repeating the request for an org this account already created returns 200.
Billing Users
Billing users are the people on the account, each with one or more billing roles. Adding one sends them an invitation email.POST and PUT take the user wrapped in user, with roles set to one or more of billing_admin, billing_viewer, and org_creator:
409. You cannot change or remove your own billing user; that returns 400.
Invoice Email Recipients
Each new invoice is emailed to the account’s enabled invoice email recipients, for example an accounts-payable mailbox./account/{accountId}/invoice-delivery manages that list and shows each delivery’s status. Every endpoint needs billing_admin.
Each delivery has a
recipientEmail, a status of pending, in_progress, delivered, failed, or permanently_failed, and the attemptCount and errorMessages of its delivery attempts.
Billing API Errors
Errors return a JSON body of the form{"code": 400, "error": "message"}.
Learn More
Usage API
Usage tags, metrics, units, and the usage query syntax.
Query Costs and Usage
Step by step: break down a month’s cost and usage per GVC and workload.
Billing Account
Billing roles, spend alerts, and how accounts pay for orgs.
Manage Quotas
View org quotas and request increases through the billing API.