# Nightmail API

Send, receive and reply to email on your own domains. 202 means queued, not delivered.

- [Interactive documentation](/docs)
- [OpenAPI 3.1 JSON](/openapi.json)
- [Agent index](/llms.txt)
- TypeScript package: `@nightmail/sdk`

[API index](/docs.md) · [Billing reference](/docs/tags/billing.md)

## Get billing

`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.

Operation ID: `getBilling`

Permission: Needs Configuration: read on the whole workspace.



### TypeScript SDK

```ts
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

```sh
curl --request GET \
  --url 'https://nightmail.dev/v1/billing' \
  --header "Authorization: Bearer $NIGHTMAIL_API_KEY"
```

### Responses

| Status | Description | Schema |
| --- | --- | --- |
| `200` | Success | object |
| `400`, `401`, `403`, `404`, `409`, `413`, `422`, `429`, `500`, `503` | Request failed; use error.code and requestId to diagnose. | object |

#### 200: Success

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `enforcement` | string | yes | off: nothing is metered for billing. shadow: usage is recorded and priced but nothing is charged. enforce: usage is taken from the balance hourly. |
| `mode` | string | yes | prepaid: usage is taken from the balance. exempt: the workspace is free (see freePlan). |
| `state` | object | yes |  |
| `state.sending` | string | yes | paused: sends get 402 BALANCE_EXHAUSTED until credit is added. |
| `state.receiving` | string | yes | 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.autoRecharge` | string | yes |  |
| `balance` | object or null | yes | Null unless the caller is an owner or admin session, or a manage key or grant. |
| `balance.paid` | string | yes | Integer micro-cents (1¢ = 1,000,000) as a string. |
| `balance.promo` | object | yes |  |
| `balance.unsettled` | object | yes |  |
| `balance.available` | object | yes |  |
| `free` | object | yes |  |
| `free.month` | string | yes |  |
| `free.emails` | object | yes | The sent allowance (same as sent), kept for older clients. Each direction has its own allowance: see sent and received. |
| `free.sent` | object | yes | Free sent emails this month, each recipient counting once. Sends beyond it are charged even while received mail is still free. |
| `free.received` | object or null | yes | 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.storage` | object | yes |  |
| `monthToDate` | object or null | yes |  |
| `monthToDate.cost` | object | yes |  |
| `grace` | object | yes |  |
| `grace.unpaidSince` | string or null | yes |  |
| `grace.receiveHoldAt` | string or null | yes | When new received mail starts being held; null when nothing is owed or the installation doesn’t hold received mail. |
| `grace.writeOffAt` | string or null | yes |  |
| `autoRecharge` | object or null | yes |  |
| `autoRecharge.enabled` | boolean | yes |  |
| `autoRecharge.thresholdCents` | integer | yes |  |
| `autoRecharge.amountCents` | integer | yes |  |
| `autoRecharge.monthlyCapCents` | integer | yes |  |
| `autoRecharge.monthTotalCents` | integer | yes |  |
| `autoRecharge.disabledReason` | string or null | yes | Why Nightmail turned auto-recharge off (a card decline code, dispute or a removed card). |
| `autoRecharge.pending` | boolean | yes |  |
| `paymentMethod` | object or null | yes |  |
| `paymentMethod.brand` | string | yes |  |
| `paymentMethod.last4` | string | yes |  |
| `paymentMethod.expMonth` | integer | yes |  |
| `paymentMethod.expYear` | integer | yes |  |
| `prices` | object | yes |  |
| `prices.emailPerThousand` | string | yes | USD per 1,000 emails, sent (per recipient) or received (per message). |
| `prices.decisionPerThousand` | string | yes | Deprecated: AI decisions are free, so this is always "0.00". |
| `prices.omenPerThousand` | string | yes | Deprecated: decisionPerThousand, always "0.00". |
| `prices.storagePerGbMonth` | string | yes | USD per GB-month for received mail older than 90 days, beyond the free GB. |
| `prices.freeEmails` | integer | yes | The sent allowance (same as freeSentEmails), kept for older clients. Each direction has its own allowance, counted separately (freeSentEmails, freeReceivedEmails). |
| `prices.freeSentEmails` | integer | yes | Sent emails (each recipient) free each calendar month (UTC). |
| `prices.freeReceivedEmails` | integer | yes | Received messages free each calendar month (UTC), separate from the sent allowance. |
| `prices.freeStorageBytes` | integer | yes |  |
| `prices.topUpMinCents` | integer | yes |  |
| `prices.currency` | string | yes |  |
| `topUpUrl` | string | yes | Where a person adds credit. |
| `freePlan` | object or null | yes | 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.until` | string or null | yes | When the free plan ends; null: no end date. |

#### 400, 401, 403, 404, 409, 413, 422, 429, 500, 503: Request failed; use error.code and requestId to diagnose.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `error` | object | yes |  |
| `error.code` | string | yes |  |
| `error.message` | string | yes |  |
| `error.requestId` | string | yes |  |
| `error.field` | string | no |  |
| `error.retryable` | boolean | yes |  |
| `error.resetAt` | string | no | Next capacity change for a Hosted rolling send limit. |
| `error.details` | object[] | no | 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.required` | object | no | On a 403 permission refusal: what the request needs that this credential lacks. The Nightmail-Required-Permission header says the same. |
