# 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) · [Metrics reference](/docs/tags/metrics.md)

## Get usage

`GET /v1/usage`

Hosted only. Pricing and whether billing charges yet, this month's sent and received counts against their free allowances (5,000 sent and 20,000 received), counted separately (received only for credentials that may read all received mail), and the rolling daily sending limit (none in good standing) with the evaluation before it. Workspace-wide: keys restricted to domains get 403. Dashboard sessions may receive a cached result until the workspace creates an email or records an email event (quantized to 10-second buckets during high-volume sending), or for up to 60 seconds, and compute at most 30 such Overview reads a minute: past that they get their last result (cache header stale) or 429 DASHBOARD_RATE_LIMITED. API keys, MCP and agent tokens always get fresh results.

Operation ID: `getUsage`

Permission: Needs Sent mail: read on the whole workspace.



### TypeScript SDK

```ts
import { createClient } from '@nightmail/sdk/client';
import { getUsage } from '@nightmail/sdk';

const client = createClient({
  baseUrl: 'https://nightmail.dev',
  auth: scheme => scheme.scheme === 'bearer'
    ? process.env.NIGHTMAIL_API_KEY
    : undefined,
});

const result = await getUsage({
  client,
  throwOnError: true,
});

console.log(result.data);
```

### cURL

```sh
curl --request GET \
  --url 'https://nightmail.dev/v1/usage' \
  --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 |
| --- | --- | --- | --- |
| `billing` | object | yes |  |
| `billing.enabled` | boolean | yes | Usage is taken from the prepaid balance (enforcement is enforce). |
| `billing.enforcement` | string | yes | off or shadow: nothing is charged yet (shadow records what would be); enforce: usage is charged hourly. The balance is GET /v1/billing. |
| `pricing` | object | yes |  |
| `pricing.currency` | string | yes |  |
| `pricing.perThousand` | number | yes | Price per 1,000 emails: each recipient of a sent email, each received message. SES mailbox simulator sends count like any other send. |
| `pricing.freeEmails` | integer | yes | The sent allowance (same as freeSentEmails), kept for older clients. Sent and received each have their own allowance (freeSentEmails, freeReceivedEmails), counted separately: sends beyond theirs are charged even while received mail is still free, and the other way round. |
| `pricing.freeSentEmails` | integer | yes | Sent emails (each recipient) included free each calendar month (UTC). |
| `pricing.freeReceivedEmails` | integer | yes | Received messages included free each calendar month (UTC), separate from the sent allowance. |
| `pricing.freeStorageBytes` | integer | yes | Bytes of received mail older than 90 days stored free. |
| `month` | object | yes |  |
| `month.from` | string | yes | Start of the current calendar month, UTC. |
| `month.sent` | integer | yes | Emails created this month, each counted once however many recipients it has. |
| `month.received` | integer or null | yes | Messages received this month on any address, routed, unrouted or spam. Null unless the credential may read every received message (owners, admins and manage credentials): members and read-only keys never learn about mail they can't open. |
| `month.billedSent` | integer | yes | Sent emails billing counts this month, each recipient once (Hosted sending; mail canceled or rejected before it went out is taken off). The free sent allowance and the price apply to this count. |
| `month.billedReceived` | integer or null | yes | Received messages billing counts this month: mail Amazon's spam scan flagged and simulated mail are free. The free received allowance and the price apply to this count. Null like received. |
| `daily` | object or null | yes | Null until the workspace connects hosted sending. |
| `daily.cap` | integer or null | yes | Recipients allowed per rolling 24 hours; null when this workspace has no daily limit. |
| `daily.used` | integer | yes | Recipients charged in the rolling 24 hours, SES mailbox simulator addresses included. |
| `daily.resetAt` | string or null | yes | When capacity next frees up or the limit changes. |
| `daily.step` | integer or null | yes | Index into steps of the step this workspace is on; null past them: no daily limit (cap null), or one set by the score, a warning or an operator. |
| `steps` | object[] | yes | The daily limits a new workspace passes through: only the evaluation. After it, a workspace in good standing (score 75 and up, no warning) has no daily limit; bad signals set one (GET /v1/sender-score). Only real SES acceptances count: simulated sends and simulator addresses use the limit but never end the evaluation. |
| `steps[].cap` | integer | yes | Recipients per rolling 24 hours at this step. |
| `steps[].requires` | string | yes | What a workspace needs to reach this step, in plain words. |
| `simulated` | boolean | yes | This installation simulates SES: no email leaves it, and simulated sends never count against the daily limit. |

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