Read the balance and billing state
/v1/billingHosted only. The prepaid balance, this month’s free allowances (sent and received, counted separately) and cost, whether sending or receiving is paused for an empty balance, auto-recharge and the saved card, and the prices. Amounts are null unless the caller is an owner or admin session, or a manage key or grant. Keys restricted to domains get 403.
Needs Configuration: read on the whole workspace.
Example
import { createClient } from '@nightmail/sdk/client';
import { getBilling } from '@nightmail/sdk';
const client = createClient({
baseUrl: 'https://nightmail.dev',
auth: scheme => scheme.scheme === 'bearer'
? process.env.NIGHTMAIL_API_KEY
: undefined,
});
const result = await getBilling({
client,
throwOnError: true,
});
console.log(result.data);curl --request GET \
--url 'https://nightmail.dev/v1/billing' \
--header "Authorization: Bearer $NIGHTMAIL_API_KEY"Responses
200Success
BillingSummaryenforcementrequiredstringoff: nothing is metered for billing. shadow: usage is recorded and priced but nothing is charged. enforce: usage is taken from the balance hourly.
moderequiredstringprepaid: usage is taken from the balance. exempt: the workspace is free (see freePlan).
staterequiredobjectstate.sendingrequiredstringpaused: sends get 402 BALANCE_EXHAUSTED until credit is added.
state.receivingrequiredstringgrace: the balance is below $0 and received mail is still accepted until grace.receiveHoldAt; held: new received mail is stored but not delivered until a top-up. While the installation doesn’t hold received mail, receiving stays ok.
state.autoRechargerequiredstringbalancerequiredobject or nullNull unless the caller is an owner or admin session, or a manage key or grant.
balance.paidrequiredstringInteger micro-cents (1¢ = 1,000,000) as a string.
balance.promorequiredobjectbalance.unsettledrequiredobjectbalance.availablerequiredobjectfreerequiredobjectfree.monthrequiredstringfree.emailsrequiredobjectThe sent allowance (same as sent), kept for older clients. Each direction has its own allowance: see sent and received.
free.sentrequiredobjectFree sent emails this month, each recipient counting once. Sends beyond it are charged even while received mail is still free.
free.receivedrequiredobject or nullFree received messages this month, separate from the sent allowance. Null unless the credential may read every received message (owners, admins and manage credentials), as in GET /v1/usage.
free.storagerequiredobjectmonthToDaterequiredobject or nullmonthToDate.costrequiredobjectgracerequiredobjectgrace.unpaidSincerequiredstring or nullgrace.receiveHoldAtrequiredstring or nullWhen new received mail starts being held; null when nothing is owed or the installation doesn’t hold received mail.
grace.writeOffAtrequiredstring or nullautoRechargerequiredobject or nullautoRecharge.enabledrequiredbooleanautoRecharge.thresholdCentsrequiredintegerautoRecharge.amountCentsrequiredintegerautoRecharge.monthlyCapCentsrequiredintegerautoRecharge.monthTotalCentsrequiredintegerautoRecharge.disabledReasonrequiredstring or nullWhy Nightmail turned auto-recharge off (a card decline code, dispute or a removed card).
autoRecharge.pendingrequiredbooleanpaymentMethodrequiredobject or nullpaymentMethod.brandrequiredstringpaymentMethod.last4requiredstringpaymentMethod.expMonthrequiredintegerpaymentMethod.expYearrequiredintegerpricesrequiredobjectprices.emailPerThousandrequiredstringUSD per 1,000 emails, sent (per recipient) or received (per message).
prices.decisionPerThousandrequiredstringDeprecated: AI decisions are free, so this is always "0.00".
prices.omenPerThousandrequiredstringDeprecated: decisionPerThousand, always "0.00".
prices.storagePerGbMonthrequiredstringUSD per GB-month for received mail older than 90 days, beyond the free GB.
prices.freeEmailsrequiredintegerThe sent allowance (same as freeSentEmails), kept for older clients. Each direction has its own allowance, counted separately (freeSentEmails, freeReceivedEmails).
prices.freeSentEmailsrequiredintegerSent emails (each recipient) free each calendar month (UTC).
prices.freeReceivedEmailsrequiredintegerReceived messages free each calendar month (UTC), separate from the sent allowance.
prices.freeStorageBytesrequiredintegerprices.topUpMinCentsrequiredintegerprices.currencyrequiredstringtopUpUrlrequiredstringWhere a person adds credit.
freePlanrequiredobject or nullSet when Anomaly made this workspace free (mode exempt): nothing is charged and sending never pauses for the balance. Usage is still measured, and monthToDate shows what it would cost.
freePlan.untilrequiredstring or nullWhen the free plan ends; null: no end date.
400, 401, 403, 404, 409, 413, 422, 429, 500, 503Request failed; use error.code and requestId to diagnose.
ApiErrorerrorrequiredobjecterror.coderequiredstringerror.messagerequiredstringerror.requestIdrequiredstringerror.fieldstringerror.retryablerequiredbooleanerror.resetAtstringNext capacity change for a Hosted rolling send limit.
error.detailsobject[]Every problem found, when there is more than one part, such as rule diagnostics with rule, line, column, message and hint, or a measurement, such as CONTENT_TOO_LARGE_TO_SCREEN with screenedBytes and limitBytes (and index in a batch).
error.requiredobjectOn a 403 permission refusal: what the request needs that this credential lacks. The Nightmail-Required-Permission header says the same.