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

`GET /v1/metrics`

Operational created-cohort metrics, not invoicing or provider reputation. 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. Selects emails created in [from,to), scoped by email region and stream. to defaults to now and from to 24 hours (granularity=10m) or 30 days before to; from equal to to is an empty window. Outcomes use current email state and all recorded events, including events after to; this is not a historical state snapshot. Each outcome counts distinct emails, so replays do not inflate counts and outcomes may overlap. Accepted (bucket sent) means evidence of provider acceptance, not merely queued/created. Daily UTC creation buckets contain count=created emails. Granularity defaults to day; granularity=hour returns hourly UTC creation buckets and granularity=10m returns 10-minute UTC creation buckets (within the last 6 days) with canonical ISO dates, while preserving daily buckets and totals. Absent buckets mean zero created emails and zero outcomes; no moving averages are applied. Engagement is observed, not verified human activity. Each statement stops after 5 seconds: a request that needs longer is refused with 422 READ_TOO_LARGE. Narrow the dates or filters.

Operation ID: `getMetrics`

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `region` | query | string | no |  |
| `from` | query | string | no |  |
| `to` | query | string | no |  |
| `stream` | query | string | no |  |
| `granularity` | query | string | no |  |
| `include` | query | string | no | Comma-separated extras computed in the same statement: previous (totals for the window of equal length ending at from) and streams (totals per stream for the window, ignoring the stream filter). |


### TypeScript SDK

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

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

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

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

### cURL

```sh
curl --request GET \
  --url 'https://nightmail.dev/v1/metrics' \
  --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 |
| --- | --- | --- | --- |
| `basis` | string | yes |  |
| `from` | string | yes |  |
| `to` | string | yes |  |
| `region` | string or null | yes |  |
| `stream` | string or null | yes |  |
| `totals` | object | yes |  |
| `totals.emails` | number | yes |  |
| `totals.accepted` | number | yes |  |
| `totals.delivered` | number | yes |  |
| `totals.bounced` | number | yes |  |
| `totals.complained` | number | yes |  |
| `totals.opened` | number | yes |  |
| `totals.clicked` | number | yes |  |
| `totals.failed` | number | yes |  |
| `totals.deliveryDelayed` | number | yes |  |
| `totals.simulated` | number | yes |  |
| `daily` | object[] | yes |  |
| `daily[].date` | string | yes |  |
| `daily[].count` | number | yes |  |
| `daily[].sent` | number | yes |  |
| `daily[].delivered` | number | yes |  |
| `daily[].bounced` | number | yes |  |
| `daily[].complained` | number | yes |  |
| `hourly` | object[] | no |  |
| `hourly[].date` | string | yes |  |
| `hourly[].count` | number | yes |  |
| `hourly[].sent` | number | yes |  |
| `hourly[].delivered` | number | yes |  |
| `hourly[].bounced` | number | yes |  |
| `hourly[].complained` | number | yes |  |
| `tenMinute` | object[] | no |  |
| `tenMinute[].date` | string | yes |  |
| `tenMinute[].count` | number | yes |  |
| `tenMinute[].sent` | number | yes |  |
| `tenMinute[].delivered` | number | yes |  |
| `tenMinute[].bounced` | number | yes |  |
| `tenMinute[].complained` | number | yes |  |
| `previous` | object | no | Present with include=previous. |
| `previous.from` | string | yes |  |
| `previous.to` | string | yes |  |
| `previous.totals` | object | yes |  |
| `streams` | object | no | Present with include=streams. |
| `streams.transactional` | object | yes |  |
| `streams.marketing` | object | yes |  |

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