# Deliverability API

Best-effort deliverability insights computed from the email rows and webhook events Groundmail already stores.

Base URL: `https://api.groundmail.dev`

Auth:

```http
Authorization: Bearer gm_...
```

---

## Get insights

`GET /deliverability?window=30d`

Supported windows:

- `7d`
- `30d` (default)

Example:

```bash
curl -X GET "https://api.groundmail.dev/deliverability?window=7d" \
  -H "Authorization: Bearer $GROUNDMAIL_API_KEY"
```

Response:

```json
{
  "window": "7d",
  "window_start": "2026-07-19T00:00:00.000Z",
  "generated_at": "2026-07-26T00:00:00.000Z",
  "summary": {
    "total_emails": 10,
    "attempted": 9,
    "sent": 8,
    "delivered": 7,
    "bounced": 1,
    "failed": 1,
    "suppressed": 1,
    "scheduled": 0,
    "opened": 3,
    "clicked": 1,
    "bounce_rate": 0.1111,
    "delivery_rate": 0.7778,
    "open_rate": 0.4286,
    "click_rate": 0.1429
  },
  "by_domain": [],
  "top_bounce_reasons": [],
  "notes": [
    "Best-effort metrics only"
  ]
}
```

---

## Transactional and product streams

Groundmail sends every email on a stream, and each stream has its own sending IPs:

| Category | Stream | Typical email |
|----------|--------|---------------|
| `transactional` | Transactional | Sign-in codes, password resets, receipts, alerts, account notices |
| `product` | Product | Promotions, announcements, upsells, onboarding and lifecycle email |
| `newsletter` | Newsletter | Opt-in newsletters, for approved accounts only |

There is nothing to configure: Groundmail reads each email and decides whether it's transactional or product ([how](#detected-category)), and routes it. A product email that draws complaints never shares IPs with the sign-in codes and receipts your users are waiting for. The `category` field on sends, templates, automation steps and SMTP logins is deprecated: `transactional` and `product` there are accepted and ignored, so existing code keeps working. `newsletter` is the one value still honoured.

Each stream's bounce and complaint rates are tracked separately. If your product email bounces or draws complaints at a high rate, Groundmail can pause product email for your workspace on its own while transactional email keeps sending. Product sends then return `403` `forbidden`; contact support@groundmail.dev to resume after cleaning the list.

Marketing campaigns aren't available yet; they're coming later. Cold email and mail to purchased or scraped lists are never allowed. Opt-in newsletter email is accepted only for accounts we approve: it goes out from separate IPs from transactional and product email, always carries one-click unsubscribe, and has its own daily ramp-up limit. On any other account `category: "newsletter"` returns `403` [`newsletter_not_enabled`](https://docs.groundmail.dev/errors#newsletter_not_enabled) and nothing is sent. To ask for approval, email support@groundmail.dev. Newsletter email is paused on its own the same way product email is.

### Detected category

Groundmail reads each email's content to tell what it is: `transactional` (receipts, sign-in codes, alerts, account notices) or `product` (promotions, announcements, upsells). It recognises the template an email was sent from, so emails from one template get that template's category, and it decides from the template's wording alone, with names, addresses, amounts, codes and other personal details taken out first. Templates you save in Groundmail are checked each time you publish them.

The result is `detected_category` on [`GET /emails`](https://docs.groundmail.dev/emails#list-emails), [`GET /emails/{id}`](https://docs.groundmail.dev/emails#retrieve-email) and every outbound [webhook](https://docs.groundmail.dev/webhooks). Each email records a category only once its template's is settled, and keeps it. So it's `null` while an email is being checked, for the first emails of a new template while Groundmail is still deciding it (and for a saved template's sends just after you publish it, until that version is checked), and for email Groundmail doesn't check: `newsletter` sends, test sends, agent mailboxes and forwarded mail. Newsletter email is never detected; it stays opt-in for approved accounts.

The email goes out on the stream for its category. While a template isn't settled yet (its first emails, or a saved template you just published), its emails go out as transactional for 5 minutes after it was first seen or published, then as product until it's settled; a template's very first email goes out at once by the content when Groundmail is sure of it. Product mail gets product handling: one-click unsubscribe and category opt-outs. A template whose emails draw spam complaints at 0.3% or more over 30 days (at least 3 complaints) moves to product, however it reads: people marking it as spam means it isn't mail they were waiting for. If a template's category looks wrong, email support@groundmail.dev with an email id and we'll correct it for that template.

`GET /deliverability` also returns `by_stream_24h`: sent, bounced and complained per stream over the last 24 hours, for each stream with activity. The [email list](https://docs.groundmail.dev/emails#list-emails) and webhooks name each email's `stream`.

## What this includes

- attempted vs scheduled/suppressed counts
- delivered and bounced counts
- best-effort open/click counts from stored events
- breakdown by sending domain
- top recorded bounce reasons
- optional `mail_server_relay` on top domains when relay metrics are available (relay-side sent/bounce/fail counts)

## Roadmap

These are not exposed in the API yet:

- inbox placement / spam folder data
- provider reputation and reputation trends
- richer bounce classifications beyond stored events

---

## SDK

```ts
const insights = await client.emails.insights('30d')
```

## CLI

```bash
groundmail emails insights --window 7d
```
