Key balance
/v1/balanceHow much money the key's account has: granted, spent, left.
Responses
Response
{
"object": "balance",
"granted": 100.0,
"spend": 37.42,
"balance": 62.58,
"currency": "USD"
}Details
Needs a key in Authorization: Bearer or x-api-key.
The balance comes from one formula: granted − text spend − effective media spend. Hence three numbers plus a currency:
granted — everything ever credited to the account; spend — total spend, text and media as one number; balance — what is left, granted minus spend; currency — always USD.
What matters about spend: its media part counts not only what was charged but also what is held for generations still running. A hold is released when the job finishes (turning into a charge) or fails (returning the money). That is why balance drops the moment you queue a generation rather than at the end — otherwise ten generations could be queued on money that covers one.
Degradation worth knowing in advance. If our storage is unreachable the response shape does not change, but granted is taken from the account budget, which already has media subtracted; while that budget is in sync, balance comes out the same. If the key-and-remainder check itself is unreachable, the endpoint answers 502 and returns no number at all: no answer is more honest than an invented one.