NightmailDocs
Docs

Read the balance and billing state

get/v1/billing

Hosted 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
BillingSummary
enforcementrequiredstring

off: nothing is metered for billing. shadow: usage is recorded and priced but nothing is charged. enforce: usage is taken from the balance hourly.

moderequiredstring

prepaid: usage is taken from the balance. exempt: the workspace is free (see freePlan).

staterequiredobject
state.sendingrequiredstring

paused: sends get 402 BALANCE_EXHAUSTED until credit is added.

state.receivingrequiredstring

grace: 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.autoRechargerequiredstring
balancerequiredobject or null

Null unless the caller is an owner or admin session, or a manage key or grant.

balance.paidrequiredstring

Integer micro-cents (1¢ = 1,000,000) as a string.

balance.promorequiredobject
balance.unsettledrequiredobject
balance.availablerequiredobject
freerequiredobject
free.monthrequiredstring
free.emailsrequiredobject

The sent allowance (same as sent), kept for older clients. Each direction has its own allowance: see sent and received.

free.sentrequiredobject

Free sent emails this month, each recipient counting once. Sends beyond it are charged even while received mail is still free.

free.receivedrequiredobject or null

Free 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.storagerequiredobject
monthToDaterequiredobject or null
monthToDate.costrequiredobject
gracerequiredobject
grace.unpaidSincerequiredstring or null
grace.receiveHoldAtrequiredstring or null

When new received mail starts being held; null when nothing is owed or the installation doesn’t hold received mail.

grace.writeOffAtrequiredstring or null
autoRechargerequiredobject or null
autoRecharge.enabledrequiredboolean
autoRecharge.thresholdCentsrequiredinteger
autoRecharge.amountCentsrequiredinteger
autoRecharge.monthlyCapCentsrequiredinteger
autoRecharge.monthTotalCentsrequiredinteger
autoRecharge.disabledReasonrequiredstring or null

Why Nightmail turned auto-recharge off (a card decline code, dispute or a removed card).

autoRecharge.pendingrequiredboolean
paymentMethodrequiredobject or null
paymentMethod.brandrequiredstring
paymentMethod.last4requiredstring
paymentMethod.expMonthrequiredinteger
paymentMethod.expYearrequiredinteger
pricesrequiredobject
prices.emailPerThousandrequiredstring

USD per 1,000 emails, sent (per recipient) or received (per message).

prices.decisionPerThousandrequiredstring

Deprecated: AI decisions are free, so this is always "0.00".

prices.omenPerThousandrequiredstring

Deprecated: decisionPerThousand, always "0.00".

prices.storagePerGbMonthrequiredstring

USD per GB-month for received mail older than 90 days, beyond the free GB.

prices.freeEmailsrequiredinteger

The sent allowance (same as freeSentEmails), kept for older clients. Each direction has its own allowance, counted separately (freeSentEmails, freeReceivedEmails).

prices.freeSentEmailsrequiredinteger

Sent emails (each recipient) free each calendar month (UTC).

prices.freeReceivedEmailsrequiredinteger

Received messages free each calendar month (UTC), separate from the sent allowance.

prices.freeStorageBytesrequiredinteger
prices.topUpMinCentsrequiredinteger
prices.currencyrequiredstring
topUpUrlrequiredstring

Where a person adds credit.

freePlanrequiredobject or null

Set 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 null

When 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.
ApiError
errorrequiredobject
error.coderequiredstring
error.messagerequiredstring
error.requestIdrequiredstring
error.fieldstring
error.retryablerequiredboolean
error.resetAtstring

Next 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.requiredobject

On a 403 permission refusal: what the request needs that this credential lacks. The Nightmail-Required-Permission header says the same.